diff --git a/docs/Webhook-Parameters.md b/docs/Webhook-Parameters.md index 7d5beed..6e88a37 100644 --- a/docs/Webhook-Parameters.md +++ b/docs/Webhook-Parameters.md @@ -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 diff --git a/webhook.go b/webhook.go index 6807520..2902030 100644 --- a/webhook.go +++ b/webhook.go @@ -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)