diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index 336b75d48..1e668b6b8 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -211,6 +211,19 @@ func LoadConfig(cConfig *csconfig.Config) error { return err } + // Configure logging + if err := types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, + cConfig.Common.LogDir, *cConfig.Common.LogLevel, + cConfig.Common.LogMaxSize, cConfig.Common.LogMaxFiles, + cConfig.Common.LogMaxAge, cConfig.Common.CompressLogs, + cConfig.Common.ForceColorLogs); err != nil { + return err + } + + if err := csconfig.LoadFeatureFlagsFile(cConfig, log.StandardLogger()); err != nil { + return err + } + if !flags.DisableAgent { if err := cConfig.LoadCrowdsec(); err != nil { return err @@ -256,15 +269,6 @@ func LoadConfig(cConfig *csconfig.Config) error { cConfig.Common.Daemonize = false } - // Configure logging - if err := types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, - cConfig.Common.LogDir, *cConfig.Common.LogLevel, - cConfig.Common.LogMaxSize, cConfig.Common.LogMaxFiles, - cConfig.Common.LogMaxAge, cConfig.Common.CompressLogs, - cConfig.Common.ForceColorLogs); err != nil { - return err - } - // recap of the enabled feature flags, because logging // was not enabled when we set them from envvars if fflist := csconfig.ListFeatureFlags(); fflist != "" { diff --git a/pkg/csconfig/crowdsec_service.go b/pkg/csconfig/crowdsec_service.go index 56350a8a4..a5ed2dd2f 100644 --- a/pkg/csconfig/crowdsec_service.go +++ b/pkg/csconfig/crowdsec_service.go @@ -40,10 +40,7 @@ type CrowdsecServiceCfg struct { func (c *Config) LoadCrowdsec() error { var err error - if err = LoadFeatureFlagsFile(c, log.StandardLogger()); err != nil { - return err - } - + log.Warningf("c.Crowdsec: %+v", c.Crowdsec) if c.Crowdsec == nil { log.Warning("crowdsec agent is disabled") c.DisableAgent = true diff --git a/tests/bats/02_nolapi.bats b/tests/bats/02_nolapi.bats index fd0427793..21eb7f13e 100644 --- a/tests/bats/02_nolapi.bats +++ b/tests/bats/02_nolapi.bats @@ -35,6 +35,7 @@ teardown() { @test "crowdsec should not run without LAPI (no api.server in configuration file)" { config_disable_lapi + config_log_stderr # really needs 4 secs on slow boxes run -1 --separate-stderr timeout 4s "${CROWDSEC}" diff --git a/tests/bats/03_noagent.bats b/tests/bats/03_noagent.bats index 2127fc796..211f62947 100644 --- a/tests/bats/03_noagent.bats +++ b/tests/bats/03_noagent.bats @@ -33,6 +33,7 @@ teardown() { @test "no agent: crowdsec LAPI should run (no crowdsec_service in configuration file)" { config_disable_agent + config_log_stderr run -124 --separate-stderr timeout 2s "${CROWDSEC}" assert_stderr --partial "crowdsec agent is disabled" diff --git a/tests/lib/setup_file.sh b/tests/lib/setup_file.sh index 25842fcdc..22a9bc303 100755 --- a/tests/lib/setup_file.sh +++ b/tests/lib/setup_file.sh @@ -71,6 +71,11 @@ config_disable_agent() { } export -f config_disable_agent +config_log_stderr() { + config_set '.common.log_media="stdout"' +} +export -f config_log_stderr + config_disable_lapi() { config_set 'del(.api.server)' }