Quiet mode flag
The -q command line flag disables stderr output. However it causes file logging to change format.
This commit is contained in:
parent
e8a72dede3
commit
50233827b6
2 changed files with 8 additions and 0 deletions
|
@ -54,6 +54,7 @@ To Do
|
||||||
|
|
||||||
* Proper logging, work in progress:
|
* Proper logging, work in progress:
|
||||||
* Sending logs to... well, Graylog... through CLI switches.
|
* Sending logs to... well, Graylog... through CLI switches.
|
||||||
|
* Fix file output when quiet mode flag is specified.
|
||||||
* Document command line flags.
|
* Document command line flags.
|
||||||
* Add TLS options (skip checks / specify CA) for the Graylog API.
|
* Add TLS options (skip checks / specify CA) for the Graylog API.
|
||||||
* Read object ownership using `grn_permissions` to preserve privileges on users'
|
* Read object ownership using `grn_permissions` to preserve privileges on users'
|
||||||
|
|
7
main.go
7
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -15,6 +16,8 @@ type (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
// The name of the instance, to be used in logs.
|
// The name of the instance, to be used in logs.
|
||||||
instance string
|
instance string
|
||||||
|
// Quiet mode. Will disable logging to stderr.
|
||||||
|
quiet bool
|
||||||
// The log level.
|
// The log level.
|
||||||
logLevel string
|
logLevel string
|
||||||
// A file to write logs into.
|
// A file to write logs into.
|
||||||
|
@ -32,6 +35,7 @@ func parseCommandLine() cliFlags {
|
||||||
flags := cliFlags{}
|
flags := cliFlags{}
|
||||||
flag.StringVar(&flags.cfgFile, "c", "graylog-groups.yml", "Configuration file.")
|
flag.StringVar(&flags.cfgFile, "c", "graylog-groups.yml", "Configuration file.")
|
||||||
flag.StringVar(&flags.instance, "i", "", "Instance identifier.")
|
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.logLevel, "L", "", "Log level.")
|
||||||
flag.StringVar(&flags.logFile, "log-file", "", "Log file.")
|
flag.StringVar(&flags.logFile, "log-file", "", "Log file.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -86,6 +90,9 @@ func configureLogging(flags cliFlags) {
|
||||||
if flags.logFile != "" {
|
if flags.logFile != "" {
|
||||||
configureLogFile(flags.logFile)
|
configureLogFile(flags.logFile)
|
||||||
}
|
}
|
||||||
|
if flags.quiet {
|
||||||
|
log.Logger.SetOutput(ioutil.Discard)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Reference in a new issue