From 52713b8d85e26a984ecaeef926c815e8cf8075b7 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期四, 07 十一月 2019 19:24:17 +0800 Subject: [PATCH] --- --- logger/logger.go | 54 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 31 insertions(+), 23 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 72314ff..82d7a77 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -17,47 +17,47 @@ InfoLevel DebugLevel ) - +var loggerString string = "" const ( color_red = uint8(iota + 91) - color_green // 缁� - color_yellow // 榛� - color_blue // 钃� - color_magenta // 娲嬬孩 + color_green // 缁� + color_yellow // 榛� + color_blue // 钃� + color_magenta // 娲嬬孩 ) const ( - fatalPrefix = "[FATAL] " - errorPrefix = "[ERROR] " - warnPrefix = "[WARN] " - infoPrefix = "[INFO] " - debugPrefix = "[DEBUG] " + fatalPrefix = "[FATAL] " + errorPrefix = "[ERROR] " + warnPrefix = "[WARN] " + infoPrefix = "[INFO] " + debugPrefix = "[DEBUG] " ) const ( - ByDay int = iota + ByDay int = iota ByWeek ByMonth BySize ) type LogFile struct { - level int // 鏃ュ織绛夌骇 - saveMode int // 淇濆瓨妯″紡 - saveDays int // 鏃ュ織淇濆瓨澶╂暟 - logTime int64 // - fileName string // 鏃ュ織鏂囦欢鍚� - filesize int64 // 鏂囦欢澶у皬, 闇�瑕佽缃� saveMode 涓� BySize 鐢熸晥 + level int // 鏃ュ織绛夌骇 + saveMode int // 淇濆瓨妯″紡 + saveDays int // 鏃ュ織淇濆瓨澶╂暟 + logTime int64 // + fileName string // 鏃ュ織鏂囦欢鍚� + filesize int64 // 鏂囦欢澶у皬, 闇�瑕佽缃� saveMode 涓� BySize 鐢熸晥 fileFd *os.File } var logFile LogFile func init() { - logFile.saveMode = ByDay // 榛樿鎸夊ぉ淇濆瓨 - logFile.saveDays = 15 // 榛樿淇濆瓨涓夊ぉ鐨� - logFile.level = ErrorLevel - logFile.filesize = 1024 * 1024 * 10 // 榛樿10M锛� 闇�瑕佽缃� saveMode 涓� BySize + logFile.saveMode = ByDay // 榛樿鎸夊ぉ淇濆瓨 + logFile.saveDays = 7 // 榛樿淇濆瓨涓夊ぉ鐨� + logFile.level = DebugLevel + //logFile.filesize = 1024 * 1024 * 10 // 榛樿10M锛� 闇�瑕佽缃� saveMode 涓� BySize } func Config(logFolder string, level int) { @@ -92,6 +92,7 @@ if logFile.level >= DebugLevel { log.SetPrefix(blue(debugPrefix)) _ = log.Output(2, fmt.Sprintln(args...)) + //loggerString += fmt.Sprintln(args...) } } @@ -99,6 +100,7 @@ if logFile.level >= InfoLevel { log.SetPrefix(green(infoPrefix)) _ = log.Output(2, fmt.Sprintln(args...)) + //loggerString += fmt.Sprintln(args...) } } @@ -106,6 +108,7 @@ if logFile.level >= WarnLevel { log.SetPrefix(magenta(warnPrefix)) _ = log.Output(2, fmt.Sprintln(args...)) + //loggerString += fmt.Sprintln(args...) } } @@ -113,14 +116,19 @@ if logFile.level >= ErrorLevel { log.SetPrefix(red(errorPrefix)) _ = log.Output(2, fmt.Sprintln(args...)) + //loggerString += fmt.Sprintln(args...) } } -func Fatalf(args ...interface{}) { +func Fatal(args ...interface{}) { if logFile.level >= FatalLevel { log.SetPrefix(red(fatalPrefix)) _ = log.Output(2, fmt.Sprintln(args...)) + //loggerString += fmt.Sprintln(args...) } +} +func OutPutByPanlei() { + _ = log.Output(2, loggerString) } func GetRedPrefix(s string) string { @@ -167,7 +175,7 @@ logFile.logTime = time.Now().Unix() } } - default: // 榛樿鎸夊ぉ ByDay + default: // 榛樿鎸夊ぉ ByDay if logFile.logTime+3600 < time.Now().Unix() { logFile.createLogFile() logFile.logTime = time.Now().Unix() -- Gitblit v1.8.0