From bfcbe0b37dee113a153f96c1f4013c55678782a0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 10 Apr 2026 18:15:49 +0200 Subject: [PATCH] feat(config): add logging configuration fields --- config.example.yaml | 8 ++++++++ internal/config/config.go | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/config.example.yaml b/config.example.yaml index a3e732a..13aa791 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -45,3 +45,11 @@ sanitize: replace: "claude.ai" - match: "opencode" replace: "agent" + +logging: + level: info + # file: /var/log/anthropic-proxy.log # omit to log to stderr + # max_size_mb: 100 + # max_backups: 5 + # max_age_days: 30 + # compress: true diff --git a/internal/config/config.go b/internal/config/config.go index df44d51..78f022e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,6 +15,7 @@ type Config struct { APIKeys []string `yaml:"api_keys"` ClaudeBinary string `yaml:"claude_binary"` Sanitize SanitizeConfig `yaml:"sanitize"` + Logging LoggingConfig `yaml:"logging"` } type SanitizeConfig struct { @@ -33,6 +34,15 @@ type ReplaceRule struct { Replace string `yaml:"replace"` } +type LoggingConfig struct { + Level string `yaml:"level"` + File string `yaml:"file"` + MaxSizeMB int `yaml:"max_size_mb"` + MaxBackups int `yaml:"max_backups"` + MaxAgeDays int `yaml:"max_age_days"` + Compress bool `yaml:"compress"` +} + type claudeCredentialsJSON struct { ClaudeAiOauth struct { AccessToken string `json:"accessToken"` @@ -53,6 +63,19 @@ func Load(path string) (*Config, error) { return nil, fmt.Errorf("parse config: %w", err) } + if cfg.Logging.Level == "" { + cfg.Logging.Level = "info" + } + if cfg.Logging.MaxSizeMB == 0 { + cfg.Logging.MaxSizeMB = 100 + } + if cfg.Logging.MaxBackups == 0 { + cfg.Logging.MaxBackups = 5 + } + if cfg.Logging.MaxAgeDays == 0 { + cfg.Logging.MaxAgeDays = 30 + } + // Check for deprecated claude_credentials field var rawCfg map[string]interface{} if err := yaml.Unmarshal(data, &rawCfg); err == nil {