mirror of
https://github.com/pgsty/minio.git
synced 2026-08-04 15:12:47 +03:00
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:
committed by
Harshavardhana
parent
01ae5bb39c
commit
22c98d3fa2
+11
-3
@@ -18,6 +18,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
@@ -43,15 +44,22 @@ func enableFileLogger() {
|
||||
file, err := os.OpenFile(flogger.Filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
||||
fatalIf(err, "Unable to open log file.")
|
||||
|
||||
fileLogger := logrus.New()
|
||||
|
||||
// Add a local file hook.
|
||||
log.Hooks.Add(&localFile{file})
|
||||
fileLogger.Hooks.Add(&localFile{file})
|
||||
|
||||
lvl, err := logrus.ParseLevel(flogger.Level)
|
||||
fatalIf(err, "Unknown log level found in the config file.")
|
||||
|
||||
// Set default JSON formatter.
|
||||
log.Formatter = new(logrus.JSONFormatter)
|
||||
log.Level = lvl // Minimum log level.
|
||||
fileLogger.Out = ioutil.Discard
|
||||
fileLogger.Formatter = new(logrus.JSONFormatter)
|
||||
fileLogger.Level = lvl // Minimum log level.
|
||||
|
||||
log.mu.Lock()
|
||||
log.loggers = append(log.loggers, fileLogger)
|
||||
log.mu.Unlock()
|
||||
}
|
||||
|
||||
// Fire fires the file logger hook and logs to the file.
|
||||
|
||||
Reference in New Issue
Block a user