1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 08:10:58 +00:00

beego: fix log output when SetLogger has error

This commit is contained in:
slene 2014-04-04 07:33:13 +08:00
parent d58e9e6e12
commit acbdeb62e8
2 changed files with 6 additions and 2 deletions

View File

@ -43,6 +43,9 @@ func NewConsole() LoggerInterface {
// init console logger. // init console logger.
// jsonconfig like '{"level":LevelTrace}'. // jsonconfig like '{"level":LevelTrace}'.
func (c *ConsoleWriter) Init(jsonconfig string) error { func (c *ConsoleWriter) Init(jsonconfig string) error {
if len(jsonconfig) == 0 {
return nil
}
err := json.Unmarshal([]byte(jsonconfig), c) err := json.Unmarshal([]byte(jsonconfig), c)
if err != nil { if err != nil {
return err return err

View File

@ -79,14 +79,15 @@ func (bl *BeeLogger) SetLogger(adaptername string, config string) error {
if log, ok := adapters[adaptername]; ok { if log, ok := adapters[adaptername]; ok {
lg := log() lg := log()
err := lg.Init(config) err := lg.Init(config)
bl.outputs[adaptername] = lg
if err != nil { if err != nil {
fmt.Println("logs.BeeLogger.SetLogger: " + err.Error())
return err return err
} }
bl.outputs[adaptername] = lg
return nil
} else { } else {
return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adaptername) return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adaptername)
} }
return nil
} }
// remove a logger adapter in BeeLogger. // remove a logger adapter in BeeLogger.