mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 11:41:58 +08:00
36 lines
744 B
Go
36 lines
744 B
Go
package instrumentation
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/SigNoz/signoz/pkg/instrumentation/loghandler"
|
|
)
|
|
|
|
func NewLogger(config Config, wrappers ...loghandler.Wrapper) *slog.Logger {
|
|
logger := slog.New(
|
|
loghandler.New(
|
|
slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: config.Logs.Level, AddSource: true, ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
|
|
// This is more in line with OpenTelemetry semantic conventions
|
|
if a.Key == slog.SourceKey {
|
|
a.Key = "code"
|
|
return a
|
|
}
|
|
|
|
if a.Key == slog.TimeKey {
|
|
a.Key = "timestamp"
|
|
return a
|
|
}
|
|
|
|
return a
|
|
}}),
|
|
wrappers...,
|
|
),
|
|
)
|
|
|
|
slog.SetDefault(logger)
|
|
_ = slog.SetLogLoggerLevel(config.Logs.Level)
|
|
|
|
return logger
|
|
}
|