1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 23:01:28 +00:00

For enhancing performance, check log level before fmt.Sprintf()

This commit is contained in:
toalexjin 2015-03-25 15:14:57 +08:00 committed by astaxie
parent 1d8afdc9c9
commit 2e51c124f1

View File

@ -207,48 +207,72 @@ func (bl *BeeLogger) startLogger() {
// Log EMERGENCY level message. // Log EMERGENCY level message.
func (bl *BeeLogger) Emergency(format string, v ...interface{}) { func (bl *BeeLogger) Emergency(format string, v ...interface{}) {
if LevelEmergency > bl.level {
return
}
msg := fmt.Sprintf("[M] "+format, v...) msg := fmt.Sprintf("[M] "+format, v...)
bl.writerMsg(LevelEmergency, msg) bl.writerMsg(LevelEmergency, msg)
} }
// Log ALERT level message. // Log ALERT level message.
func (bl *BeeLogger) Alert(format string, v ...interface{}) { func (bl *BeeLogger) Alert(format string, v ...interface{}) {
if LevelAlert > bl.level {
return
}
msg := fmt.Sprintf("[A] "+format, v...) msg := fmt.Sprintf("[A] "+format, v...)
bl.writerMsg(LevelAlert, msg) bl.writerMsg(LevelAlert, msg)
} }
// Log CRITICAL level message. // Log CRITICAL level message.
func (bl *BeeLogger) Critical(format string, v ...interface{}) { func (bl *BeeLogger) Critical(format string, v ...interface{}) {
if LevelCritical > bl.level {
return
}
msg := fmt.Sprintf("[C] "+format, v...) msg := fmt.Sprintf("[C] "+format, v...)
bl.writerMsg(LevelCritical, msg) bl.writerMsg(LevelCritical, msg)
} }
// Log ERROR level message. // Log ERROR level message.
func (bl *BeeLogger) Error(format string, v ...interface{}) { func (bl *BeeLogger) Error(format string, v ...interface{}) {
if LevelError > bl.level {
return
}
msg := fmt.Sprintf("[E] "+format, v...) msg := fmt.Sprintf("[E] "+format, v...)
bl.writerMsg(LevelError, msg) bl.writerMsg(LevelError, msg)
} }
// Log WARNING level message. // Log WARNING level message.
func (bl *BeeLogger) Warning(format string, v ...interface{}) { func (bl *BeeLogger) Warning(format string, v ...interface{}) {
if LevelWarning > bl.level {
return
}
msg := fmt.Sprintf("[W] "+format, v...) msg := fmt.Sprintf("[W] "+format, v...)
bl.writerMsg(LevelWarning, msg) bl.writerMsg(LevelWarning, msg)
} }
// Log NOTICE level message. // Log NOTICE level message.
func (bl *BeeLogger) Notice(format string, v ...interface{}) { func (bl *BeeLogger) Notice(format string, v ...interface{}) {
if LevelNotice > bl.level {
return
}
msg := fmt.Sprintf("[N] "+format, v...) msg := fmt.Sprintf("[N] "+format, v...)
bl.writerMsg(LevelNotice, msg) bl.writerMsg(LevelNotice, msg)
} }
// Log INFORMATIONAL level message. // Log INFORMATIONAL level message.
func (bl *BeeLogger) Informational(format string, v ...interface{}) { func (bl *BeeLogger) Informational(format string, v ...interface{}) {
if LevelInformational > bl.level {
return
}
msg := fmt.Sprintf("[I] "+format, v...) msg := fmt.Sprintf("[I] "+format, v...)
bl.writerMsg(LevelInformational, msg) bl.writerMsg(LevelInformational, msg)
} }
// Log DEBUG level message. // Log DEBUG level message.
func (bl *BeeLogger) Debug(format string, v ...interface{}) { func (bl *BeeLogger) Debug(format string, v ...interface{}) {
if LevelDebug > bl.level {
return
}
msg := fmt.Sprintf("[D] "+format, v...) msg := fmt.Sprintf("[D] "+format, v...)
bl.writerMsg(LevelDebug, msg) bl.writerMsg(LevelDebug, msg)
} }