mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-15 13:42:26 +03:00
cmd: common/log: Always configure logging
When LOG_DIR or so is not specified, just configure the formatter.
This commit is contained in:
parent
8010083026
commit
e8d2d61cc2
3 changed files with 20 additions and 20 deletions
|
@ -10,16 +10,22 @@ import (
|
|||
|
||||
// SetupLogging configures the logging format and destination(s).
|
||||
func SetupLogging(logDir string) {
|
||||
_ = os.Mkdir(logDir, os.ModePerm)
|
||||
logrus.AddHook(dugong.NewFSHook(
|
||||
filepath.Join(logDir, "info.log"),
|
||||
filepath.Join(logDir, "warn.log"),
|
||||
filepath.Join(logDir, "error.log"),
|
||||
&logrus.TextFormatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000000",
|
||||
DisableColors: true,
|
||||
DisableTimestamp: false,
|
||||
DisableSorting: false,
|
||||
}, &dugong.DailyRotationSchedule{GZip: true},
|
||||
))
|
||||
formatter := &logrus.TextFormatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000000",
|
||||
DisableColors: true,
|
||||
DisableTimestamp: false,
|
||||
DisableSorting: false,
|
||||
}
|
||||
if logDir != "" {
|
||||
_ = os.Mkdir(logDir, os.ModePerm)
|
||||
logrus.AddHook(dugong.NewFSHook(
|
||||
filepath.Join(logDir, "info.log"),
|
||||
filepath.Join(logDir, "warn.log"),
|
||||
filepath.Join(logDir, "error.log"),
|
||||
formatter,
|
||||
&dugong.DailyRotationSchedule{GZip: true},
|
||||
))
|
||||
} else {
|
||||
logrus.SetFormatter(formatter)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue