MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / InitLogger

Function InitLogger

pkg/shared/logger.go:40–65  ·  view source on GitHub ↗

InitLogger initializes the structured logger

(config *LogConfig)

Source from the content-addressed store, hash-verified

38
39// InitLogger initializes the structured logger
40func InitLogger(config *LogConfig) {
41 if config == nil {
42 config = DefaultLogConfig()
43 }
44
45 var handler slog.Handler
46
47 opts := &slog.HandlerOptions{
48 Level: config.Level,
49 AddSource: config.AddSource,
50 }
51
52 if config.Format == "json" {
53 handler = slog.NewJSONHandler(os.Stdout, opts)
54 } else {
55 handler = slog.NewTextHandler(os.Stdout, opts)
56 }
57
58 logger = slog.New(handler).With(
59 "service", config.ServiceName,
60 "version", "1.0.0",
61 )
62
63 // Set as default logger
64 slog.SetDefault(logger)
65}
66
67// GetLogger returns the global structured logger
68func GetLogger() *slog.Logger {

Callers 4

initFunction · 0.92
initFunction · 0.92
GetLoggerFunction · 0.85
SetLogLevelFunction · 0.85

Calls 1

DefaultLogConfigFunction · 0.85

Tested by

no test coverage detected