logger: Add experimental support for adding trace_id from context

This commit is contained in:
2023-10-21 21:51:29 -07:00
parent 7420ad12f4
commit 9d136b2502
3 changed files with 18 additions and 4 deletions

View File

@@ -3,11 +3,12 @@ package logger
import (
"context"
"log"
"log/slog"
"os"
"strconv"
"sync"
"log/slog"
"github.com/ttys3/slogx"
)
var ConfigPrefix = ""
@@ -41,8 +42,7 @@ func Setup() *slog.Logger {
logReplace := func(groups []string, a slog.Attr) slog.Attr {
// Remove time
if a.Key == slog.TimeKey && len(groups) == 0 {
a.Key = ""
a.Value = slog.AnyValue(nil)
return slog.Attr{}
}
return a
}
@@ -50,7 +50,7 @@ func Setup() *slog.Logger {
logOptions.ReplaceAttr = logReplace
}
logHandler := slog.NewTextHandler(os.Stderr, logOptions)
logHandler := slogx.NewTracingHandler(slog.NewTextHandler(os.Stderr, logOptions))
// https://github.com/cyrusaf/ctxlog/pull/1
// log := slog.New(ctxlog.NewHandler(logHandler))