Skip to content

Commit

Permalink
🎨 fmt: fix some code style check error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 2, 2023
1 parent e08faea commit 53f432c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions benchmark2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions formatter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package slog

import "runtime"

//
// Formatter interface
//
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand Down
2 changes: 0 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 53f432c

Please sign in to comment.