Skip to content

Commit

Permalink
👔 up: add release statement for logger With* method
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 5, 2024
1 parent 58189e6 commit 661c430
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func NewWithName(name string, fns ...LoggerFn) *Logger {
// NewRecord get new logger record
func (l *Logger) newRecord() *Record {
r := l.recordPool.Get().(*Record)
r.reuse = false
r.freed = false
r.Fields = nil
return r
Expand Down Expand Up @@ -429,6 +430,7 @@ func (l *Logger) Reused() *Record {
// TIP: add field need config Formatter template fields.
func (l *Logger) WithField(name string, value any) *Record {
r := l.newRecord()
defer l.releaseRecord(r)
return r.WithField(name, value)
}

Expand All @@ -437,12 +439,14 @@ func (l *Logger) WithField(name string, value any) *Record {
// TIP: add field need config Formatter template fields.
func (l *Logger) WithFields(fields M) *Record {
r := l.newRecord()
defer l.releaseRecord(r)
return r.WithFields(fields)
}

// WithData new record with data
func (l *Logger) WithData(data M) *Record {
r := l.newRecord()
defer l.releaseRecord(r)
return r.WithData(data)
}

Expand All @@ -461,6 +465,7 @@ func (l *Logger) WithExtra(ext M) *Record {
// WithTime new record with time.Time
func (l *Logger) WithTime(t time.Time) *Record {
r := l.newRecord()
defer l.releaseRecord(r)
return r.WithTime(t)
}

Expand All @@ -470,6 +475,7 @@ func (l *Logger) WithCtx(ctx context.Context) *Record { return l.WithContext(ctx
// WithContext new record with context.Context
func (l *Logger) WithContext(ctx context.Context) *Record {
r := l.newRecord()
defer l.releaseRecord(r)
return r.WithContext(ctx)
}

Expand Down

0 comments on commit 661c430

Please sign in to comment.