diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-12-05 10:52:24 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-12-05 10:52:24 +0100 |
commit | f75d24ca885690289c16adeac0e5c5e7bb56e36c (patch) | |
tree | b7d66cd4cffed7d0c1070312bebe92209575419f /lib/agent | |
parent | 9194f6c934ab3af0a559290b9299f6be2d9b2269 (diff) |
Improved silly logging.
Diffstat (limited to 'lib/agent')
-rw-r--r-- | lib/agent/agent.go | 11 | ||||
-rw-r--r-- | lib/agent/apiv1-exec.go | 8 | ||||
-rw-r--r-- | lib/agent/events.go | 4 | ||||
-rw-r--r-- | lib/agent/sessions.go | 10 |
4 files changed, 16 insertions, 17 deletions
diff --git a/lib/agent/agent.go b/lib/agent/agent.go index d1a3d05..58a2ba0 100644 --- a/lib/agent/agent.go +++ b/lib/agent/agent.go @@ -41,6 +41,7 @@ type Context struct { Config *xdsconfig.Config Log *logrus.Logger LogLevelSilly bool + LogSillyf func(format string, args ...interface{}) SThg *st.SyncThing SThgCmd *exec.Cmd SThgInotCmd *exec.Cmd @@ -71,13 +72,21 @@ func NewAgent(cliCtx *cli.Context) *Context { } log.Formatter = &logrus.TextFormatter{} + // Support silly logging (printed on log.debug) sillyVal, sillyLog := os.LookupEnv("XDS_LOG_SILLY") + logSilly := sillyLog && sillyVal == "1" + sillyFunc := func(format string, args ...interface{}) { + if logSilly { + log.Debugf("SILLY: "+format, args...) + } + } // Define default configuration ctx := Context{ ProgName: cliCtx.App.Name, Log: log, - LogLevelSilly: (sillyLog && sillyVal == "1"), + LogLevelSilly: logSilly, + LogSillyf: sillyFunc, Exit: make(chan os.Signal, 1), webServer: nil, diff --git a/lib/agent/apiv1-exec.go b/lib/agent/apiv1-exec.go index 2f38b63..ace2cdc 100644 --- a/lib/agent/apiv1-exec.go +++ b/lib/agent/apiv1-exec.go @@ -81,9 +81,7 @@ func (s *APIService) execCmd(c *gin.Context) { for _, evName := range evtInList { evN := evName err := (*sock).On(evN, func(stdin string) { - if s.LogLevelSilly { - s.Log.Debugf("EXEC EVENT IN (%s) <<%v>>", evN, stdin) - } + s.LogSillyf("EXEC EVENT IN (%s) <<%v>>", evN, stdin) svr.EventEmit(evN, stdin) }) if err != nil { @@ -115,9 +113,7 @@ func (s *APIService) execCmd(c *gin.Context) { // Add sessionID to event Data reflectme.SetField(evData, "sessionID", sid) - if s.LogLevelSilly { - s.Log.Debugf("EXEC EVENT OUT (%s) <<%v>>", evN, evData) - } + s.LogSillyf("EXEC EVENT OUT (%s) <<%v>>", evN, evData) // Forward event to Client/Dashboard (*so).Emit(evN, evData) diff --git a/lib/agent/events.go b/lib/agent/events.go index c316db8..df7015a 100644 --- a/lib/agent/events.go +++ b/lib/agent/events.go @@ -95,9 +95,7 @@ func (e *Events) Emit(evName string, data interface{},fromSid string) error { return fmt.Errorf("Unsupported event type") } - if e.LogLevelSilly { - e.Log.Debugf("Emit Event %s: %v", evName, data) - } + e.LogSillyf("Emit Event %s: %v", evName, data) firstErr = nil evm := e.eventsMap[evName] diff --git a/lib/agent/sessions.go b/lib/agent/sessions.go index d02ea3c..3655eef 100644 --- a/lib/agent/sessions.go +++ b/lib/agent/sessions.go @@ -225,10 +225,8 @@ func (s *Sessions) monitorSessMap() { s.Log.Debugln("Stop monitorSessMap") return case <-time.After(sessionMonitorTime * time.Second): - if s.LogLevelSilly { - s.Log.Debugf("Sessions Map size: %d", len(s.sessMap)) - s.Log.Debugf("Sessions Map : %v", s.sessMap) - } + s.LogSillyf("Sessions Map size: %d", len(s.sessMap)) + s.LogSillyf("Sessions Map : %v", s.sessMap) if len(s.sessMap) > maxSessions { s.Log.Errorln("TOO MUCH sessions, cleanup old ones !") @@ -237,9 +235,7 @@ func (s *Sessions) monitorSessMap() { s.mutex.Lock() for _, ss := range s.sessMap { if ss.expireAt.Sub(time.Now()) < 0 { - if s.LogLevelSilly { - s.Log.Debugf("Delete expired session id: %s", ss.ID) - } + s.LogSillyf("Delete expired session id: %s", ss.ID) delete(s.sessMap, ss.ID) } } |