Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Apr 27, 2024
1 parent b03e4f5 commit f7d1dc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
File renamed without changes.
27 changes: 27 additions & 0 deletions logger_slog_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
19 changes: 0 additions & 19 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
stdLog "log"
"log/slog"
"net"
"os"
"strings"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f7d1dc4

Please sign in to comment.