mirror of
https://github.com/beego/bee.git
synced 2024-11-25 20:10:55 +00:00
Initialize the logger templates inside the logger singleton once (and only once)
This commit is contained in:
parent
ab39926c41
commit
7fcbba0f53
14
logger.go
14
logger.go
@ -64,7 +64,10 @@ var (
|
|||||||
debugLogRecordTemplate *template.Template
|
debugLogRecordTemplate *template.Template
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// GetBeeLogger initializes the logger instance with a NewColorWriter output
|
||||||
|
// and returns a singleton
|
||||||
|
func GetBeeLogger(w io.Writer) *BeeLogger {
|
||||||
|
once.Do(func() {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
simpleLogFormat = `{{Now "2006/01/02 15:04:05"}} {{.Level}} ▶ {{.ID}} {{.Message}}{{EndLine}}`
|
simpleLogFormat = `{{Now "2006/01/02 15:04:05"}} {{.Level}} ▶ {{.ID}} {{.Message}}{{EndLine}}`
|
||||||
@ -76,16 +79,11 @@ func init() {
|
|||||||
"Now": Now,
|
"Now": Now,
|
||||||
"EndLine": EndLine,
|
"EndLine": EndLine,
|
||||||
}
|
}
|
||||||
logRecordTemplate, err = template.New("logRecordTemplate").Funcs(funcs).Parse(simpleLogFormat)
|
logRecordTemplate, err = template.New("simpleLogFormat").Funcs(funcs).Parse(simpleLogFormat)
|
||||||
MustCheck(err)
|
MustCheck(err)
|
||||||
debugLogRecordTemplate, err = template.New("dbgLogRecordTemplate").Funcs(funcs).Parse(debugLogFormat)
|
debugLogRecordTemplate, err = template.New("debugLogFormat").Funcs(funcs).Parse(debugLogFormat)
|
||||||
MustCheck(err)
|
MustCheck(err)
|
||||||
}
|
|
||||||
|
|
||||||
// GetBeeLogger initializes the logger instance with a NewColorWriter output
|
|
||||||
// and returns a singleton
|
|
||||||
func GetBeeLogger(w io.Writer) *BeeLogger {
|
|
||||||
once.Do(func() {
|
|
||||||
instance = &BeeLogger{output: NewColorWriter(w)}
|
instance = &BeeLogger{output: NewColorWriter(w)}
|
||||||
})
|
})
|
||||||
return instance
|
return instance
|
||||||
|
Loading…
Reference in New Issue
Block a user