From abf2b4a4cb0513b3acc1d12c294f99103268cc7d Mon Sep 17 00:00:00 2001 From: Sergey Lanzman Date: Fri, 10 Mar 2017 20:32:22 +0200 Subject: [PATCH] 1. Make logs for beego developer not for bee developer 2. Fix debug mode --- cmd/commands/run/watch.go | 6 +++--- logger/logger.go | 26 ++++++++++++++++---------- utils/utils.go | 6 ------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index 4452b61..0b7abd7 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -73,14 +73,14 @@ func NewWatcher(paths []string, files []string, isgenerate bool) { mt := getFileModTime(e.Name) if t := eventTime[e.Name]; mt == t { - beeLogger.Log.Infof(colors.Bold("Skipping: ")+"%s", e.String()) + beeLogger.Log.Hintf(colors.Bold("Skipping: ")+"%s", e.String()) isBuild = false } eventTime[e.Name] = mt if isBuild { - beeLogger.Log.Infof("Event fired: %s", e) + beeLogger.Log.Hintf("Event fired: %s", e) go func() { // Wait 1s before autobuild until there is no file change. scheduleTime = time.Now().Add(1 * time.Second) @@ -96,7 +96,7 @@ func NewWatcher(paths []string, files []string, isgenerate bool) { beeLogger.Log.Info("Initializing watcher...") for _, path := range paths { - beeLogger.Log.Infof(colors.Bold("Watching: ")+"%s", path) + beeLogger.Log.Hintf(colors.Bold("Watching: ")+"%s", path) err = watcher.Add(path) if err != nil { beeLogger.Log.Fatalf("Failed to watch directory: %s", err) diff --git a/logger/logger.go b/logger/logger.go index 5b15d81..acf654f 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -30,14 +30,14 @@ import ( var errInvalidLogLevel = errors.New("logger: invalid log level") const ( - levelCritical = iota - levelFatal - levelSuccess - levelHint - levelDebug - levelInfo - levelWarn + levelDebug = iota levelError + levelFatal + levelCritical + levelSuccess + levelWarn + levelInfo + levelHint ) var ( @@ -45,6 +45,9 @@ var ( instance *BeeLogger once sync.Once ) +var debugMode = map[string]bool{"1": true, "0": false}[os.Getenv("DEBUG_ENABLED")] + +var logLevel = levelInfo // BeeLogger logs logging records to the specified io.Writer type BeeLogger struct { @@ -164,6 +167,9 @@ func (l *BeeLogger) getColorLevel(level int) string { // mustLog logs the message according to the specified level and arguments. // It panics in case of an error. func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) { + if level > logLevel { + return + } // Acquire the lock l.mu.Lock() defer l.mu.Unlock() @@ -184,9 +190,9 @@ func (l *BeeLogger) mustLog(level int, message string, args ...interface{}) { // mustLogDebug logs a debug message only if debug mode // is enabled. i.e. DEBUG_ENABLED="1" func (l *BeeLogger) mustLogDebug(message string, file string, line int, args ...interface{}) { - //if !IsDebugEnabled() { - // return - //} + if !debugMode { + return + } // Change the output to Stderr l.SetOutput(os.Stderr) diff --git a/utils/utils.go b/utils/utils.go index 03a94c8..8262db3 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -241,12 +241,6 @@ func WriteToFile(filename, content string) { MustCheck(err) } -// IsDebugEnabled checks if DEBUG_ENABLED is set or not -func IsDebugEnabled() bool { - debugMode := os.Getenv("DEBUG_ENABLED") - return map[string]bool{"1": true, "0": false}[debugMode] -} - // __FILE__ returns the file name in which the function was invoked func FILE() string { _, file, _, _ := runtime.Caller(1)