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

@ -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())
}
}