Changeset 0.33.0 (#207)

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
2026-03-19 21:37:32 +00:00
committed by xcaliber
parent b1266b0d7c
commit ed3e9363f2
42 changed files with 2527 additions and 129 deletions

39
server/logging/logger.go Normal file
View File

@@ -0,0 +1,39 @@
// Package logging provides structured logging configuration for
// Chat Switchboard using the standard library's log/slog package.
// Configured via LOG_FORMAT ("text"|"json") and LOG_LEVEL env vars.
package logging
import (
"log/slog"
"os"
"strings"
)
// Init configures the global slog logger.
//
// - format: "json" for machine-parseable output, anything else for
// human-readable key=value pairs (backward-compatible default).
// - level: "debug", "info" (default), "warn", "error".
func Init(format, level string) {
var lvl slog.Level
switch strings.ToLower(level) {
case "debug":
lvl = slog.LevelDebug
case "warn", "warning":
lvl = slog.LevelWarn
case "error":
lvl = slog.LevelError
default:
lvl = slog.LevelInfo
}
opts := &slog.HandlerOptions{Level: lvl}
var handler slog.Handler
if strings.ToLower(format) == "json" {
handler = slog.NewJSONHandler(os.Stdout, opts)
} else {
handler = slog.NewTextHandler(os.Stdout, opts)
}
slog.SetDefault(slog.New(handler))
}