diff options
author | Rasmus Dahlberg <rasmus@rgdd.se> | 2024-01-08 08:37:43 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus@rgdd.se> | 2024-01-08 08:37:43 +0100 |
commit | 2bfa00660bf5c21d222dd17a27c9006c9fedf6c7 (patch) | |
tree | c06aaba6e20251511052e687823961f93c52ca86 | |
parent | e371f2005f91b3db1904b3038c498c764ae15279 (diff) |
Configure logger using the -o option
-rw-r--r-- | cmd/silent-ctmoon/main.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cmd/silent-ctmoon/main.go b/cmd/silent-ctmoon/main.go index 436ea64..823b1c7 100644 --- a/cmd/silent-ctmoon/main.go +++ b/cmd/silent-ctmoon/main.go @@ -91,10 +91,17 @@ func configure(cmd string, args []string) (cfg config, err error) { if cfg.policyFile == "" { return cfg, fmt.Errorf("policy file is a required option") } + output := os.Stdout + if cfg.outputFile != "" { + if output, err = os.OpenFile(cfg.outputFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644); err != nil { + return cfg, fmt.Errorf("failed to open output file: %v", err) + } + } if cfg.numWorkers == 0 || cfg.numWorkers > 4 { return cfg, fmt.Errorf("number of workers must be in [1, 4]") } - cfg.log = logger.New(logger.Config{Level: lv, File: os.Stdout}) + + cfg.log = logger.New(logger.Config{Level: lv, File: output}) if err := ioutil.ReadJSON(cfg.policyFile, &cfg.policy); err != nil { return cfg, err } |