maintain backward compatibility on engine's logging settings
This commit is contained in:
parent
8db467b435
commit
01b89af2ce
22
engine.go
22
engine.go
|
@ -177,6 +177,7 @@ func (engine *Engine) Ping() error {
|
||||||
// logging sql
|
// logging sql
|
||||||
func (engine *Engine) logSQL(sqlStr string, sqlArgs ...interface{}) {
|
func (engine *Engine) logSQL(sqlStr string, sqlArgs ...interface{}) {
|
||||||
if engine.ShowSQL {
|
if engine.ShowSQL {
|
||||||
|
overrideLogLevel(LOG_INFO)
|
||||||
if len(sqlArgs) > 0 {
|
if len(sqlArgs) > 0 {
|
||||||
engine.Logger.Info(fmt.Sprintf("[sql] %v [args] %v", sqlStr, sqlArgs))
|
engine.Logger.Info(fmt.Sprintf("[sql] %v [args] %v", sqlStr, sqlArgs))
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,27 +187,42 @@ func (engine *Engine) logSQL(sqlStr string, sqlArgs ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// logging error
|
// logging error
|
||||||
|
func (engine *Engine) overrideLogLevel(overrideLevel core.LogLevel) {
|
||||||
|
logLevel := engine.Logger.Level()
|
||||||
|
if logLevel == core.LOG_UNKNOWN {
|
||||||
|
// intend to left empty
|
||||||
|
}
|
||||||
|
else if logLevel < core.overrideLevel { // TODO can remove if deprecated engine.ShowErr
|
||||||
|
engine.Logger.SetLevel(LOG_ERR) // try override logger's log level
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (engine *Engine) LogError(contents ...interface{}) {
|
func (engine *Engine) LogError(contents ...interface{}) {
|
||||||
if engine.ShowErr {
|
if engine.ShowErr {
|
||||||
|
overrideLogLevel(LOG_ERR)
|
||||||
engine.Logger.Err(contents...)
|
engine.Logger.Err(contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) LogErrorf(format string, contents ...interface{}) {
|
func (engine *Engine) LogErrorf(format string, contents ...interface{}) {
|
||||||
if engine.ShowErr {
|
if engine.ShowErr {
|
||||||
engine.Logger.Err(fmt.Sprintf(format, contents...))
|
overrideLogLevel(LOG_ERR)
|
||||||
|
engine.Logger.Errf(format, contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// logging info
|
// logging info
|
||||||
func (engine *Engine) LogInfo(contents ...interface{}) {
|
func (engine *Engine) LogInfo(contents ...interface{}) {
|
||||||
if engine.ShowInfo {
|
if engine.ShowInfo {
|
||||||
|
overrideLogLevel(LOG_INFO)
|
||||||
engine.Logger.Info(contents...)
|
engine.Logger.Info(contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) LogInfof(format string, contents ...interface{}) {
|
func (engine *Engine) LogInfof(format string, contents ...interface{}) {
|
||||||
if engine.ShowErr {
|
if engine.ShowErr {
|
||||||
|
overrideLogLevel(LOG_INFO)
|
||||||
engine.Logger.Infof(format, contents...)
|
engine.Logger.Infof(format, contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,12 +230,14 @@ func (engine *Engine) LogInfof(format string, contents ...interface{}) {
|
||||||
// logging debug
|
// logging debug
|
||||||
func (engine *Engine) LogDebug(contents ...interface{}) {
|
func (engine *Engine) LogDebug(contents ...interface{}) {
|
||||||
if engine.ShowDebug {
|
if engine.ShowDebug {
|
||||||
|
overrideLogLevel(LOG_DEBUG)
|
||||||
engine.Logger.Debug(contents...)
|
engine.Logger.Debug(contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) LogDebugf(format string, contents ...interface{}) {
|
func (engine *Engine) LogDebugf(format string, contents ...interface{}) {
|
||||||
if engine.ShowDebug {
|
if engine.ShowDebug {
|
||||||
|
overrideLogLevel(LOG_DEBUG)
|
||||||
engine.Logger.Debugf(format, contents...)
|
engine.Logger.Debugf(format, contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,12 +245,14 @@ func (engine *Engine) LogDebugf(format string, contents ...interface{}) {
|
||||||
// logging warn
|
// logging warn
|
||||||
func (engine *Engine) LogWarn(contents ...interface{}) {
|
func (engine *Engine) LogWarn(contents ...interface{}) {
|
||||||
if engine.ShowWarn {
|
if engine.ShowWarn {
|
||||||
|
overrideLogLevel(LOG_WARNING)
|
||||||
engine.Logger.Warning(contents...)
|
engine.Logger.Warning(contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) LogWarnf(format string, contents ...interface{}) {
|
func (engine *Engine) LogWarnf(format string, contents ...interface{}) {
|
||||||
if engine.ShowWarn {
|
if engine.ShowWarn {
|
||||||
|
overrideLogLevel(LOG_WARNING)
|
||||||
engine.Logger.Warningf(format, contents...)
|
engine.Logger.Warningf(format, contents...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue