|
|
|
@ -1,11 +1,16 @@
|
|
|
|
|
package logger
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io"
|
|
|
|
|
"log/slog"
|
|
|
|
|
|
|
|
|
|
"github.com/ThreeDotsLabs/watermill"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
LevelTrace = slog.Level(-5)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func LogFieldsToSlogAttrs(in watermill.LogFields) []slog.Attr {
|
|
|
|
|
attrs := make([]slog.Attr, 0)
|
|
|
|
|
for k, v := range in {
|
|
|
|
@ -21,15 +26,19 @@ type WrappedSlogger struct {
|
|
|
|
|
*slog.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewWrappedSlogger() *WrappedSlogger {
|
|
|
|
|
func NewWrappedSlogger(w io.Writer, verbose int) *WrappedSlogger {
|
|
|
|
|
opts := &slog.HandlerOptions{
|
|
|
|
|
Level: slog.Level(verbose),
|
|
|
|
|
}
|
|
|
|
|
handler := slog.NewTextHandler(w, opts)
|
|
|
|
|
return &WrappedSlogger{
|
|
|
|
|
slog.Default(),
|
|
|
|
|
slog.New(handler),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (wl *WrappedSlogger) Error(msg string, err error, fields watermill.LogFields) {
|
|
|
|
|
attrs := LogFieldsToSlogAttrs(fields)
|
|
|
|
|
wl.LogAttrs(nil, slog.Level(-5), msg, attrs...)
|
|
|
|
|
wl.LogAttrs(nil, LevelTrace, msg, attrs...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (wl *WrappedSlogger) Info(msg string, fields watermill.LogFields) {
|
|
|
|
@ -44,7 +53,7 @@ func (wl *WrappedSlogger) Debug(msg string, fields watermill.LogFields) {
|
|
|
|
|
|
|
|
|
|
func (wl *WrappedSlogger) Trace(msg string, fields watermill.LogFields) {
|
|
|
|
|
attrs := LogFieldsToSlogAttrs(fields)
|
|
|
|
|
wl.LogAttrs(nil, slog.Level(-5), msg, attrs...)
|
|
|
|
|
wl.LogAttrs(nil, LevelTrace, msg, attrs...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (wl *WrappedSlogger) With(fields watermill.LogFields) watermill.LoggerAdapter {
|
|
|
|
|