Commit 8a06c1f3 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Support logging in JSON format

parent 04e6adae
......@@ -62,6 +62,7 @@ type Configuration struct {
Verbose int `json:"verbose" mapstructure:"verbose"`
Quiet bool `json:"quiet" mapstructure:"quiet"`
LogJSON bool `json:"log_json" mapstructure:"log_json"`
jwtPrivateKey *rsa.PrivateKey
}
......
......@@ -153,6 +153,7 @@ using the corresponding "-file" flag.`
flags.CountP("verbose", "v", "verbose (repeatable)")
flags.BoolP("quiet", "q", false, "quiet")
flags.Bool("log-json", false, "Log in JSON format")
flags.Lookup("verbose").Header = `Other options`
return nil
......@@ -183,6 +184,9 @@ func configure(cmd *cobra.Command) error {
err := viper.ReadInConfig() // Hold error checking until we know how much of it to log
// Set log level
if viper.GetBool("log-json") {
logger.SetFormatter(&logrus.JSONFormatter{})
}
logger.Level = server.Verbosity(viper.GetInt("verbose"))
if viper.GetBool("quiet") {
logger.Out = ioutil.Discard
......@@ -228,6 +232,7 @@ func configure(cmd *cobra.Command) error {
MaxRequestAge: viper.GetInt("max-request-age"),
Verbose: viper.GetInt("verbose"),
Quiet: viper.GetBool("quiet"),
LogJSON: viper.GetBool("log-json"),
TlsCertificate: viper.GetString("tls-cert"),
TlsCertificateFile: viper.GetString("tls-cert-file"),
......
......@@ -32,8 +32,12 @@ func Start(config *Configuration) error {
return err
}
bts, _ := json.MarshalIndent(conf, "", " ")
conf.Logger.Debug("Configuration: ", string(bts), "\n")
if conf.LogJSON {
conf.Logger.WithField("configuration", conf).Debug("Configuration")
} else {
bts, _ := json.MarshalIndent(conf, "", " ")
conf.Logger.Debug("Configuration: ", string(bts), "\n")
}
// Start server(s)
if conf.separateClientServer() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment