mirror of
https://github.com/btouchard/ackify-ce.git
synced 2026-02-13 01:08:30 -06:00
- Added structured logs in HandleError() for each error type in middleware - Explicit log of the OAuth callback error before handling feat: add configurable log level via ACKIFY_LOG_LEVEL - Add ParseLevel function to logger package - Extend config structure with LoggerConfig - Apply log level during server initialization - Update documentation and .env.example
36 lines
608 B
Go
36 lines
608 B
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
package logger
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
var Logger *slog.Logger
|
|
|
|
func init() {
|
|
SetLevel(slog.LevelInfo)
|
|
}
|
|
|
|
func SetLevel(level slog.Level) {
|
|
Logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
Level: level,
|
|
}))
|
|
}
|
|
|
|
func ParseLevel(levelStr string) slog.Level {
|
|
switch strings.ToLower(strings.TrimSpace(levelStr)) {
|
|
case "debug":
|
|
return slog.LevelDebug
|
|
case "info":
|
|
return slog.LevelInfo
|
|
case "warn", "warning":
|
|
return slog.LevelWarn
|
|
case "error":
|
|
return slog.LevelError
|
|
default:
|
|
return slog.LevelInfo
|
|
}
|
|
}
|