Added possible fix for logging when nothing is set

This commit is contained in:
konrad 2019-01-25 21:09:24 +01:00
parent 9e635ea54e
commit 5e7c9b9eb9
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 15 additions and 13 deletions

View file

@ -76,13 +76,13 @@ log:
path: <rootpath>logs path: <rootpath>logs
# Whether to show any logging at all or none # Whether to show any logging at all or none
enabled: true enabled: true
# Where the error log should go. Possible values are stdout, file or off to disable error logging. # Where the error log should go. Possible values are stdout, stderr, file or off to disable error logging.
errors: "stdout" errors: "stdout"
# Where the normal log should go. Possible values are stdout, file or off to disable standard logging. # Where the normal log should go. Possible values are stdout, stderr, file or off to disable standard logging.
standard: "stdout" standard: "stdout"
# Whether or not to log database queries. Useful for debugging. Possible values are stdout, file or off to disable database logging. # Whether or not to log database queries. Useful for debugging. Possible values are stdout, stderr, file or off to disable database logging.
database: "off" database: "off"
# Whether to log http requests or not. Possible values are stdout, file or off to disable http logging. # Whether to log http requests or not. Possible values are stdout, stderr, file or off to disable http logging.
http: "stdout" http: "stdout"
# Echo has its own logging which usually is unnessecary, which is why it is disabled by default. Possible values are stdout, file or off to disable standard logging. # Echo has its own logging which usually is unnessecary, which is why it is disabled by default. Possible values are stdout, stderr, file or off to disable standard logging.
echo: "off" echo: "off"

View file

@ -106,18 +106,17 @@ mailer:
log: log:
# A folder where all the logfiles should go. # A folder where all the logfiles should go.
path: service.rootpath + "/logs" path: <rootpath>logs
# Whether to show any logging at all or none # Whether to show any logging at all or none
enabled: true enabled: true
# Where the error log should go. Possible values are stdout, file or off to disable error logging. # Where the error log should go. Possible values are stdout, stderr, file or off to disable error logging.
errors: "stdout" errors: "stdout"
# Where the normal log should go. Possible values are stdout, file or off to disable standard logging. # Where the normal log should go. Possible values are stdout, stderr, file or off to disable standard logging.
standard: "stdout" standard: "stdout"
# Whether or not to log database queries. Useful for debugging. Possible values are stdout, file or off to disable database logging. # Whether or not to log database queries. Useful for debugging. Possible values are stdout, stderr, file or off to disable database logging.
database: "off" database: "off"
# Whether to log http requests or not. Possible values are stdout, file or off to disable http logging. # Whether to log http requests or not. Possible values are stdout, stderr, file or off to disable http logging.
http: "stdout" http: "stdout"
# Echo has its own logging which usually is unnessecary, which is why it is disabled by default. Possible values are stdout, file or off to disable standard logging. # Echo has its own logging which usually is unnessecary, which is why it is disabled by default. Possible values are stdout, stderr, file or off to disable standard logging.
echo: "off" echo: "off"
``` ```

View file

@ -83,6 +83,7 @@ func InitLogger() {
// GetLogWriter returns the writer to where the normal log goes, depending on the config // GetLogWriter returns the writer to where the normal log goes, depending on the config
func GetLogWriter(logfile string) (writer io.Writer) { func GetLogWriter(logfile string) (writer io.Writer) {
writer = os.Stderr // Set the default case to prevent nil pointer panics
switch viper.GetString("log." + logfile) { switch viper.GetString("log." + logfile) {
case "file": case "file":
f, err := os.OpenFile(viper.GetString("log.path")+"/"+logfile+".log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) f, err := os.OpenFile(viper.GetString("log.path")+"/"+logfile+".log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
@ -91,6 +92,8 @@ func GetLogWriter(logfile string) (writer io.Writer) {
} }
writer = f writer = f
break break
case "stderr":
writer = os.Stderr
case "stdout": case "stdout":
default: default:
writer = os.Stdout writer = os.Stdout