Skip to content

Commit

Permalink
* user-define max log lines
Browse files Browse the repository at this point in the history
* fix memory leak (now clears logs over max)
  • Loading branch information
jpillora committed Oct 11, 2016
1 parent 20b28cf commit f2c3b65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 6 additions & 5 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
}
Expand Down
4 changes: 4 additions & 0 deletions agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions agent/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ app.directive("log", function() {
span.textContent = m.b;
span.className = m.p;
e.appendChild(span);
m.$rendered = true;
}
followLog();
});
Expand All @@ -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);
};
Expand All @@ -110,7 +107,7 @@ app.run(function($rootScope, $http, $timeout, sync) {
show: {
out: true,
err: true,
agent: false
agent: true
},
file: '',
files: null
Expand Down

0 comments on commit f2c3b65

Please sign in to comment.