add flush & read all chan data

This commit is contained in:
astaxie
2013-11-27 17:50:10 +08:00
parent 690d77e985
commit ba5e393e99
5 changed files with 35 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ type LoggerInterface interface {
Init(config string) error
WriteMsg(msg string, level int) error
Destroy()
Flush()
}
var adapters = make(map[string]loggerType)
@@ -140,8 +141,26 @@ func (bl *BeeLogger) Critical(format string, v ...interface{}) {
bl.writerMsg(LevelCritical, msg)
}
func (bl *BeeLogger) Close() {
//flush all chan data
func (bl *BeeLogger) Flush() {
for _, l := range bl.outputs {
l.Flush()
}
}
func (bl *BeeLogger) Close() {
for {
if len(bl.msg) > 0 {
bm := <-bl.msg
for _, l := range bl.outputs {
l.WriteMsg(bm.msg, bm.level)
}
} else {
break
}
}
for _, l := range bl.outputs {
l.Flush()
l.Destroy()
}
}