1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 21:30:49 +00:00

remove from init method

This commit is contained in:
JessonChan 2016-03-25 15:04:52 +08:00
parent e59271662c
commit 826f81f479
2 changed files with 15 additions and 6 deletions

3
log.go
View File

@ -32,6 +32,9 @@ const (
LevelDebug
)
// BeeLogger references the used application logger.
var BeeLogger = logs.GetBeeLogger()
// SetLevel sets the global log level used by the simple logger.
func SetLevel(l int) {
logs.SetLevel(l)

View File

@ -120,6 +120,8 @@ type BeeLogger struct {
outputs []*nameLogger
}
const defaultAsyncMsgLen = 1e3
type nameLogger struct {
Logger
name string
@ -157,6 +159,9 @@ func (bl *BeeLogger) Async() *BeeLogger {
return bl
}
bl.asynchronous = true
if bl.msgChanLen <= 0 {
bl.msgChanLen = defaultAsyncMsgLen
}
bl.msgChan = make(chan *logMsg, bl.msgChanLen)
logMsgPool = &sync.Pool{
New: func() interface{} {
@ -250,6 +255,11 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
}
func (bl *BeeLogger) writeMsg(logLevel int, msg string, v ...interface{}) error {
if !beeLogger.init {
bl.lock.Lock()
bl.setLogger(AdapterConsole)
bl.lock.Unlock()
}
if logLevel == levelLoggerImpl {
// set to emergency to ensure all log will be print out correctly
logLevel = LevelEmergency
@ -465,12 +475,8 @@ func (bl *BeeLogger) flush() {
}
}
// BeeLogger references the used application logger.
var beeLogger *BeeLogger
func init() {
beeLogger = NewLogger()
}
// beeLogger references the used application logger.
var beeLogger *BeeLogger = NewLogger()
// GetLogger returns the default BeeLogger
func GetBeeLogger() *BeeLogger {