diff --git a/benchmark2_test.go b/benchmark2_test.go index 3c8e7d3..114a8be 100644 --- a/benchmark2_test.go +++ b/benchmark2_test.go @@ -8,7 +8,7 @@ import ( "github.com/gookit/goutil/dump" ) -func TestLogger_newRecord_AllocTimes(t *testing.T) { +func TestLogger_newRecord_AllocTimes(_ *testing.T) { l := Std() l.Output = io.Discard defer l.Reset() @@ -22,7 +22,7 @@ func TestLogger_newRecord_AllocTimes(t *testing.T) { }))) } -func Test_formatArgsWithSpaces_oneElem_AllocTimes(t *testing.T) { +func Test_formatArgsWithSpaces_oneElem_AllocTimes(_ *testing.T) { // output: 1 times -> 0 times fmt.Println("Alloc Times:", int(testing.AllocsPerRun(10, func() { // logger.Info("rate", "15", "low", 16, "high", 123.2, msg) @@ -32,7 +32,7 @@ func Test_formatArgsWithSpaces_oneElem_AllocTimes(t *testing.T) { }))) } -func Test_AllocTimes_formatArgsWithSpaces_manyElem(t *testing.T) { +func Test_AllocTimes_formatArgsWithSpaces_manyElem(_ *testing.T) { l := Std() l.Output = io.Discard defer l.Reset() @@ -48,7 +48,7 @@ func Test_AllocTimes_formatArgsWithSpaces_manyElem(t *testing.T) { }))) } -func Test_AllocTimes_stringsPool(t *testing.T) { +func Test_AllocTimes_stringsPool(_ *testing.T) { l := Std() l.Output = io.Discard l.LowerLevelName = true @@ -76,7 +76,7 @@ func Test_AllocTimes_stringsPool(t *testing.T) { dump.P(ln, cp) } -func TestLogger_Info_oneElem_AllocTimes(t *testing.T) { +func TestLogger_Info_oneElem_AllocTimes(_ *testing.T) { l := Std() // l.Output = io.Discard l.ReportCaller = false @@ -93,7 +93,7 @@ func TestLogger_Info_oneElem_AllocTimes(t *testing.T) { }))) } -func TestLogger_Info_moreElem_AllocTimes(t *testing.T) { +func TestLogger_Info_moreElem_AllocTimes(_ *testing.T) { l := NewStdLogger() // l.Output = io.Discard l.ReportCaller = false diff --git a/formatter.go b/formatter.go index dd81d23..ea8e183 100644 --- a/formatter.go +++ b/formatter.go @@ -1,5 +1,7 @@ package slog +import "runtime" + // // Formatter interface // @@ -49,6 +51,9 @@ func (f *FormattableTrait) Format(record *Record) ([]byte, error) { return f.Formatter().Format(record) } +// CallerFormatFn caller format func +type CallerFormatFn func(rf *runtime.Frame) (cs string) + // AsTextFormatter util func func AsTextFormatter(f Formatter) *TextFormatter { if tf, ok := f.(*TextFormatter); ok { diff --git a/logger.go b/logger.go index d5c7181..733ddff 100644 --- a/logger.go +++ b/logger.go @@ -75,7 +75,7 @@ func NewWithName(name string, fns ...LoggerFn) *Logger { TimeClock: DefaultClockFn, } - logger.recordPool.New = func() interface{} { + logger.recordPool.New = func() any { return newRecord(logger) } return logger.Config(fns...) @@ -92,6 +92,7 @@ func (l *Logger) releaseRecord(r *Record) { r.Data = nil r.Extra = nil r.Fields = nil + r.inited = false r.CallerSkip = l.CallerSkip l.recordPool.Put(r) } @@ -305,11 +306,9 @@ func (l *Logger) SetProcessors(ps []Processor) { l.processors = ps } // --------------------------------------------------------------------------- // -// Record return a new record for log +// Record return a new record with logger func (l *Logger) Record() *Record { - r := l.newRecord() - defer l.releaseRecord(r) - return r + return l.newRecord() } // WithField new record with field diff --git a/slog.go b/slog.go index 51fe374..361f2dd 100644 --- a/slog.go +++ b/slog.go @@ -63,14 +63,14 @@ func Reset() { } // Configure the std logger -func Configure(fn func(l *SugaredLogger)) { std.Configure(fn) } - -// Exit runs all the logger exit handlers and then terminates the program using os.Exit(code) -func Exit(code int) { std.Exit(code) } +func Configure(fn func(l *SugaredLogger)) { std.Config(fn) } // SetExitFunc to the std logger func SetExitFunc(fn func(code int)) { std.ExitFunc = fn } +// Exit runs all the logger exit handlers and then terminates the program using os.Exit(code) +func Exit(code int) { std.Exit(code) } + // Flush log messages func Flush() error { return std.Flush() } diff --git a/util.go b/util.go index f9ebfa3..09944da 100644 --- a/util.go +++ b/util.go @@ -24,8 +24,6 @@ import ( // return nil // } -type CallerFormatFn func(rf *runtime.Frame) (cs string) - func buildLowerLevelName() map[Level]string { mp := make(map[Level]string, len(LevelNames)) for level, s := range LevelNames {