diff --git a/converter.go b/converter.go index 0349b74..e476ae7 100644 --- a/converter.go +++ b/converter.go @@ -19,9 +19,9 @@ func DefaultConverter(addSource bool, replaceAttr func(groups []string, a slog.A // developer formatters attrs = slogcommon.ReplaceError(attrs, ErrorKeys...) - if addSource { - attrs = append(attrs, slogcommon.Source(SourceKey, record)) - } + // if addSource { + // attrs = append(attrs, slogcommon.Source(SourceKey, record)) + // } attrs = slogcommon.ReplaceAttrs(replaceAttr, []string{}, attrs...) // handler formatter diff --git a/handler.go b/handler.go index dd940a4..92ff179 100644 --- a/handler.go +++ b/handler.go @@ -2,11 +2,13 @@ package slogzap import ( "context" + "runtime" "log/slog" slogcommon "github.com/samber/slog-common" "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) type Option struct { @@ -62,7 +64,21 @@ func (h *ZapHandler) Handle(ctx context.Context, record slog.Record) error { level := LogLevels[record.Level] fields := converter(h.option.AddSource, h.option.ReplaceAttr, h.attrs, h.groups, &record) - h.option.Logger.Log(level, record.Message, fields...) + checked := h.option.Logger.Check(level, record.Message) + if checked != nil { + if h.option.AddSource { + frame, _ := runtime.CallersFrames([]uintptr{record.PC}).Next() + checked.Caller = zapcore.NewEntryCaller(0, frame.File, frame.Line, true) + checked.Stack = "" //@TODO + } else { + checked.Caller = zapcore.EntryCaller{} + checked.Stack = "" + } + checked.Write(fields...) + return nil + } else { + h.option.Logger.Log(level, record.Message, fields...) + } return nil }