feat: add logs
This commit is contained in:
@@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/pierre-bot/internal/chatter"
|
||||
"git.schreifuchs.ch/schreifuchs/pierre-bot/internal/gitadapters/bitbucket"
|
||||
@@ -46,6 +48,7 @@ type ReviewConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
LogLevel string `help:"Log verbosity: debug, info, warn, error"`
|
||||
// Deprecated flags (no prefix). Retained for backward compatibility.
|
||||
// These will be mapped to the embedded ReviewConfig if provided.
|
||||
MaxChunkSize int `help:"Deprecated: use --review-max-chunk-size"`
|
||||
@@ -65,6 +68,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
cfg := &Config{}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
@@ -81,6 +85,21 @@ func main() {
|
||||
kong.Configuration(kongyaml.Loader, "config.yaml", defaultConfig),
|
||||
)
|
||||
|
||||
// Configure global slog logger based on the --log-level flag
|
||||
lvl := slog.LevelInfo
|
||||
switch strings.ToLower(cfg.LogLevel) {
|
||||
case "debug":
|
||||
lvl = slog.LevelDebug
|
||||
case "info":
|
||||
lvl = slog.LevelInfo
|
||||
case "warn":
|
||||
lvl = slog.LevelWarn
|
||||
case "error":
|
||||
lvl = slog.LevelError
|
||||
}
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: lvl}))
|
||||
slog.SetDefault(logger)
|
||||
|
||||
// Backwards compatibility: map deprecated flag values (if any) to the embedded ReviewConfig.
|
||||
if cfg.MaxChunkSize != 0 {
|
||||
cfg.Review.MaxChunkSize = cfg.MaxChunkSize
|
||||
|
||||
Reference in New Issue
Block a user