Commit fb068f80 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Make verbosity configurable

parent 5e4c2f59
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
...@@ -29,6 +30,11 @@ func main() { ...@@ -29,6 +30,11 @@ func main() {
}, },
} }
logger.Level = logrus.InfoLevel
logger.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
if err := setFlags(cmd); err != nil { if err := setFlags(cmd); err != nil {
die(errors.WrapPrefix(err, "Failed to attach flags", 0)) die(errors.WrapPrefix(err, "Failed to attach flags", 0))
} }
...@@ -40,7 +46,7 @@ func main() { ...@@ -40,7 +46,7 @@ func main() {
func die(err *errors.Error) { func die(err *errors.Error) {
logger.Error(err.Error()) logger.Error(err.Error())
logger.Debug(string(err.Stack())) logger.Trace(string(err.Stack()))
os.Exit(1) os.Exit(1)
} }
...@@ -63,12 +69,9 @@ func setFlags(cmd *cobra.Command) error { ...@@ -63,12 +69,9 @@ func setFlags(cmd *cobra.Command) error {
flags.Lookup("signing").NoOptDefVal = "*" flags.Lookup("signing").NoOptDefVal = "*"
flags.Lookup("issuing").NoOptDefVal = "*" flags.Lookup("issuing").NoOptDefVal = "*"
return viper.BindPFlags(flags) flags.BoolP("verbose", "v", false, "verbose")
} flags.Bool("vverbose", false, "more verbose")
flags.BoolP("quiet", "q", false, "quiet")
func configure() error {
logger.Level = logrus.TraceLevel
logger.Debugf("Configuring")
// Environment variables // Environment variables
viper.SetEnvPrefix("IRMASERVER") viper.SetEnvPrefix("IRMASERVER")
...@@ -79,7 +82,24 @@ func configure() error { ...@@ -79,7 +82,24 @@ func configure() error {
viper.AddConfigPath(".") viper.AddConfigPath(".")
viper.AddConfigPath("/etc/irmaserver/") viper.AddConfigPath("/etc/irmaserver/")
viper.AddConfigPath("$HOME/.irmaserver") viper.AddConfigPath("$HOME/.irmaserver")
if err := viper.ReadInConfig(); err != nil {
return viper.BindPFlags(flags)
}
func configure() error {
err := viper.ReadInConfig() // Hold error checking until we know how much of it to log
if viper.GetBool("verbose") {
logger.Level = logrus.DebugLevel
}
if viper.GetBool("vverbose") {
logger.Level = logrus.TraceLevel
}
if viper.GetBool("quiet") {
logger.Out = ioutil.Discard
}
logger.Debugf("Configuring")
if err != nil {
logger.Info("No configuration file found") logger.Info("No configuration file found")
} else { } else {
logger.Info("Config file: ", viper.ConfigFileUsed()) logger.Info("Config file: ", viper.ConfigFileUsed())
...@@ -98,6 +118,8 @@ func configure() error { ...@@ -98,6 +118,8 @@ func configure() error {
GlobalPermissions: irmaserver.Permissions{}, GlobalPermissions: irmaserver.Permissions{},
JwtIssuer: viper.GetString("jwtissuer"), JwtIssuer: viper.GetString("jwtissuer"),
JwtPrivateKey: viper.GetString("jwtprivatekey"), JwtPrivateKey: viper.GetString("jwtprivatekey"),
Verbose: viper.GetBool("verbose"),
VVerbose: viper.GetBool("vverbose"),
} }
// Handle global permissions // Handle global permissions
......
...@@ -32,6 +32,10 @@ type Configuration struct { ...@@ -32,6 +32,10 @@ type Configuration struct {
// Private key to sign result JWTs with. If absent, /result-jwt and /getproof are disabled. // Private key to sign result JWTs with. If absent, /result-jwt and /getproof are disabled.
JwtPrivateKey string `json:"jwtprivatekey" mapstructure:"jwtprivatekey"` JwtPrivateKey string `json:"jwtprivatekey" mapstructure:"jwtprivatekey"`
Verbose bool
VVerbose bool
Quiet bool
jwtPrivateKey *rsa.PrivateKey jwtPrivateKey *rsa.PrivateKey
} }
......
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