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:
parent
8b927ed366
commit
1cd741c610
1 changed files with 10 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue