2017-02-20 03:11:13 -05:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-xorm/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
// XORMLogBridge a logger bridge from Logger to xorm
|
|
|
|
type XORMLogBridge struct {
|
|
|
|
showSQL bool
|
|
|
|
level core.LogLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// XORMLogger the logger for xorm
|
|
|
|
XORMLogger *XORMLogBridge
|
|
|
|
)
|
|
|
|
|
2019-04-02 02:48:31 -05:00
|
|
|
// InitXORMLogger inits a log bridge for xorm
|
|
|
|
func InitXORMLogger(showSQL bool) {
|
2017-02-22 06:44:51 -05:00
|
|
|
XORMLogger = &XORMLogBridge{
|
2019-04-02 02:48:31 -05:00
|
|
|
showSQL: showSQL,
|
2017-02-22 06:44:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 02:48:31 -05:00
|
|
|
// GetGiteaLevel returns the minimum Gitea logger level
|
|
|
|
func (l *XORMLogBridge) GetGiteaLevel() Level {
|
|
|
|
return GetLogger("xorm").GetLevel()
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
2019-04-02 02:48:31 -05:00
|
|
|
// Log a message with defined skip and at logging level
|
|
|
|
func (l *XORMLogBridge) Log(skip int, level Level, format string, v ...interface{}) error {
|
|
|
|
return GetLogger("xorm").Log(skip+1, level, format, v...)
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debug show debug log
|
|
|
|
func (l *XORMLogBridge) Debug(v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, DEBUG, fmt.Sprint(v...))
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Debugf show debug log
|
|
|
|
func (l *XORMLogBridge) Debugf(format string, v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, DEBUG, format, v...)
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Error show error log
|
|
|
|
func (l *XORMLogBridge) Error(v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, ERROR, fmt.Sprint(v...))
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Errorf show error log
|
|
|
|
func (l *XORMLogBridge) Errorf(format string, v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, ERROR, format, v...)
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Info show information level log
|
|
|
|
func (l *XORMLogBridge) Info(v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, INFO, fmt.Sprint(v...))
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Infof show information level log
|
|
|
|
func (l *XORMLogBridge) Infof(format string, v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, INFO, format, v...)
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
2017-03-14 19:52:01 -05:00
|
|
|
// Warn show warning log
|
2017-02-20 03:11:13 -05:00
|
|
|
func (l *XORMLogBridge) Warn(v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, WARN, fmt.Sprint(v...))
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Warnf show warnning log
|
|
|
|
func (l *XORMLogBridge) Warnf(format string, v ...interface{}) {
|
2019-04-02 02:48:31 -05:00
|
|
|
l.Log(2, WARN, format, v...)
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Level get logger level
|
|
|
|
func (l *XORMLogBridge) Level() core.LogLevel {
|
2019-04-02 02:48:31 -05:00
|
|
|
switch l.GetGiteaLevel() {
|
|
|
|
case TRACE, DEBUG:
|
|
|
|
return core.LOG_DEBUG
|
|
|
|
case INFO:
|
|
|
|
return core.LOG_INFO
|
|
|
|
case WARN:
|
|
|
|
return core.LOG_WARNING
|
|
|
|
case ERROR, CRITICAL:
|
|
|
|
return core.LOG_ERR
|
|
|
|
}
|
|
|
|
return core.LOG_OFF
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
2019-04-02 02:48:31 -05:00
|
|
|
// SetLevel set the logger level
|
|
|
|
func (l *XORMLogBridge) SetLevel(lvl core.LogLevel) {
|
2017-02-20 03:11:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|