diff --git a/agent/agent.go b/agent/agent.go index 19e6677..5ca2402 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -65,7 +65,7 @@ func Run(c Config) error { a.data.Files = map[string]string{} a.data.Log = map[int64]msg{} a.data.LogOffset = 0 - a.data.LogMaxSize = 10000 + a.data.LogMaxSize = int64(c.MaxLines) a.sync = velox.SyncHandler(&a.data) //http h := http.Handler(http.HandlerFunc(a.router)) @@ -179,11 +179,12 @@ func (a *agent) readFiles() { func (a *agent) readLog() { for l := range a.msgQueue { a.data.Lock() - a.data.Log[a.data.LogOffset] = l - a.data.LogOffset++ - if a.data.LogOffset >= a.data.LogMaxSize { - delete(a.data.Log, a.data.LogMaxSize-a.data.LogOffset) + o := a.data.LogOffset + a.data.Log[o] = l + if o >= a.data.LogMaxSize { + delete(a.data.Log, o-a.data.LogMaxSize) } + a.data.LogOffset++ a.data.Unlock() a.data.Push() } diff --git a/agent/config.go b/agent/config.go index ee40638..1989fc6 100644 --- a/agent/config.go +++ b/agent/config.go @@ -37,6 +37,7 @@ type Config struct { OnExit OnExit `help:"process exit action" default:"ignore"` ConfigurationFiles []string `name:"config" type:"commalist" help:"comma-separated list of configuration files"` RestartTimeout Duration `opts:"-"` + MaxLines int `help:"maximum number of log lines to show in webui" default:"1000"` } func LoadConfig(path string, c *Config) error { @@ -69,6 +70,9 @@ func ValidateConfig(c *Config) error { if c.Port == 0 { c.Port = 8080 } + if c.MaxLines == 0 { + c.MaxLines = 1000 + } switch c.Log { case LogBoth, LogProxy, LogWebUI: default: diff --git a/agent/static/js/app.js b/agent/static/js/app.js index 7c82931..abf30f4 100644 --- a/agent/static/js/app.js +++ b/agent/static/js/app.js @@ -81,7 +81,6 @@ app.directive("log", function() { span.textContent = m.b; span.className = m.p; e.appendChild(span); - m.$rendered = true; } followLog(); }); @@ -90,15 +89,13 @@ app.directive("log", function() { }); app.service("sync", function() { - return function(obj, key) { + return function(scope, key) { var val = localStorage.getItem(key); if(val) { - console.log("load", key, val); - obj.$eval(key + "=" + val); + scope.$eval(key + "=" + val); //assume JSON } - obj.$watch(key, function(val) { + scope.$watch(key, function(val) { var str = JSON.stringify(val); - console.log("set", key, str); localStorage.setItem(key, str); }, true); }; @@ -110,7 +107,7 @@ app.run(function($rootScope, $http, $timeout, sync) { show: { out: true, err: true, - agent: false + agent: true }, file: '', files: null