Request access logs, panics, migration output and fatal errors are now emitted through the JSON slog handler. BREAKING CHANGE: UPTIME_LOG_FORMAT is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
22 lines
575 B
Go
22 lines
575 B
Go
package platform
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo"
|
|
)
|
|
|
|
var logLevel = new(slog.LevelVar)
|
|
|
|
// NewLogger installs a JSON logger as the process default so output from the
|
|
// standard log package and dependencies ends up in the same format.
|
|
func NewLogger(component string) *slog.Logger {
|
|
l := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: logLevel})).
|
|
With("component", component, "app_version", buildinfo.Version)
|
|
slog.SetDefault(l)
|
|
return l
|
|
}
|
|
|
|
func SetLogLevel(l slog.Level) { logLevel.Set(l) }
|