mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
This makes the logger instance a singleton
This commit is contained in:
parent
21fc177551
commit
6b27ef186a
2
bee.go
2
bee.go
@ -90,6 +90,8 @@ var commands = []*Command{
|
||||
cmdFix,
|
||||
}
|
||||
|
||||
var logger = GetBeeLogger(os.Stdout)
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
13
logger.go
13
logger.go
@ -39,7 +39,8 @@ const (
|
||||
|
||||
var (
|
||||
sequenceNo uint64
|
||||
logger *BeeLogger
|
||||
instance *BeeLogger
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// BeeLogger logs logging records to the specified io.Writer
|
||||
@ -79,9 +80,15 @@ func init() {
|
||||
MustCheck(err)
|
||||
debugLogRecordTemplate, err = template.New("dbgLogRecordTemplate").Funcs(funcs).Parse(debugLogFormat)
|
||||
MustCheck(err)
|
||||
}
|
||||
|
||||
// Initialize the logger instance with a NewColorWriter output
|
||||
logger = &BeeLogger{output: NewColorWriter(os.Stdout)}
|
||||
// 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)}
|
||||
})
|
||||
return instance
|
||||
}
|
||||
|
||||
// SetOutput sets the logger output destination
|
||||
|
Loading…
Reference in New Issue
Block a user