|
|
@ -2,11 +2,13 @@ |
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package log |
|
|
|
package models |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
|
|
|
|
"github.com/go-xorm/core" |
|
|
|
) |
|
|
|
|
|
|
@ -14,80 +16,72 @@ import ( |
|
|
|
type XORMLogBridge struct { |
|
|
|
showSQL bool |
|
|
|
level core.LogLevel |
|
|
|
logger *log.Logger |
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
|
// XORMLogger the logger for xorm
|
|
|
|
XORMLogger *XORMLogBridge |
|
|
|
) |
|
|
|
|
|
|
|
// InitXORMLogger inits a log bridge for xorm
|
|
|
|
func InitXORMLogger(showSQL bool) { |
|
|
|
XORMLogger = &XORMLogBridge{ |
|
|
|
// NewXORMLogger inits a log bridge for xorm
|
|
|
|
func NewXORMLogger(showSQL bool) core.ILogger { |
|
|
|
return &XORMLogBridge{ |
|
|
|
showSQL: showSQL, |
|
|
|
logger: log.GetLogger("xorm"), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// GetGiteaLevel returns the minimum Gitea logger level
|
|
|
|
func (l *XORMLogBridge) GetGiteaLevel() Level { |
|
|
|
return GetLogger("xorm").GetLevel() |
|
|
|
} |
|
|
|
|
|
|
|
// 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...) |
|
|
|
func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...interface{}) error { |
|
|
|
return l.logger.Log(skip+1, level, format, v...) |
|
|
|
} |
|
|
|
|
|
|
|
// Debug show debug log
|
|
|
|
func (l *XORMLogBridge) Debug(v ...interface{}) { |
|
|
|
l.Log(2, DEBUG, fmt.Sprint(v...)) |
|
|
|
l.Log(2, log.DEBUG, fmt.Sprint(v...)) |
|
|
|
} |
|
|
|
|
|
|
|
// Debugf show debug log
|
|
|
|
func (l *XORMLogBridge) Debugf(format string, v ...interface{}) { |
|
|
|
l.Log(2, DEBUG, format, v...) |
|
|
|
l.Log(2, log.DEBUG, format, v...) |
|
|
|
} |
|
|
|
|
|
|
|
// Error show error log
|
|
|
|
func (l *XORMLogBridge) Error(v ...interface{}) { |
|
|
|
l.Log(2, ERROR, fmt.Sprint(v...)) |
|
|
|
l.Log(2, log.ERROR, fmt.Sprint(v...)) |
|
|
|
} |
|
|
|
|
|
|
|
// Errorf show error log
|
|
|
|
func (l *XORMLogBridge) Errorf(format string, v ...interface{}) { |
|
|
|
l.Log(2, ERROR, format, v...) |
|
|
|
l.Log(2, log.ERROR, format, v...) |
|
|
|
} |
|
|
|
|
|
|
|
// Info show information level log
|
|
|
|
func (l *XORMLogBridge) Info(v ...interface{}) { |
|
|
|
l.Log(2, INFO, fmt.Sprint(v...)) |
|
|
|
l.Log(2, log.INFO, fmt.Sprint(v...)) |
|
|
|
} |
|
|
|
|
|
|
|
// Infof show information level log
|
|
|
|
func (l *XORMLogBridge) Infof(format string, v ...interface{}) { |
|
|
|
l.Log(2, INFO, format, v...) |
|
|
|
l.Log(2, log.INFO, format, v...) |
|
|
|
} |
|
|
|
|
|
|
|
// Warn show warning log
|
|
|
|
func (l *XORMLogBridge) Warn(v ...interface{}) { |
|
|
|
l.Log(2, WARN, fmt.Sprint(v...)) |
|
|
|
l.Log(2, log.WARN, fmt.Sprint(v...)) |
|
|
|
} |
|
|
|
|
|
|
|
// Warnf show warnning log
|
|
|
|
func (l *XORMLogBridge) Warnf(format string, v ...interface{}) { |
|
|
|
l.Log(2, WARN, format, v...) |
|
|
|
l.Log(2, log.WARN, format, v...) |
|
|
|
} |
|
|
|
|
|
|
|
// Level get logger level
|
|
|
|
func (l *XORMLogBridge) Level() core.LogLevel { |
|
|
|
switch l.GetGiteaLevel() { |
|
|
|
case TRACE, DEBUG: |
|
|
|
switch l.logger.GetLevel() { |
|
|
|
case log.TRACE, log.DEBUG: |
|
|
|
return core.LOG_DEBUG |
|
|
|
case INFO: |
|
|
|
case log.INFO: |
|
|
|
return core.LOG_INFO |
|
|
|
case WARN: |
|
|
|
case log.WARN: |
|
|
|
return core.LOG_WARNING |
|
|
|
case ERROR, CRITICAL: |
|
|
|
case log.ERROR, log.CRITICAL: |
|
|
|
return core.LOG_ERR |
|
|
|
} |
|
|
|
return core.LOG_OFF |