fix4791: delay to format parameter

This commit is contained in:
Deng Ming 2021-10-25 22:22:09 +08:00
parent 99d26b06b4
commit fe4b84e4f6
3 changed files with 15 additions and 14 deletions

View File

@ -69,6 +69,7 @@
- Fix 4759: fix numeric notation of permissions [4759](https://github.com/beego/beego/pull/4759) - Fix 4759: fix numeric notation of permissions [4759](https://github.com/beego/beego/pull/4759)
- set default rate and capacity for ratelimit filter [4796](https://github.com/beego/beego/pull/4796) - set default rate and capacity for ratelimit filter [4796](https://github.com/beego/beego/pull/4796)
- Fix 4782: must set status before rendering error page [4797](https://github.com/beego/beego/pull/4797) - Fix 4782: must set status before rendering error page [4797](https://github.com/beego/beego/pull/4797)
- Fix 4791: delay to format parameter in log module [4804](https://github.com/beego/beego/pull/4804)
## Fix Sonar ## Fix Sonar

View File

@ -60,7 +60,7 @@ func GetFormatter(name string) (LogFormatter, bool) {
return res, ok return res, ok
} }
// 'w' when, 'm' msg,'f' filename'F' full path'n' line number // ToString 'w' when, 'm' msg,'f' filename'F' full path'n' line number
// 'l' level number, 't' prefix of level type, 'T' full name of level type // 'l' level number, 't' prefix of level type, 'T' full name of level type
func (p *PatternLogFormatter) ToString(lm *LogMsg) string { func (p *PatternLogFormatter) ToString(lm *LogMsg) string {
s := []rune(p.Pattern) s := []rune(p.Pattern)

View File

@ -705,61 +705,61 @@ func SetLogger(adapter string, config ...string) error {
// Emergency logs a message at emergency level. // Emergency logs a message at emergency level.
func Emergency(f interface{}, v ...interface{}) { func Emergency(f interface{}, v ...interface{}) {
beeLogger.Emergency(formatLog(f, v...)) beeLogger.Emergency(formatPattern(f, v...), v...)
} }
// Alert logs a message at alert level. // Alert logs a message at alert level.
func Alert(f interface{}, v ...interface{}) { func Alert(f interface{}, v ...interface{}) {
beeLogger.Alert(formatLog(f, v...)) beeLogger.Alert(formatPattern(f, v...), v...)
} }
// Critical logs a message at critical level. // Critical logs a message at critical level.
func Critical(f interface{}, v ...interface{}) { func Critical(f interface{}, v ...interface{}) {
beeLogger.Critical(formatLog(f, v...)) beeLogger.Critical(formatPattern(f, v...), v...)
} }
// Error logs a message at error level. // Error logs a message at error level.
func Error(f interface{}, v ...interface{}) { func Error(f interface{}, v ...interface{}) {
beeLogger.Error(formatLog(f, v...)) beeLogger.Error(formatPattern(f, v...), v...)
} }
// Warning logs a message at warning level. // Warning logs a message at warning level.
func Warning(f interface{}, v ...interface{}) { func Warning(f interface{}, v ...interface{}) {
beeLogger.Warn(formatLog(f, v...)) beeLogger.Warn(formatPattern(f, v...), v...)
} }
// Warn compatibility alias for Warning() // Warn compatibility alias for Warning()
func Warn(f interface{}, v ...interface{}) { func Warn(f interface{}, v ...interface{}) {
beeLogger.Warn(formatLog(f, v...)) beeLogger.Warn(formatPattern(f, v...), v...)
} }
// Notice logs a message at notice level. // Notice logs a message at notice level.
func Notice(f interface{}, v ...interface{}) { func Notice(f interface{}, v ...interface{}) {
beeLogger.Notice(formatLog(f, v...)) beeLogger.Notice(formatPattern(f, v...), v...)
} }
// Informational logs a message at info level. // Informational logs a message at info level.
func Informational(f interface{}, v ...interface{}) { func Informational(f interface{}, v ...interface{}) {
beeLogger.Info(formatLog(f, v...)) beeLogger.Info(formatPattern(f, v...), v...)
} }
// Info compatibility alias for Warning() // Info compatibility alias for Warning()
func Info(f interface{}, v ...interface{}) { func Info(f interface{}, v ...interface{}) {
beeLogger.Info(formatLog(f, v...)) beeLogger.Info(formatPattern(f, v...), v...)
} }
// Debug logs a message at debug level. // Debug logs a message at debug level.
func Debug(f interface{}, v ...interface{}) { func Debug(f interface{}, v ...interface{}) {
beeLogger.Debug(formatLog(f, v...)) beeLogger.Debug(formatPattern(f, v...), v...)
} }
// Trace logs a message at trace level. // Trace logs a message at trace level.
// compatibility alias for Warning() // compatibility alias for Warning()
func Trace(f interface{}, v ...interface{}) { func Trace(f interface{}, v ...interface{}) {
beeLogger.Trace(formatLog(f, v...)) beeLogger.Trace(formatPattern(f, v...), v...)
} }
func formatLog(f interface{}, v ...interface{}) string { func formatPattern(f interface{}, v ...interface{}) string {
var msg string var msg string
switch f.(type) { switch f.(type) {
case string: case string:
@ -778,5 +778,5 @@ func formatLog(f interface{}, v ...interface{}) string {
} }
msg += strings.Repeat(" %v", len(v)) msg += strings.Repeat(" %v", len(v))
} }
return fmt.Sprintf(msg, v...) return msg
} }