diff --git a/daemon/log/log.go b/daemon/log/log.go index 0602124e..7987e958 100644 --- a/daemon/log/log.go +++ b/daemon/log/log.go @@ -23,10 +23,11 @@ const ( FG_BLACK = "\033[30m" FG_WHITE = "\033[97m" - BG_DGRAY = "\033[100m" + BG_PURPLE = "\033[45m" BG_RED = "\033[41m" BG_GREEN = "\033[42m" BG_YELLOW = "\033[43m" + BG_DGRAY = "\033[100m" BG_LBLUE = "\033[104m" RESET = "\033[0m" @@ -40,6 +41,8 @@ const ( WARNING ERROR FATAL + + TRACE = -1 ) // @@ -48,12 +51,13 @@ var ( Output = os.Stdout StdoutFile = "/dev/stdout" DateFormat = "2006-01-02 15:04:05" - MinLevel = INFO + MinLevel = int(INFO) LogUTC = true LogMicro = false mutex = &sync.RWMutex{} labels = map[int]string{ + TRACE: "TRC", DEBUG: "DBG", INFO: "INF", IMPORTANT: "IMP", @@ -62,6 +66,7 @@ var ( FATAL: "!!!", } colors = map[int]string{ + TRACE: FG_WHITE + BG_PURPLE, DEBUG: DIM + FG_BLACK + BG_DGRAY, INFO: FG_WHITE + BG_GREEN, IMPORTANT: FG_WHITE + BG_LBLUE, @@ -163,15 +168,14 @@ func GetLogMicro() bool { // Log prints out a text with the given color and format func Log(level int, format string, args ...interface{}) { - mutex.Lock() - defer mutex.Unlock() + mutex.RLock() + defer mutex.RUnlock() if level >= MinLevel { label := labels[level] color := colors[level] - datefmt := DateFormat - if LogMicro == true { + if LogMicro { datefmt = DateFormat + ".000000" } when := time.Now().UTC().Format(datefmt) @@ -221,6 +225,11 @@ func Close() { } } +// Trace is the log level for tracing purposes +func Trace(format string, args ...interface{}) { + Log(TRACE, format, args...) +} + // Debug is the log level for debugging purposes func Debug(format string, args ...interface{}) { Log(DEBUG, format, args...)