logger: Disassociate shared log config between console, file and syslog (#3333)

logurs is not helping us to set different log formats (json/text) to
different loggers. Now, we create different logurs instances and call
them in errorIf and fatalIf
This commit is contained in:
Anis Elleuch
2016-11-23 20:35:04 +01:00
committed by Harshavardhana
parent 01ae5bb39c
commit 22c98d3fa2
5 changed files with 47 additions and 19 deletions

View File

@@ -16,11 +16,7 @@
package cmd
import (
"io/ioutil"
"github.com/Sirupsen/logrus"
)
import "github.com/Sirupsen/logrus"
// consoleLogger - default logger if not other logging is enabled.
type consoleLogger struct {
@@ -32,15 +28,19 @@ type consoleLogger struct {
func enableConsoleLogger() {
clogger := serverConfig.GetConsoleLogger()
if !clogger.Enable {
// Disable console logger if asked for.
log.Out = ioutil.Discard
return
}
consoleLogger := logrus.New()
// log.Out and log.Formatter use the default versions.
// Only set specific log level.
lvl, err := logrus.ParseLevel(clogger.Level)
fatalIf(err, "Unknown log level found in the config file.")
log.Level = lvl
consoleLogger.Level = lvl
consoleLogger.Formatter = new(logrus.TextFormatter)
log.mu.Lock()
log.loggers = append(log.loggers, consoleLogger)
log.mu.Unlock()
}