diff --git a/pkg/cfg/logging.go b/pkg/cfg/logging.go index acb7e82..980d076 100644 --- a/pkg/cfg/logging.go +++ b/pkg/cfg/logging.go @@ -4,18 +4,19 @@ import ( "fmt" "io" "os" + "path/filepath" log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/writer" "gopkg.in/natefinch/lumberjack.v2" - "github.com/crowdsecurity/go-cs-lib/pkg/logtools" + "github.com/crowdsecurity/go-cs-lib/pkg/ptr" ) type LoggingConfig struct { + LogLevel *log.Level `yaml:"log_level"` LogMode string `yaml:"log_mode"` LogDir string `yaml:"log_dir"` - LogLevel *log.Level `yaml:"log_level"` LogMaxSize int `yaml:"log_max_size,omitempty"` LogMaxFiles int `yaml:"log_max_files,omitempty"` LogMaxAge int `yaml:"log_max_age,omitempty"` @@ -27,13 +28,11 @@ func (c *LoggingConfig) LoggerForFile(fileName string) (io.Writer, error) { return os.Stderr, nil } - logPath, err := logtools.SetLogFilePermissions(c.LogDir, fileName) - if err != nil { - return nil, err - } + // default permissions will be 0600 from lumberjack + // and are preserved if the file already exists l := &lumberjack.Logger{ - Filename: logPath, + Filename: filepath.Join(c.LogDir, fileName), MaxSize: c.LogMaxSize, MaxBackups: c.LogMaxFiles, MaxAge: c.LogMaxAge, @@ -53,8 +52,7 @@ func (c *LoggingConfig) setDefaults() { } if c.LogLevel == nil { - defaultLevel := log.InfoLevel - c.LogLevel = &defaultLevel + c.LogLevel = ptr.Of(log.InfoLevel) } if c.LogMaxSize == 0 { @@ -70,8 +68,7 @@ func (c *LoggingConfig) setDefaults() { } if c.CompressLogs == nil { - defaultCompress := true - c.CompressLogs = &defaultCompress + c.CompressLogs = ptr.Of(true) } } diff --git a/test/bouncer/test_custom_bouncer.py b/test/bouncer/test_custom_bouncer.py index 49d4081..ada3501 100644 --- a/test/bouncer/test_custom_bouncer.py +++ b/test/bouncer/test_custom_bouncer.py @@ -227,7 +227,7 @@ def test_bin_args(bouncer_with_lapi, tmp_path_factory): res = lapi.cont.exec_run(f'cscli decisions add -i 1.2.3.{i}') assert res.exit_code == 0 - time.sleep(1) + time.sleep(2) with open(data) as f: lines = f.readlines()