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
|
@ -20,10 +20,7 @@ func main() {
|
||||||
if bindAddr == "" {
|
if bindAddr == "" {
|
||||||
log.Panic("No BIND_ADDRESS environment variable found.")
|
log.Panic("No BIND_ADDRESS environment variable found.")
|
||||||
}
|
}
|
||||||
logDir := os.Getenv("LOG_DIR")
|
common.SetupLogging(os.Getenv("LOG_DIR"))
|
||||||
if logDir != "" {
|
|
||||||
common.SetupLogging(logDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Rather than generating a new key on every startup, we should be
|
// TODO: Rather than generating a new key on every startup, we should be
|
||||||
// reading a PEM formatted file instead.
|
// reading a PEM formatted file instead.
|
||||||
|
|
|
@ -47,10 +47,7 @@ func main() {
|
||||||
if *bindAddr == "" {
|
if *bindAddr == "" {
|
||||||
log.Fatal("--listen must be supplied")
|
log.Fatal("--listen must be supplied")
|
||||||
}
|
}
|
||||||
logDir := os.Getenv("LOG_DIR")
|
common.SetupLogging(os.Getenv("LOG_DIR"))
|
||||||
if logDir != "" {
|
|
||||||
common.SetupLogging(logDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("sync server config: ", cfg)
|
log.Info("sync server config: ", cfg)
|
||||||
|
|
||||||
|
|
|
@ -10,16 +10,22 @@ import (
|
||||||
|
|
||||||
// SetupLogging configures the logging format and destination(s).
|
// SetupLogging configures the logging format and destination(s).
|
||||||
func SetupLogging(logDir string) {
|
func SetupLogging(logDir string) {
|
||||||
_ = os.Mkdir(logDir, os.ModePerm)
|
formatter := &logrus.TextFormatter{
|
||||||
logrus.AddHook(dugong.NewFSHook(
|
TimestampFormat: "2006-01-02 15:04:05.000000",
|
||||||
filepath.Join(logDir, "info.log"),
|
DisableColors: true,
|
||||||
filepath.Join(logDir, "warn.log"),
|
DisableTimestamp: false,
|
||||||
filepath.Join(logDir, "error.log"),
|
DisableSorting: false,
|
||||||
&logrus.TextFormatter{
|
}
|
||||||
TimestampFormat: "2006-01-02 15:04:05.000000",
|
if logDir != "" {
|
||||||
DisableColors: true,
|
_ = os.Mkdir(logDir, os.ModePerm)
|
||||||
DisableTimestamp: false,
|
logrus.AddHook(dugong.NewFSHook(
|
||||||
DisableSorting: false,
|
filepath.Join(logDir, "info.log"),
|
||||||
}, &dugong.DailyRotationSchedule{GZip: true},
|
filepath.Join(logDir, "warn.log"),
|
||||||
))
|
filepath.Join(logDir, "error.log"),
|
||||||
|
formatter,
|
||||||
|
&dugong.DailyRotationSchedule{GZip: true},
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
logrus.SetFormatter(formatter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue