From bc472fea71c6e8c3f28a2ca1bbf7250507556252 Mon Sep 17 00:00:00 2001 From: Trevor Atkinson Date: Mon, 5 Jan 2026 19:56:29 -0700 Subject: [PATCH] fix all --- attr.go | 18 ++++++++++++------ const.go | 1 + log.go | 16 +++++----------- log_test.go | 5 ++++- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/attr.go b/attr.go index 6c3b1bf..e87e649 100644 --- a/attr.go +++ b/attr.go @@ -5,12 +5,13 @@ type Attr struct { key string kfield kField - intValue int - int16Value int16 - int32Value int32 - int64Value int64 - stringValue string - boolValue bool + intValue int + int16Value int16 + int32Value int32 + int64Value int64 + stringValue string + boolValue bool + stringSliceValue []string anyValue any @@ -52,6 +53,11 @@ func Any(key string, value any) Attr { return Attr{key: key, kfield: kany, anyValue: value} } +// StringSlice +func StringSlice(key string, value []string) Attr { + return Attr{key: key, kfield: kstringslice, stringSliceValue: value} +} + // Error func Error(err error) Attr { return Attr{key: "error", kfield: kerr, errValue: err} diff --git a/const.go b/const.go index 6ae0001..79be66d 100644 --- a/const.go +++ b/const.go @@ -29,5 +29,6 @@ const ( kbool kany kstring + kstringslice kerr ) diff --git a/log.go b/log.go index d97ab27..5612e3c 100644 --- a/log.go +++ b/log.go @@ -5,6 +5,7 @@ import ( "os" "runtime" "strconv" + "strings" "sync" "time" ) @@ -54,18 +55,8 @@ func (l *Logger) Debug(format string, attrs ...Attr) { l.printf(format, DEBUG, attrs...) } -// Debugf -func (l *Logger) Debugf(format string, attrs ...Attr) { - l.printf(format, INFO, attrs...) -} - // Info -func (l *Logger) Info(format string) { - l.printf(format, INFO) -} - -// Infof -func (l *Logger) Infof(format string, attrs ...Attr) { +func (l *Logger) Info(format string, attrs ...Attr) { l.printf(format, INFO, attrs...) } @@ -118,6 +109,9 @@ func (l *Logger) printf(format string, level Level, attrs ...Attr) { buf = strconv.AppendBool(buf, attr.boolValue) case kstring: buf = strconv.AppendQuote(buf, attr.stringValue) + case kstringslice: + s := strings.Join(attr.stringSliceValue, ",") + buf = strconv.AppendQuote(buf, s) case kerr: buf = strconv.AppendQuote(buf, attr.errValue.Error()) } diff --git a/log_test.go b/log_test.go index 656715a..5edd695 100644 --- a/log_test.go +++ b/log_test.go @@ -35,10 +35,13 @@ func TestLogger_JSON(t *testing.T) { WithWriter(&buf), ) - l.Infof("hello", + l.Info("hello", String("user", "alice"), + StringSlice("x", []string{"hello", "world"}), ) + fmt.Println(buf.String()) + var result map[string]interface{} if err := json.Unmarshal(buf.Bytes(), &result); err != nil { t.Fatalf("json.Unmarshal: %v", err)