Skip to content

Commit

Permalink
fix 5129: must set formatter after init the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Dec 20, 2022
1 parent f0a59fe commit 09815e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
14 changes: 6 additions & 8 deletions core/logs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import (
"strings"
"sync"
"time"

"github.com/pkg/errors"
)

// RFC5424 log message levels.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 09815e2

Please sign in to comment.