chore: version 1.0.7 - add log levels
Some checks failed
Build and Test / test (push) Has been cancelled
Build and Test / build (push) Has been cancelled
Build and Test / docker (push) Has been cancelled

- Add configurable log levels: DEBUG, INFO, WARN, ERROR
- Replace debug.enabled with log.level in configuration
- Add Warn/Warnf methods for warning messages
- Log orphan events and buffer overflow as WARN
- Log parse errors as WARN
- Log raw events and correlations as DEBUG

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Jacquin Antoine
2026-03-01 02:33:04 +01:00
parent 56c2923121
commit a3ae5421cf
12 changed files with 408 additions and 88 deletions

View File

@ -12,9 +12,23 @@ import (
// Config holds the complete application configuration.
type Config struct {
Inputs InputsConfig `yaml:"inputs"`
Outputs OutputsConfig `yaml:"outputs"`
Correlation CorrelationConfig `yaml:"correlation"`
Log LogConfig `yaml:"log"`
Inputs InputsConfig `yaml:"inputs"`
Outputs OutputsConfig `yaml:"outputs"`
Correlation CorrelationConfig `yaml:"correlation"`
}
// LogConfig holds logging configuration.
type LogConfig struct {
Level string `yaml:"level"` // DEBUG, INFO, WARN, ERROR
}
// GetLogLevel returns the log level, defaulting to INFO if not set.
func (c *LogConfig) GetLevel() string {
if c.Level == "" {
return "INFO"
}
return strings.ToUpper(c.Level)
}
// ServiceConfig holds service-level configuration.
@ -97,6 +111,9 @@ func Load(path string) (*Config, error) {
// defaultConfig returns a Config with default values.
func defaultConfig() *Config {
return &Config{
Log: LogConfig{
Level: "INFO",
},
Inputs: InputsConfig{
UnixSockets: make([]UnixSocketConfig, 0),
},

View File

@ -474,3 +474,83 @@ func TestGetSocketPermissions(t *testing.T) {
})
}
}
func TestLogConfig_GetLevel(t *testing.T) {
tests := []struct {
name string
config LogConfig
expected string
}{
{
name: "default",
config: LogConfig{Level: ""},
expected: "INFO",
},
{
name: "DEBUG uppercase",
config: LogConfig{Level: "DEBUG"},
expected: "DEBUG",
},
{
name: "debug lowercase",
config: LogConfig{Level: "debug"},
expected: "DEBUG",
},
{
name: "WARN",
config: LogConfig{Level: "WARN"},
expected: "WARN",
},
{
name: "ERROR",
config: LogConfig{Level: "ERROR"},
expected: "ERROR",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.config.GetLevel()
if result != tt.expected {
t.Errorf("GetLevel() = %v, want %v", result, tt.expected)
}
})
}
}
func TestLoad_LogLevel(t *testing.T) {
content := `
log:
level: DEBUG
inputs:
unix_sockets:
- name: http
path: /var/run/logcorrelator/http.socket
- name: network
path: /var/run/logcorrelator/network.socket
outputs:
file:
path: /var/log/test.log
correlation:
time_window_s: 1
emit_orphans: true
`
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config.yml")
if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
t.Fatalf("failed to write config: %v", err)
}
cfg, err := Load(configPath)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cfg.Log.GetLevel() != "DEBUG" {
t.Errorf("expected log level DEBUG, got %s", cfg.Log.GetLevel())
}
}