Skip to content

Commit

Permalink
chore(logger): optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 committed Nov 7, 2023
1 parent 9fea15a commit 6eacaeb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()}
)

Expand Down Expand Up @@ -129,28 +129,28 @@ 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) {
func (l *logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) {

Check failure on line 153 in logger/logger.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 calculated cyclomatic complexity for function Trace is 13, max is 10 (cyclop) Raw Output: logger/logger.go:153:1: calculated cyclomatic complexity for function Trace is 13, max is 10 (cyclop) func (l *logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) { ^
if l.LogLevel <= Silent {
return
}
Expand Down Expand Up @@ -182,8 +182,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
}
Expand All @@ -198,8 +198,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()}
}

Expand Down

0 comments on commit 6eacaeb

Please sign in to comment.