You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.5 KiB
108 lines
2.5 KiB
8 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package db
|
||
8 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
6 years ago
|
"code.gitea.io/gitea/modules/log"
|
||
|
|
||
5 years ago
|
xormlog "xorm.io/xorm/log"
|
||
8 years ago
|
)
|
||
|
|
||
|
// XORMLogBridge a logger bridge from Logger to xorm
|
||
|
type XORMLogBridge struct {
|
||
|
showSQL bool
|
||
4 years ago
|
logger log.Logger
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
// NewXORMLogger inits a log bridge for xorm
|
||
5 years ago
|
func NewXORMLogger(showSQL bool) xormlog.Logger {
|
||
6 years ago
|
return &XORMLogBridge{
|
||
6 years ago
|
showSQL: showSQL,
|
||
6 years ago
|
logger: log.GetLogger("xorm"),
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
const stackLevel = 8
|
||
|
|
||
6 years ago
|
// Log a message with defined skip and at logging level
|
||
6 years ago
|
func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...interface{}) error {
|
||
|
return l.logger.Log(skip+1, level, format, v...)
|
||
8 years ago
|
}
|
||
|
|
||
|
// Debug show debug log
|
||
|
func (l *XORMLogBridge) Debug(v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.DEBUG, fmt.Sprint(v...))
|
||
8 years ago
|
}
|
||
|
|
||
|
// Debugf show debug log
|
||
|
func (l *XORMLogBridge) Debugf(format string, v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.DEBUG, format, v...)
|
||
8 years ago
|
}
|
||
|
|
||
|
// Error show error log
|
||
|
func (l *XORMLogBridge) Error(v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.ERROR, fmt.Sprint(v...))
|
||
8 years ago
|
}
|
||
|
|
||
|
// Errorf show error log
|
||
|
func (l *XORMLogBridge) Errorf(format string, v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.ERROR, format, v...)
|
||
8 years ago
|
}
|
||
|
|
||
|
// Info show information level log
|
||
|
func (l *XORMLogBridge) Info(v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.INFO, fmt.Sprint(v...))
|
||
8 years ago
|
}
|
||
|
|
||
|
// Infof show information level log
|
||
|
func (l *XORMLogBridge) Infof(format string, v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.INFO, format, v...)
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// Warn show warning log
|
||
8 years ago
|
func (l *XORMLogBridge) Warn(v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.WARN, fmt.Sprint(v...))
|
||
8 years ago
|
}
|
||
|
|
||
|
// Warnf show warnning log
|
||
|
func (l *XORMLogBridge) Warnf(format string, v ...interface{}) {
|
||
4 years ago
|
_ = l.Log(stackLevel, log.WARN, format, v...)
|
||
8 years ago
|
}
|
||
|
|
||
|
// Level get logger level
|
||
5 years ago
|
func (l *XORMLogBridge) Level() xormlog.LogLevel {
|
||
6 years ago
|
switch l.logger.GetLevel() {
|
||
|
case log.TRACE, log.DEBUG:
|
||
5 years ago
|
return xormlog.LOG_DEBUG
|
||
6 years ago
|
case log.INFO:
|
||
5 years ago
|
return xormlog.LOG_INFO
|
||
6 years ago
|
case log.WARN:
|
||
5 years ago
|
return xormlog.LOG_WARNING
|
||
6 years ago
|
case log.ERROR, log.CRITICAL:
|
||
5 years ago
|
return xormlog.LOG_ERR
|
||
6 years ago
|
}
|
||
5 years ago
|
return xormlog.LOG_OFF
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
// SetLevel set the logger level
|
||
5 years ago
|
func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel) {
|
||
8 years ago
|
}
|
||
|
|
||
|
// ShowSQL set if record SQL
|
||
|
func (l *XORMLogBridge) ShowSQL(show ...bool) {
|
||
|
if len(show) > 0 {
|
||
|
l.showSQL = show[0]
|
||
|
} else {
|
||
|
l.showSQL = true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// IsShowSQL if record SQL
|
||
|
func (l *XORMLogBridge) IsShowSQL() bool {
|
||
|
return l.showSQL
|
||
|
}
|