From 00e986cd3b50a464ebb74b332144d87b93950066 Mon Sep 17 00:00:00 2001 From: chenlei106 Date: Tue, 23 Aug 2016 16:16:57 +0800 Subject: [PATCH] log output format improvement move log level info ahead to filename info, better readability --- logs/log.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/logs/log.go b/logs/log.go index c43782f3..3ff72447 100644 --- a/logs/log.go +++ b/logs/log.go @@ -260,12 +260,7 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error bl.setLogger(AdapterConsole) bl.lock.Unlock() } - if logLevel == levelLoggerImpl { - // set to emergency to ensure all log will be print out correctly - logLevel = LevelEmergency - } else { - msg = levelPrefix[logLevel] + msg - } + if len(v) > 0 { msg = fmt.Sprintf(msg, v...) } @@ -279,6 +274,15 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error _, filename := path.Split(file) msg = "[" + filename + ":" + strconv.FormatInt(int64(line), 10) + "] " + msg } + + //set level info in front of filename info + if logLevel == levelLoggerImpl { + // set to emergency to ensure all log will be print out correctly + logLevel = LevelEmergency + } else { + msg = levelPrefix[logLevel] + msg + } + if bl.asynchronous { lm := logMsgPool.Get().(*logMsg) lm.level = logLevel