This commit is contained in:
ryan
2026-06-19 15:13:24 +08:00
parent 0b34792709
commit 32861c5db9
376 changed files with 3648 additions and 19957 deletions
+5 -1
View File
@@ -1,3 +1,4 @@
// Package logging configures structured logging for edge applications.
package logging
import (
@@ -6,10 +7,12 @@ import (
"strings"
)
// Options holds configuration options for the structured logger.
type Options struct {
AddSource bool
}
// Setup initialises the default slog handler using the given options and the LOG_LEVEL environment variable.
func Setup(opts Options) {
handlerOpts := &slog.HandlerOptions{
AddSource: opts.AddSource,
@@ -19,6 +22,7 @@ func Setup(opts Options) {
slog.SetDefault(slog.New(handler))
}
// ParseLevel converts a log-level string (e.g. "debug", "warn") to the corresponding slog.Level.
func ParseLevel(value string) slog.Level {
switch strings.ToLower(strings.TrimSpace(value)) {
case "debug":
@@ -30,4 +34,4 @@ func ParseLevel(value string) slog.Level {
default:
return slog.LevelInfo
}
}
}