From 45ab79249aabf37dc4259ba24ac69a759878681c Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Sun, 21 Feb 2021 12:15:45 +0800 Subject: [PATCH] Add when to write method --- CHANGELOG.md | 1 + core/logs/log.go | 2 ++ core/logs/log_test.go | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3d3f760..fc786fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # developing +- Fix 4503 and 4504: Add `when` to `Write([]byte)` method and add `prefix` to `writeMsg`. [4507](https://github.com/beego/beego/pull/4507) - Fix 4480: log format incorrect. [4482](https://github.com/beego/beego/pull/4482) - Remove `duration` from prometheus labels. [4391](https://github.com/beego/beego/pull/4391) - Fix `unknown escape sequence` in generated code. [4385](https://github.com/beego/beego/pull/4385) diff --git a/core/logs/log.go b/core/logs/log.go index ef9aa7f3..52d3007f 100644 --- a/core/logs/log.go +++ b/core/logs/log.go @@ -261,6 +261,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) { lm := &LogMsg{ Msg: string(p), Level: levelLoggerImpl, + When: time.Now(), } // set levelLoggerImpl to ensure all log message will be write out @@ -291,6 +292,7 @@ func (bl *BeeLogger) writeMsg(lm *LogMsg) error { } lm.FilePath = file lm.LineNumber = line + lm.Prefix = bl.prefix lm.enableFullFilePath = bl.enableFullFilePath lm.enableFuncCallDepth = bl.enableFuncCallDepth diff --git a/core/logs/log_test.go b/core/logs/log_test.go index d7728c76..b65d8dbb 100644 --- a/core/logs/log_test.go +++ b/core/logs/log_test.go @@ -25,4 +25,9 @@ func TestBeeLoggerDelLogger(t *testing.T) { prefix := "My-Cus" l := GetLogger(prefix) assert.NotNil(t, l) + l.Print("hello") + + GetLogger().Print("hello") + SetPrefix("aaa") + Info("hello") }