1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 20:20:49 +00:00

This makes the logger instance a singleton

This commit is contained in:
Faissal Elamraoui 2016-11-16 12:33:01 +01:00
parent 21fc177551
commit 6b27ef186a
2 changed files with 12 additions and 3 deletions

2
bee.go
View File

@ -90,6 +90,8 @@ var commands = []*Command{
cmdFix,
}
var logger = GetBeeLogger(os.Stdout)
func main() {
flag.Usage = usage
flag.Parse()

View File

@ -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