chore(logger): optimize (#6675)

* chore(logger): optimize

* chore(logger): optimize
This commit is contained in:
Flc゛ 2023-11-07 10:19:41 +08:00 committed by GitHub
parent 9fea15ae75
commit d2fb7a942b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -69,7 +69,7 @@ type Interface interface {
}
var (
// Discard Discard logger will print any log to io.Discard
// Discard logger will print any log to io.Discard
Discard = New(log.New(io.Discard, "", log.LstdFlags), Config{})
// Default Default logger
Default = New(log.New(os.Stdout, "\r\n", log.LstdFlags), Config{
@ -78,7 +78,7 @@ var (
IgnoreRecordNotFoundError: false,
Colorful: true,
})
// Recorder Recorder logger records running SQL into a recorder instance
// Recorder logger records running SQL into a recorder instance
Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()}
)
@ -129,28 +129,30 @@ func (l *logger) LogMode(level LogLevel) Interface {
}
// Info print info
func (l logger) Info(ctx context.Context, msg string, data ...interface{}) {
func (l *logger) Info(ctx context.Context, msg string, data ...interface{}) {
if l.LogLevel >= Info {
l.Printf(l.infoStr+msg, append([]interface{}{utils.FileWithLineNum()}, data...)...)
}
}
// Warn print warn messages
func (l logger) Warn(ctx context.Context, msg string, data ...interface{}) {
func (l *logger) Warn(ctx context.Context, msg string, data ...interface{}) {
if l.LogLevel >= Warn {
l.Printf(l.warnStr+msg, append([]interface{}{utils.FileWithLineNum()}, data...)...)
}
}
// Error print error messages
func (l logger) Error(ctx context.Context, msg string, data ...interface{}) {
func (l *logger) Error(ctx context.Context, msg string, data ...interface{}) {
if l.LogLevel >= Error {
l.Printf(l.errStr+msg, append([]interface{}{utils.FileWithLineNum()}, data...)...)
}
}
// Trace print sql message
func (l logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
//
//nolint:cyclop
func (l *logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {
if l.LogLevel <= Silent {
return
}
@ -182,8 +184,8 @@ func (l logger) Trace(ctx context.Context, begin time.Time, fc func() (string, i
}
}
// Trace print sql message
func (l logger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
// ParamsFilter filter params
func (l *logger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
if l.Config.ParameterizedQueries {
return sql, nil
}
@ -198,8 +200,8 @@ type traceRecorder struct {
Err error
}
// New new trace recorder
func (l traceRecorder) New() *traceRecorder {
// New trace recorder
func (l *traceRecorder) New() *traceRecorder {
return &traceRecorder{Interface: l.Interface, BeginAt: time.Now()}
}