configure logging earlier
This commit is contained in:
parent
91b0f8fee1
commit
47dbfa770d
|
@ -211,6 +211,19 @@ func LoadConfig(cConfig *csconfig.Config) error {
|
||||||
return err
|
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 !flags.DisableAgent {
|
||||||
if err := cConfig.LoadCrowdsec(); err != nil {
|
if err := cConfig.LoadCrowdsec(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -256,15 +269,6 @@ func LoadConfig(cConfig *csconfig.Config) error {
|
||||||
cConfig.Common.Daemonize = false
|
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
|
// recap of the enabled feature flags, because logging
|
||||||
// was not enabled when we set them from envvars
|
// was not enabled when we set them from envvars
|
||||||
if fflist := csconfig.ListFeatureFlags(); fflist != "" {
|
if fflist := csconfig.ListFeatureFlags(); fflist != "" {
|
||||||
|
|
|
@ -40,10 +40,7 @@ type CrowdsecServiceCfg struct {
|
||||||
func (c *Config) LoadCrowdsec() error {
|
func (c *Config) LoadCrowdsec() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err = LoadFeatureFlagsFile(c, log.StandardLogger()); err != nil {
|
log.Warningf("c.Crowdsec: %+v", c.Crowdsec)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Crowdsec == nil {
|
if c.Crowdsec == nil {
|
||||||
log.Warning("crowdsec agent is disabled")
|
log.Warning("crowdsec agent is disabled")
|
||||||
c.DisableAgent = true
|
c.DisableAgent = true
|
||||||
|
|
|
@ -35,6 +35,7 @@ teardown() {
|
||||||
|
|
||||||
@test "crowdsec should not run without LAPI (no api.server in configuration file)" {
|
@test "crowdsec should not run without LAPI (no api.server in configuration file)" {
|
||||||
config_disable_lapi
|
config_disable_lapi
|
||||||
|
config_log_stderr
|
||||||
# really needs 4 secs on slow boxes
|
# really needs 4 secs on slow boxes
|
||||||
run -1 --separate-stderr timeout 4s "${CROWDSEC}"
|
run -1 --separate-stderr timeout 4s "${CROWDSEC}"
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ teardown() {
|
||||||
|
|
||||||
@test "no agent: crowdsec LAPI should run (no crowdsec_service in configuration file)" {
|
@test "no agent: crowdsec LAPI should run (no crowdsec_service in configuration file)" {
|
||||||
config_disable_agent
|
config_disable_agent
|
||||||
|
config_log_stderr
|
||||||
run -124 --separate-stderr timeout 2s "${CROWDSEC}"
|
run -124 --separate-stderr timeout 2s "${CROWDSEC}"
|
||||||
|
|
||||||
assert_stderr --partial "crowdsec agent is disabled"
|
assert_stderr --partial "crowdsec agent is disabled"
|
||||||
|
|
|
@ -71,6 +71,11 @@ config_disable_agent() {
|
||||||
}
|
}
|
||||||
export -f 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_disable_lapi() {
|
||||||
config_set 'del(.api.server)'
|
config_set 'del(.api.server)'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue