mirror of
https://github.com/astaxie/beego.git
synced 2024-12-18 16:00:50 +00:00
make the BeegoLogger a adapter of http server ErrorLog
This commit is contained in:
parent
9872041f12
commit
c92c3fc8b5
2
app.go
2
app.go
@ -16,6 +16,7 @@ package beego
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/fcgi"
|
||||
@ -95,6 +96,7 @@ func (app *App) Run() {
|
||||
app.Server.Handler = app.Handlers
|
||||
app.Server.ReadTimeout = time.Duration(BConfig.Listen.ServerTimeOut) * time.Second
|
||||
app.Server.WriteTimeout = time.Duration(BConfig.Listen.ServerTimeOut) * time.Second
|
||||
app.Server.ErrorLog = log.New(BeeLogger, "", 0)
|
||||
|
||||
// run graceful mode
|
||||
if BConfig.Listen.Graceful {
|
||||
|
18
logs/log.go
18
logs/log.go
@ -196,6 +196,22 @@ func (bl *BeeLogger) writeToLoggers(when time.Time, msg string, level int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (bl *BeeLogger) Write(p []byte) (n int, err error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
// writeMsg will always add a '\n' character
|
||||
if p[len(p)-1] == '\n' {
|
||||
p = p[0 : len(p)-1]
|
||||
}
|
||||
// set LevelCritical to ensure all log message will be write out
|
||||
err = bl.writeMsg(LevelCritical, string(p))
|
||||
if err == nil {
|
||||
return len(p), err
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func (bl *BeeLogger) writeMsg(logLevel int, msg string) error {
|
||||
when := time.Now()
|
||||
if bl.enableFuncCallDepth {
|
||||
@ -205,7 +221,7 @@ func (bl *BeeLogger) writeMsg(logLevel int, msg string) error {
|
||||
line = 0
|
||||
}
|
||||
_, filename := path.Split(file)
|
||||
msg = "[" + filename + ":" + strconv.FormatInt(int64(line), 10) + "]" + msg
|
||||
msg = "[" + filename + ":" + strconv.FormatInt(int64(line), 10) + "] " + msg
|
||||
}
|
||||
if bl.asynchronous {
|
||||
lm := logMsgPool.Get().(*logMsg)
|
||||
|
Loading…
Reference in New Issue
Block a user