Quiet mode flag

The -q command line flag disables stderr output. However it causes file
logging to change format.
This commit is contained in:
Emmanuel BENOîT 2021-02-11 23:37:13 +01:00
parent e8a72dede3
commit 50233827b6
2 changed files with 8 additions and 0 deletions

View file

@ -54,6 +54,7 @@ To Do
* Proper logging, work in progress:
* Sending logs to... well, Graylog... through CLI switches.
* Fix file output when quiet mode flag is specified.
* Document command line flags.
* Add TLS options (skip checks / specify CA) for the Graylog API.
* Read object ownership using `grn_permissions` to preserve privileges on users'

View file

@ -2,6 +2,7 @@ package main
import (
"flag"
"io/ioutil"
"os"
"github.com/sirupsen/logrus"
@ -15,6 +16,8 @@ type (
cfgFile string
// The name of the instance, to be used in logs.
instance string
// Quiet mode. Will disable logging to stderr.
quiet bool
// The log level.
logLevel string
// A file to write logs into.
@ -32,6 +35,7 @@ func parseCommandLine() cliFlags {
flags := cliFlags{}
flag.StringVar(&flags.cfgFile, "c", "graylog-groups.yml", "Configuration file.")
flag.StringVar(&flags.instance, "i", "", "Instance identifier.")
flag.BoolVar(&flags.quiet, "q", false, "Quiet mode.")
flag.StringVar(&flags.logLevel, "L", "", "Log level.")
flag.StringVar(&flags.logFile, "log-file", "", "Log file.")
flag.Parse()
@ -86,6 +90,9 @@ func configureLogging(flags cliFlags) {
if flags.logFile != "" {
configureLogFile(flags.logFile)
}
if flags.quiet {
log.Logger.SetOutput(ioutil.Discard)
}
}
func main() {