Revert "logs:default support fileline"

This reverts commit 1f26852610.
This commit is contained in:
astaxie
2014-10-30 16:57:48 +08:00
parent ecd0a5487e
commit 68c3bdfdd4
5 changed files with 38 additions and 9 deletions

View File

@@ -34,7 +34,8 @@ package logs
import (
"fmt"
"path"
"runtime"
"sync"
)
@@ -87,10 +88,12 @@ func Register(name string, log loggerType) {
// BeeLogger is default logger in beego application.
// it can contain several providers and log message into all providers.
type BeeLogger struct {
lock sync.Mutex
level int
msg chan *logMsg
outputs map[string]LoggerInterface
lock sync.Mutex
level int
enableFuncCallDepth bool
loggerFuncCallDepth int
msg chan *logMsg
outputs map[string]LoggerInterface
}
type logMsg struct {
@@ -104,6 +107,7 @@ type logMsg struct {
func NewLogger(channellen int64) *BeeLogger {
bl := new(BeeLogger)
bl.level = LevelDebug
bl.loggerFuncCallDepth = 2
bl.msg = make(chan *logMsg, channellen)
bl.outputs = make(map[string]LoggerInterface)
//bl.SetLogger("console", "") // default output to console
@@ -149,7 +153,17 @@ func (bl *BeeLogger) writerMsg(loglevel int, msg string) error {
}
lm := new(logMsg)
lm.level = loglevel
lm.msg = msg
if bl.enableFuncCallDepth {
_, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth)
if ok {
_, filename := path.Split(file)
lm.msg = fmt.Sprintf("[%s:%d] %s", filename, line, msg)
} else {
lm.msg = msg
}
} else {
lm.msg = msg
}
bl.msg <- lm
return nil
}
@@ -162,6 +176,16 @@ func (bl *BeeLogger) SetLevel(l int) {
bl.level = l
}
// set log funcCallDepth
func (bl *BeeLogger) SetLogFuncCallDepth(d int) {
bl.loggerFuncCallDepth = d
}
// enable log funcCallDepth
func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
bl.enableFuncCallDepth = b
}
// start logger chan reading.
// when chan is not empty, write logs.
func (bl *BeeLogger) startLogger() {