diff options
Diffstat (limited to 'models/db/log.go')
-rw-r--r-- | models/db/log.go | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/models/db/log.go b/models/db/log.go index fec2ea3c3d..dd95f64ca8 100644 --- a/models/db/log.go +++ b/models/db/log.go @@ -14,67 +14,62 @@ import ( // XORMLogBridge a logger bridge from Logger to xorm type XORMLogBridge struct { - showSQLint *int32 - logger log.Logger + showSQL atomic.Bool + logger log.Logger } // NewXORMLogger inits a log bridge for xorm func NewXORMLogger(showSQL bool) xormlog.Logger { - showSQLint := int32(0) - if showSQL { - showSQLint = 1 - } - return &XORMLogBridge{ - showSQLint: &showSQLint, - logger: log.GetLogger("xorm"), - } + l := &XORMLogBridge{logger: log.GetLogger("xorm")} + l.showSQL.Store(showSQL) + return l } const stackLevel = 8 // Log a message with defined skip and at logging level -func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...interface{}) error { - return l.logger.Log(skip+1, level, format, v...) +func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...interface{}) { + l.logger.Log(skip+1, level, format, v...) } // Debug show debug log func (l *XORMLogBridge) Debug(v ...interface{}) { - _ = l.Log(stackLevel, log.DEBUG, fmt.Sprint(v...)) + l.Log(stackLevel, log.DEBUG, "%s", fmt.Sprint(v...)) } // Debugf show debug log func (l *XORMLogBridge) Debugf(format string, v ...interface{}) { - _ = l.Log(stackLevel, log.DEBUG, format, v...) + l.Log(stackLevel, log.DEBUG, format, v...) } // Error show error log func (l *XORMLogBridge) Error(v ...interface{}) { - _ = l.Log(stackLevel, log.ERROR, fmt.Sprint(v...)) + l.Log(stackLevel, log.ERROR, "%s", fmt.Sprint(v...)) } // Errorf show error log func (l *XORMLogBridge) Errorf(format string, v ...interface{}) { - _ = l.Log(stackLevel, log.ERROR, format, v...) + l.Log(stackLevel, log.ERROR, format, v...) } // Info show information level log func (l *XORMLogBridge) Info(v ...interface{}) { - _ = l.Log(stackLevel, log.INFO, fmt.Sprint(v...)) + l.Log(stackLevel, log.INFO, "%s", fmt.Sprint(v...)) } // Infof show information level log func (l *XORMLogBridge) Infof(format string, v ...interface{}) { - _ = l.Log(stackLevel, log.INFO, format, v...) + l.Log(stackLevel, log.INFO, format, v...) } // Warn show warning log func (l *XORMLogBridge) Warn(v ...interface{}) { - _ = l.Log(stackLevel, log.WARN, fmt.Sprint(v...)) + l.Log(stackLevel, log.WARN, "%s", fmt.Sprint(v...)) } // Warnf show warnning log func (l *XORMLogBridge) Warnf(format string, v ...interface{}) { - _ = l.Log(stackLevel, log.WARN, format, v...) + l.Log(stackLevel, log.WARN, format, v...) } // Level get logger level @@ -86,10 +81,12 @@ func (l *XORMLogBridge) Level() xormlog.LogLevel { return xormlog.LOG_INFO case log.WARN: return xormlog.LOG_WARNING - case log.ERROR, log.CRITICAL: + case log.ERROR: return xormlog.LOG_ERR + case log.NONE: + return xormlog.LOG_OFF } - return xormlog.LOG_OFF + return xormlog.LOG_UNKNOWN } // SetLevel set the logger level @@ -98,16 +95,13 @@ func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel) { // ShowSQL set if record SQL func (l *XORMLogBridge) ShowSQL(show ...bool) { - showSQL := int32(1) - if len(show) > 0 && !show[0] { - showSQL = 0 + if len(show) == 0 { + show = []bool{true} } - atomic.StoreInt32(l.showSQLint, showSQL) + l.showSQL.Store(show[0]) } // IsShowSQL if record SQL func (l *XORMLogBridge) IsShowSQL() bool { - showSQL := atomic.LoadInt32(l.showSQLint) - - return showSQL == 1 + return l.showSQL.Load() } |