Add logfile feature

This commit is contained in:
Cameron Moore 2019-12-27 11:51:44 -06:00
parent 66562fdb41
commit 725fda68dc
2 changed files with 15 additions and 1 deletions

View file

@ -19,6 +19,8 @@ Usage of webhook:
path to the HTTPS certificate private key pem file (default "key.pem")
-list-cipher-suites
list available TLS cipher suites
-logfile string
send log output to a file; implicitly enables verbose logging
-nopanic
do not panic if hooks cannot be loaded when webhook is not running in verbose mode
-port int

View file

@ -33,6 +33,7 @@ var (
ip = flag.String("ip", "0.0.0.0", "ip the webhook should serve hooks on")
port = flag.Int("port", 9000, "port the webhook should serve hooks on")
verbose = flag.Bool("verbose", false, "show verbose output")
logPath = flag.String("logfile", "", "send log output to a file; implicitly enables verbose logging")
debug = flag.Bool("debug", false, "show debug output")
noPanic = flag.Bool("nopanic", false, "do not panic if hooks cannot be loaded when webhook is not running in verbose mode")
hotReload = flag.Bool("hotreload", false, "watch hooks file for changes and reload them automatically")
@ -103,7 +104,7 @@ func main() {
os.Exit(1)
}
if *debug {
if *debug || *logPath != "" {
*verbose = true
}
@ -111,6 +112,17 @@ func main() {
hooksFiles = append(hooksFiles, "hooks.json")
}
if *logPath != "" {
file, err := os.OpenFile(*logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Printf("error opening log file %q: %v", *logPath, err)
return
}
log.SetOutput(file)
}
log.SetPrefix("[webhook] ")
log.SetFlags(log.Ldate | log.Ltime)