mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-27 10:53:42 +02:00
cmd/main/main.go: implement logrotation.
This commit is contained in:
parent
e44dc2f4f1
commit
6729985002
1 changed files with 23 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ import (
|
||||||
"github.com/eosswedenorg/thalos/app"
|
"github.com/eosswedenorg/thalos/app"
|
||||||
"github.com/eosswedenorg/thalos/app/abi"
|
"github.com/eosswedenorg/thalos/app/abi"
|
||||||
"github.com/eosswedenorg/thalos/app/config"
|
"github.com/eosswedenorg/thalos/app/config"
|
||||||
|
. "github.com/eosswedenorg/thalos/app/log"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
@ -127,15 +129,6 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*logFile) > 0 {
|
|
||||||
logfd, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Fatal("failed open logfile")
|
|
||||||
}
|
|
||||||
log.Info("Logging to file: ", *logFile)
|
|
||||||
log.SetOutput(logfd)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write PID file
|
// Write PID file
|
||||||
if len(*pidFile) > 0 {
|
if len(*pidFile) > 0 {
|
||||||
log.Infof("Writing pid to: %s", *pidFile)
|
log.Infof("Writing pid to: %s", *pidFile)
|
||||||
|
|
@ -153,6 +146,27 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If log file is given on the commandline, override config values.
|
||||||
|
if len(*logFile) > 0 {
|
||||||
|
conf.Log.Directory = path.Dir(*logFile)
|
||||||
|
conf.Log.Filename = path.Base(*logFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(conf.Log.Filename) > 0 {
|
||||||
|
writer, err := NewRotatingFileFromConfig(conf.Log)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Fatal("Failed to open log")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"maxfilesize": conf.Log.MaxFileSize,
|
||||||
|
"maxage": conf.Log.MaxTime,
|
||||||
|
"directory": conf.Log.GetDirectory(),
|
||||||
|
"filename": conf.Log.GetFilename(),
|
||||||
|
}).Info("Logging to file: ", conf.Log.GetFilePath())
|
||||||
|
log.SetOutput(writer)
|
||||||
|
}
|
||||||
|
|
||||||
// Init telegram notification service
|
// Init telegram notification service
|
||||||
telegram, err := telegram.New(conf.Telegram.Id)
|
telegram, err := telegram.New(conf.Telegram.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue