diff options
-rw-r--r-- | lib/apiv1/events.go | 4 | ||||
-rw-r--r-- | lib/session/session.go | 32 | ||||
-rw-r--r-- | lib/webserver/server.go | 6 | ||||
-rw-r--r-- | main.go | 36 |
4 files changed, 42 insertions, 36 deletions
diff --git a/lib/apiv1/events.go b/lib/apiv1/events.go index b87486f..8f92ae0 100644 --- a/lib/apiv1/events.go +++ b/lib/apiv1/events.go @@ -112,8 +112,8 @@ func (s *APIService) eventsRegister(c *gin.Context) { Folder: *cfg, } - s.log.Debugf("Event emit %s - ID=%s, Status=%s IsInSync=%v", EventEventType+evType, cfg.ID, - cfg.Status, cfg.IsInSync) + s.log.Debugf("WS Emit %s - Status=%10s, IsInSync=%6v, ID=%s", + EventEventType+evType, cfg.Status, cfg.IsInSync, cfg.ID) if err := (*so).Emit(EventEventType+evType, msg); err != nil { s.log.Errorf("WS Emit Folder StateChanged event : %v", err) diff --git a/lib/session/session.go b/lib/session/session.go index d4e1ad3..60b7b8a 100644 --- a/lib/session/session.go +++ b/lib/session/session.go @@ -36,27 +36,29 @@ type ClientSession struct { // Sessions holds client sessions type Sessions struct { - router *gin.Engine - cookieMaxAge int64 - sessMap map[string]ClientSession - mutex sync.Mutex - log *logrus.Logger - stop chan struct{} // signals intentional stop + router *gin.Engine + cookieMaxAge int64 + sessMap map[string]ClientSession + mutex sync.Mutex + log *logrus.Logger + LogLevelSilly bool + stop chan struct{} // signals intentional stop } // NewClientSessions . -func NewClientSessions(router *gin.Engine, log *logrus.Logger, cookieMaxAge string) *Sessions { +func NewClientSessions(router *gin.Engine, log *logrus.Logger, cookieMaxAge string, sillyLog bool) *Sessions { ckMaxAge, err := strconv.ParseInt(cookieMaxAge, 10, 0) if err != nil { ckMaxAge = 0 } s := Sessions{ - router: router, - cookieMaxAge: ckMaxAge, - sessMap: make(map[string]ClientSession), - mutex: sync.NewMutex(), - log: log, - stop: make(chan struct{}), + router: router, + cookieMaxAge: ckMaxAge, + sessMap: make(map[string]ClientSession), + mutex: sync.NewMutex(), + log: log, + LogLevelSilly: sillyLog, + stop: make(chan struct{}), } s.router.Use(s.Middleware()) @@ -197,15 +199,13 @@ func (s *Sessions) refresh(sid string) { } func (s *Sessions) monitorSessMap() { - const dbgFullTrace = false // for debugging - for { select { case <-s.stop: s.log.Debugln("Stop monitorSessMap") return case <-time.After(sessionMonitorTime * time.Second): - if dbgFullTrace { + if s.LogLevelSilly { s.log.Debugf("Sessions Map size: %d", len(s.sessMap)) s.log.Debugf("Sessions Map : %v", s.sessMap) } diff --git a/lib/webserver/server.go b/lib/webserver/server.go index a2fdf6f..85a2c40 100644 --- a/lib/webserver/server.go +++ b/lib/webserver/server.go @@ -30,6 +30,7 @@ type Server struct { mfolders *model.Folders sdks *crosssdk.SDKs log *logrus.Logger + sillyLog bool stop chan struct{} // signals intentional stop } @@ -37,7 +38,7 @@ const indexFilename = "index.html" const cookieMaxAge = "3600" // New creates an instance of Server -func New(cfg *xdsconfig.Config, mfolders *model.Folders, sdks *crosssdk.SDKs, logr *logrus.Logger) *Server { +func New(cfg *xdsconfig.Config, mfolders *model.Folders, sdks *crosssdk.SDKs, logr *logrus.Logger, sillyLog bool) *Server { // Setup logging for gin router if logr.Level == logrus.DebugLevel { @@ -66,6 +67,7 @@ func New(cfg *xdsconfig.Config, mfolders *model.Folders, sdks *crosssdk.SDKs, lo mfolders: mfolders, sdks: sdks, log: logr, + sillyLog: sillyLog, stop: make(chan struct{}), } @@ -83,7 +85,7 @@ func (s *Server) Serve() error { s.router.Use(s.middlewareCORS()) // Sessions manager - s.sessions = session.NewClientSessions(s.router, s.log, cookieMaxAge) + s.sessions = session.NewClientSessions(s.router, s.log, cookieMaxAge, s.sillyLog) // Create REST API s.api = apiv1.New(s.router, s.sessions, s.cfg, s.mfolders, s.sdks) @@ -41,17 +41,18 @@ var AppSubVersion = "unknown-dev" // Context holds the XDS server context type Context struct { - ProgName string - Cli *cli.Context - Config *xdsconfig.Config - Log *logrus.Logger - SThg *st.SyncThing - SThgCmd *exec.Cmd - SThgInotCmd *exec.Cmd - MFolders *model.Folders - SDKs *crosssdk.SDKs - WWWServer *webserver.Server - Exit chan os.Signal + ProgName string + Cli *cli.Context + Config *xdsconfig.Config + Log *logrus.Logger + LogLevelSilly bool + SThg *st.SyncThing + SThgCmd *exec.Cmd + SThgInotCmd *exec.Cmd + MFolders *model.Folders + SDKs *crosssdk.SDKs + WWWServer *webserver.Server + Exit chan os.Signal } // NewContext Create a new instance of XDS server @@ -71,12 +72,15 @@ func NewContext(cliCtx *cli.Context) *Context { } log.Formatter = &logrus.TextFormatter{} + sillyVal, sillyLog := os.LookupEnv("XDS_LOG_SILLY") + // Define default configuration ctx := Context{ - ProgName: cliCtx.App.Name, - Cli: cliCtx, - Log: log, - Exit: make(chan os.Signal, 1), + ProgName: cliCtx.App.Name, + Cli: cliCtx, + Log: log, + LogLevelSilly: (sillyLog && sillyVal == "1"), + Exit: make(chan os.Signal, 1), } // register handler on SIGTERM / exit @@ -212,7 +216,7 @@ func xdsApp(cliCtx *cli.Context) error { } // Create Web Server - ctx.WWWServer = webserver.New(ctx.Config, ctx.MFolders, ctx.SDKs, ctx.Log) + ctx.WWWServer = webserver.New(ctx.Config, ctx.MFolders, ctx.SDKs, ctx.Log, ctx.LogLevelSilly) // Run Web Server until exit requested (blocking call) if err = ctx.WWWServer.Serve(); err != nil { |