mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-10 15:44:43 +00:00
Add logfile feature
This commit is contained in:
parent
66562fdb41
commit
725fda68dc
2 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
|
14
webhook.go
14
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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue