1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-29 11:21:29 +00:00

Merge pull request #1781 from JessonChan/develop

duplicate adapter logger  bug fixed
This commit is contained in:
astaxie 2016-03-11 11:19:07 +08:00
commit 778a5a11ac

View File

@ -146,7 +146,18 @@ func (bl *BeeLogger) Async() *BeeLogger {
func (bl *BeeLogger) SetLogger(adapterName string, config string) error {
bl.lock.Lock()
defer bl.lock.Unlock()
if log, ok := adapters[adapterName]; ok {
for _, l := range bl.outputs {
if l.name == adapterName {
return fmt.Errorf("logs: duplicate adaptername %q (you have set this logger before)", adapterName)
}
}
log, ok := adapters[adapterName]
if !ok {
return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adapterName)
}
lg := log()
err := lg.Init(config)
if err != nil {
@ -154,9 +165,6 @@ func (bl *BeeLogger) SetLogger(adapterName string, config string) error {
return err
}
bl.outputs = append(bl.outputs, &nameLogger{name: adapterName, Logger: lg})
} else {
return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adapterName)
}
return nil
}