mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 19:41:00 +00:00
duplicate adapter logger bug fixed
This commit is contained in:
parent
22196d7841
commit
4801099675
24
logs/log.go
24
logs/log.go
@ -146,17 +146,25 @@ func (bl *BeeLogger) Async() *BeeLogger {
|
|||||||
func (bl *BeeLogger) SetLogger(adapterName string, config string) error {
|
func (bl *BeeLogger) SetLogger(adapterName string, config string) error {
|
||||||
bl.lock.Lock()
|
bl.lock.Lock()
|
||||||
defer bl.lock.Unlock()
|
defer bl.lock.Unlock()
|
||||||
if log, ok := adapters[adapterName]; ok {
|
|
||||||
lg := log()
|
for _, l := range bl.outputs {
|
||||||
err := lg.Init(config)
|
if l.name == adapterName {
|
||||||
if err != nil {
|
return fmt.Errorf("logs: duplicate adaptername %q (you have set this logger before)", adapterName)
|
||||||
fmt.Fprintln(os.Stderr, "logs.BeeLogger.SetLogger: "+err.Error())
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
bl.outputs = append(bl.outputs, &nameLogger{name: adapterName, Logger: lg})
|
}
|
||||||
} else {
|
|
||||||
|
log, ok := adapters[adapterName]
|
||||||
|
if !ok {
|
||||||
return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adapterName)
|
return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adapterName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lg := log()
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user