From 85473bc898488d88ee5c050576d015669465a74a Mon Sep 17 00:00:00 2001 From: Deng Ming Date: Tue, 20 Dec 2022 16:44:26 +0800 Subject: [PATCH] fix 5129: must set formatter after init the logger --- CHANGELOG.md | 6 +++--- core/logs/log.go | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4499ccb..0bfd3f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # developing - [Fix 5117: support write though cache](https://github.com/beego/beego/pull/5117) +- [add read through for cache module](https://github.com/beego/beego/pull/5116) +- [add singleflight cache for cache module](https://github.com/beego/beego/pull/5119) +- [Fix 5129: must set formatter after init the logger](https://github.com/beego/beego/pull/5130) # v2.0.7 - [Upgrade github.com/go-kit/kit, CVE-2022-24450](https://github.com/beego/beego/pull/5121) @@ -16,9 +19,6 @@ Note: now we force the web admin service serving HTTP only. - [Fix 5012: fix some bug, pass []any as any in variadic function](https://github.com/beego/beego/pull/5012) - [Fix 5022: Miss assigning listener to graceful Server](https://github.com/beego/beego/pull/5028) - [Fix 4955: Make commands and Docker compose for ORM unit tests](https://github.com/beego/beego/pull/5031) -- [add read through for cache module](https://github.com/beego/beego/pull/5116) -- [add singleflight cache for cache module](https://github.com/beego/beego/pull/5119) - # v2.0.4 diff --git a/core/logs/log.go b/core/logs/log.go index e5e736ca..1ebccbc1 100644 --- a/core/logs/log.go +++ b/core/logs/log.go @@ -41,8 +41,6 @@ import ( "strings" "sync" "time" - - "github.com/pkg/errors" ) // RFC5424 log message levels. @@ -193,20 +191,20 @@ func (bl *BeeLogger) setLogger(adapterName string, configs ...string) error { lg := logAdapter() + err := lg.Init(config) + if err != nil { + return err + } + // Global formatter overrides the default set formatter if len(bl.globalFormatter) > 0 { fmtr, ok := GetFormatter(bl.globalFormatter) if !ok { - return errors.New(fmt.Sprintf("the formatter with name: %s not found", bl.globalFormatter)) + return fmt.Errorf("the formatter with name: %s not found", bl.globalFormatter) } lg.SetFormatter(fmtr) } - err := lg.Init(config) - if err != nil { - fmt.Fprintln(os.Stderr, "logs.BeeLogger.SetLogger: "+err.Error()) - return err - } bl.outputs = append(bl.outputs, &nameLogger{name: adapterName, Logger: lg}) return nil }