Skip to content

Commit

Permalink
调整自定义的 handler
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Dec 13, 2023
1 parent 0204303 commit 4d539ed
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 215 deletions.
16 changes: 16 additions & 0 deletions _examples/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ BenchmarkZapFile-2 382790 2641 ns/op
BenchmarkLogrusFile-2 174944 6491 ns/op 2080 B/op 32 allocs/op
*/

// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitLoggerStandardHandler$ -benchtime=1s
func BenchmarkLogitLoggerStandardHandler(b *testing.B) {
logger := logit.NewLogger(
logit.WithInfoLevel(),
logit.WithHandler("standard"),
logit.WithWriter(io.Discard),
)

b.ReportAllocs()
b.StartTimer()

for i := 0; i < b.N; i++ {
logger.Info("info...", "trace", "xxx", "id", 123, "pi", 3.14)
}
}

// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitLoggerTextHandler$ -benchtime=1s
func BenchmarkLogitLoggerTextHandler(b *testing.B) {
logger := logit.NewLogger(
Expand Down
206 changes: 0 additions & 206 deletions console.go

This file was deleted.

10 changes: 5 additions & 5 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
)

const (
handlerConsole = "console"
handlerText = "text"
handlerJson = "json"
handlerStandard = "standard"
handlerText = "text"
handlerJson = "json"
)

var (
newHandlers = map[string]HandlerFunc{
handlerConsole: func(w io.Writer, opts *slog.HandlerOptions) slog.Handler {
return newConsoleHandler(w, opts)
handlerStandard: func(w io.Writer, opts *slog.HandlerOptions) slog.Handler {
return newStandardHandler(w, opts)
},
handlerText: func(w io.Writer, opts *slog.HandlerOptions) slog.Handler {
return slog.NewTextHandler(w, opts)
Expand Down
Loading

0 comments on commit 4d539ed

Please sign in to comment.