mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 14:50:49 +00:00
add flush & read all chan data
This commit is contained in:
parent
690d77e985
commit
ba5e393e99
@ -65,6 +65,10 @@ func (c *ConnWriter) WriteMsg(msg string, level int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConnWriter) Flush() {
|
||||
|
||||
}
|
||||
|
||||
func (c *ConnWriter) Destroy() {
|
||||
if c.innerWriter == nil {
|
||||
return
|
||||
|
@ -42,6 +42,10 @@ func (c *ConsoleWriter) Destroy() {
|
||||
|
||||
}
|
||||
|
||||
func (c *ConsoleWriter) Flush() {
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register("console", NewConsole)
|
||||
}
|
||||
|
@ -237,6 +237,10 @@ func (w *FileLogWriter) Destroy() {
|
||||
w.mw.fd.Close()
|
||||
}
|
||||
|
||||
func (w *FileLogWriter) Flush() {
|
||||
w.mw.fd.Sync()
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register("file", NewFileWriter)
|
||||
}
|
||||
|
21
logs/log.go
21
logs/log.go
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,9 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SmtpWriter) Flush() {
|
||||
return
|
||||
}
|
||||
func (s *SmtpWriter) Destroy() {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user