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 { ...@@ -62,6 +62,7 @@ type Configuration struct {
Verbose int `json:"verbose" mapstructure:"verbose"` Verbose int `json:"verbose" mapstructure:"verbose"`
Quiet bool `json:"quiet" mapstructure:"quiet"` Quiet bool `json:"quiet" mapstructure:"quiet"`
LogJSON bool `json:"log_json" mapstructure:"log_json"`
jwtPrivateKey *rsa.PrivateKey jwtPrivateKey *rsa.PrivateKey
} }
......
...@@ -153,6 +153,7 @@ using the corresponding "-file" flag.` ...@@ -153,6 +153,7 @@ using the corresponding "-file" flag.`
flags.CountP("verbose", "v", "verbose (repeatable)") flags.CountP("verbose", "v", "verbose (repeatable)")
flags.BoolP("quiet", "q", false, "quiet") flags.BoolP("quiet", "q", false, "quiet")
flags.Bool("log-json", false, "Log in JSON format")
flags.Lookup("verbose").Header = `Other options` flags.Lookup("verbose").Header = `Other options`
return nil return nil
...@@ -183,6 +184,9 @@ func configure(cmd *cobra.Command) error { ...@@ -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 err := viper.ReadInConfig() // Hold error checking until we know how much of it to log
// Set log level // Set log level
if viper.GetBool("log-json") {
logger.SetFormatter(&logrus.JSONFormatter{})
}
logger.Level = server.Verbosity(viper.GetInt("verbose")) logger.Level = server.Verbosity(viper.GetInt("verbose"))
if viper.GetBool("quiet") { if viper.GetBool("quiet") {
logger.Out = ioutil.Discard logger.Out = ioutil.Discard
...@@ -228,6 +232,7 @@ func configure(cmd *cobra.Command) error { ...@@ -228,6 +232,7 @@ func configure(cmd *cobra.Command) error {
MaxRequestAge: viper.GetInt("max-request-age"), MaxRequestAge: viper.GetInt("max-request-age"),
Verbose: viper.GetInt("verbose"), Verbose: viper.GetInt("verbose"),
Quiet: viper.GetBool("quiet"), Quiet: viper.GetBool("quiet"),
LogJSON: viper.GetBool("log-json"),
TlsCertificate: viper.GetString("tls-cert"), TlsCertificate: viper.GetString("tls-cert"),
TlsCertificateFile: viper.GetString("tls-cert-file"), TlsCertificateFile: viper.GetString("tls-cert-file"),
......
...@@ -32,8 +32,12 @@ func Start(config *Configuration) error { ...@@ -32,8 +32,12 @@ func Start(config *Configuration) error {
return err return err
} }
bts, _ := json.MarshalIndent(conf, "", " ") if conf.LogJSON {
conf.Logger.Debug("Configuration: ", string(bts), "\n") conf.Logger.WithField("configuration", conf).Debug("Configuration")
} else {
bts, _ := json.MarshalIndent(conf, "", " ")
conf.Logger.Debug("Configuration: ", string(bts), "\n")
}
// Start server(s) // Start server(s)
if conf.separateClientServer() { 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