1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-17 04:30:03 +02:00

cmd/main/main.go: Add support for logging to file via cli flag.

This commit is contained in:
Henrik Hautakoski 2023-05-02 16:20:19 +02:00
parent 8b927ed366
commit 1cd741c610

View file

@ -113,6 +113,7 @@ func main() {
showVersion := getopt.BoolLong("version", 'v', "display this help text")
configFile := getopt.StringLong("config", 'c', "./config.yml", "Config file to read", "file")
pidFile := getopt.StringLong("pid", 'p', "", "Where to write process id", "file")
logFile := getopt.StringLong("log", 'l', "", "Path to log file", "file")
getopt.Parse()
@ -126,6 +127,15 @@ func main() {
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
if len(*pidFile) > 0 {
log.Infof("Writing pid to: %s", *pidFile)