diff --git a/logger_go1.21.go b/logger_slog.go similarity index 100% rename from logger_go1.21.go rename to logger_slog.go diff --git a/logger_slog_test.go b/logger_slog_test.go new file mode 100644 index 00000000..7ec4df35 --- /dev/null +++ b/logger_slog_test.go @@ -0,0 +1,27 @@ +//go:build go1.21 +// +build go1.21 + +package log + +import ( + "log/slog" + "testing" +) + +func TestSlog(t *testing.T) { + var logger *slog.Logger = (&Logger{ + Level: InfoLevel, + TimeField: "date", + TimeFormat: "2006-01-02", + Caller: 1, + }).Slog() + + sublogger := logger.With("logger", "a_test_slog").With("everything", 42) + sublogger.Info("hello from sub slog Info") + sublogger.Warn("hello from sub slog Warn") + sublogger.Error("hello from sub slog Error") + + logger.Info("hello from slog Info") + logger.Warn("hello from slog Warn") + logger.Error("hello from slog Error") +} diff --git a/logger_test.go b/logger_test.go index 80e50b7e..15eaa059 100644 --- a/logger_test.go +++ b/logger_test.go @@ -7,7 +7,6 @@ import ( "fmt" "io" stdLog "log" - "log/slog" "net" "os" "strings" @@ -541,24 +540,6 @@ func TestStdLogger(t *testing.T) { stdLog.Printf("hello from stdLog %s", "Printf") } -func TestSlog(t *testing.T) { - var logger *slog.Logger = (&Logger{ - Level: InfoLevel, - TimeField: "date", - TimeFormat: "2006-01-02", - Caller: 1, - }).Slog() - - sublogger := logger.With("logger", "a_test_slog").With("everything", 42) - sublogger.Info("hello from sub slog Info") - sublogger.Warn("hello from sub slog Warn") - sublogger.Error("hello from sub slog Error") - - logger.Info("hello from slog Info") - logger.Warn("hello from slog Warn") - logger.Error("hello from slog Error") -} - type errno uint func (e errno) Error() string {