forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Logger configures the minimum severity written as structured JSON to stderr.
|
||||
type Logger struct {
|
||||
// Level is one of debug, info, warn or error; the default is info.
|
||||
Level string
|
||||
}
|
||||
|
||||
// loadEnvironment applies environment overrides to this configuration section.
|
||||
func (cfg *Logger) loadEnvironment() {
|
||||
if level, exists := os.LookupEnv("LOG_LEVEL"); exists {
|
||||
cfg.Level = level
|
||||
}
|
||||
}
|
||||
|
||||
// Validate rejects unsupported levels rather than silently changing verbosity.
|
||||
func (cfg *Logger) Validate() error {
|
||||
if cfg == nil {
|
||||
return fmt.Errorf("Logger configuration is required")
|
||||
}
|
||||
switch cfg.Level {
|
||||
case "debug", "info", "warn", "error":
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("LOG_LEVEL must be debug, info, warn or error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user