Added possible fix for logging when nothing is set
This commit is contained in:
parent
9e635ea54e
commit
5e7c9b9eb9
3 changed files with 15 additions and 13 deletions
|
|
@ -83,6 +83,7 @@ func InitLogger() {
|
|||
|
||||
// GetLogWriter returns the writer to where the normal log goes, depending on the config
|
||||
func GetLogWriter(logfile string) (writer io.Writer) {
|
||||
writer = os.Stderr // Set the default case to prevent nil pointer panics
|
||||
switch viper.GetString("log." + logfile) {
|
||||
case "file":
|
||||
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
|
||||
break
|
||||
case "stderr":
|
||||
writer = os.Stderr
|
||||
case "stdout":
|
||||
default:
|
||||
writer = os.Stdout
|
||||
|
|
|
|||
Reference in a new issue