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

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

@ -65,6 +65,10 @@ func (c *ConnWriter) WriteMsg(msg string, level int) error {
return nil return nil
} }
func (c *ConnWriter) Flush() {
}
func (c *ConnWriter) Destroy() { func (c *ConnWriter) Destroy() {
if c.innerWriter == nil { if c.innerWriter == nil {
return return

View File

@ -42,6 +42,10 @@ func (c *ConsoleWriter) Destroy() {
} }
func (c *ConsoleWriter) Flush() {
}
func init() { func init() {
Register("console", NewConsole) Register("console", NewConsole)
} }

View File

@ -237,6 +237,10 @@ func (w *FileLogWriter) Destroy() {
w.mw.fd.Close() w.mw.fd.Close()
} }
func (w *FileLogWriter) Flush() {
w.mw.fd.Sync()
}
func init() { func init() {
Register("file", NewFileWriter) Register("file", NewFileWriter)
} }

View File

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

View File

@ -92,6 +92,9 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
return err return err
} }
func (s *SmtpWriter) Flush() {
return
}
func (s *SmtpWriter) Destroy() { func (s *SmtpWriter) Destroy() {
return return
} }