From 951ecf4d778b8d1a02a368bfc78f80aeb8e44272 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 3 Feb 2022 18:56:55 +0100 Subject: [PATCH] add --log-file command line argument Signed-off-by: Steffen Vogel --- cmd/wice/docs.go | 8 ++++---- cmd/wice/root.go | 21 ++++++++++++--------- cmd/wice/signal.go | 2 +- docs/usage/man/wice-completion-bash.3 | 4 ++++ docs/usage/man/wice-completion-fish.3 | 4 ++++ docs/usage/man/wice-completion-powershell.3 | 4 ++++ docs/usage/man/wice-completion-zsh.3 | 4 ++++ docs/usage/man/wice-completion.3 | 4 ++++ docs/usage/man/wice-daemon.3 | 6 +++++- docs/usage/man/wice-monitor.3 | 4 ++++ docs/usage/man/wice-signal.3 | 6 +++++- docs/usage/man/wice-stop.3 | 4 ++++ docs/usage/man/wice-sync.3 | 4 ++++ docs/usage/man/wice-wg-genkey.3 | 4 ++++ docs/usage/man/wice-wg-genpsk.3 | 4 ++++ docs/usage/man/wice-wg-pubkey.3 | 4 ++++ docs/usage/man/wice-wg-show.3 | 4 ++++ docs/usage/man/wice-wg.3 | 4 ++++ docs/usage/man/wice.3 | 6 +++++- docs/usage/md/wice.md | 3 +++ docs/usage/md/wice_completion.md | 1 + docs/usage/md/wice_completion_bash.md | 1 + docs/usage/md/wice_completion_fish.md | 1 + docs/usage/md/wice_completion_powershell.md | 1 + docs/usage/md/wice_completion_zsh.md | 1 + docs/usage/md/wice_daemon.md | 3 ++- docs/usage/md/wice_monitor.md | 1 + docs/usage/md/wice_signal.md | 3 ++- docs/usage/md/wice_stop.md | 1 + docs/usage/md/wice_sync.md | 1 + docs/usage/md/wice_wg.md | 1 + docs/usage/md/wice_wg_genkey.md | 1 + docs/usage/md/wice_wg_genpsk.md | 1 + docs/usage/md/wice_wg_pubkey.md | 1 + docs/usage/md/wice_wg_show.md | 1 + internal/common.go | 7 ++++++- internal/config/config.go | 2 +- internal/config/types.go | 11 ----------- internal/test/main.go | 2 +- 39 files changed, 112 insertions(+), 33 deletions(-) diff --git a/cmd/wice/docs.go b/cmd/wice/docs.go index 00f7c103..67624e81 100644 --- a/cmd/wice/docs.go +++ b/cmd/wice/docs.go @@ -15,10 +15,10 @@ var ( outputDir string docsCmd = &cobra.Command{ - Use: "docs", - Short: "Generate documentation for the wice commands", - // Hidden: true, - Args: cobra.NoArgs, + Use: "docs", + Short: "Generate documentation for the wice commands", + Hidden: true, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { if err := docsMarkdown(cmd, args); err != nil { return err diff --git a/cmd/wice/root.go b/cmd/wice/root.go index 32e27e3e..5b13cf31 100644 --- a/cmd/wice/root.go +++ b/cmd/wice/root.go @@ -46,37 +46,40 @@ var ( Long: "Wireguard Interactive Connectitivty Establishment", // The main wice command is just an alias for "wice daemon" - Run: daemon, + Run: daemon, + DisableAutoGenTag: true, + Version: version, } version string //lint:ignore U1000 set via ldflags -X / goreleaser commit string //lint:ignore U1000 set via ldflags -X / goreleaser date string //lint:ignore U1000 set via ldflags -X / goreleaser - level = logLevel{zapcore.InfoLevel} + logLevel = level{zapcore.InfoLevel} + logFile string ) -type logLevel struct { +type level struct { zapcore.Level } -func (l *logLevel) Type() string { +func (l *level) Type() string { return "string" } func init() { + rootCmd.SetUsageTemplate(usageTemplate) + cobra.OnInitialize( internal.SetupRand, setupLogging, ) - rootCmd.Version = version - rootCmd.SetUsageTemplate(usageTemplate) - pf := rootCmd.PersistentFlags() - pf.VarP(&level, "log-level", "d", "log level (one of \"debug\", \"info\", \"warn\", \"error\", \"dpanic\", \"panic\", and \"fatal\")") + pf.VarP(&logLevel, "log-level", "d", "log level (one of \"debug\", \"info\", \"warn\", \"error\", \"dpanic\", \"panic\", and \"fatal\")") + pf.StringVarP(&logFile, "log-file", "l", "", "path of a file to write logs to") } func setupLogging() { - logger = internal.SetupLogging(level.Level) + logger = internal.SetupLogging(logLevel.Level, logFile) } diff --git a/cmd/wice/signal.go b/cmd/wice/signal.go index 601af8fd..b7d5133e 100644 --- a/cmd/wice/signal.go +++ b/cmd/wice/signal.go @@ -23,7 +23,7 @@ var ( func init() { pf := signalCmd.PersistentFlags() - pf.StringVarP(&listenAddress, "listen", "l", ":443", "listen address") + pf.StringVarP(&listenAddress, "listen", "L", ":443", "listen address") rootCmd.AddCommand(signalCmd) } diff --git a/docs/usage/man/wice-completion-bash.3 b/docs/usage/man/wice-completion-bash.3 index 2b4c0879..76059f60 100644 --- a/docs/usage/man/wice-completion-bash.3 +++ b/docs/usage/man/wice-completion-bash.3 @@ -69,6 +69,10 @@ You will need to start a new shell for this setup to take effect. .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-completion-fish.3 b/docs/usage/man/wice-completion-fish.3 index 9210c890..eaffdd74 100644 --- a/docs/usage/man/wice-completion-fish.3 +++ b/docs/usage/man/wice-completion-fish.3 @@ -54,6 +54,10 @@ You will need to start a new shell for this setup to take effect. .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-completion-powershell.3 b/docs/usage/man/wice-completion-powershell.3 index 05fde6c5..002b4cd0 100644 --- a/docs/usage/man/wice-completion-powershell.3 +++ b/docs/usage/man/wice-completion-powershell.3 @@ -43,6 +43,10 @@ to your powershell profile. .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-completion-zsh.3 b/docs/usage/man/wice-completion-zsh.3 index 170dbb74..d12c20d9 100644 --- a/docs/usage/man/wice-completion-zsh.3 +++ b/docs/usage/man/wice-completion-zsh.3 @@ -66,6 +66,10 @@ You will need to start a new shell for this setup to take effect. .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-completion.3 b/docs/usage/man/wice-completion.3 index 7b81588b..9f083578 100644 --- a/docs/usage/man/wice-completion.3 +++ b/docs/usage/man/wice-completion.3 @@ -24,6 +24,10 @@ See each sub-command's help for details on how to use the generated script. .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-daemon.3 b/docs/usage/man/wice-daemon.3 index 3e25f3a3..c8690a0e 100644 --- a/docs/usage/man/wice-daemon.3 +++ b/docs/usage/man/wice-daemon.3 @@ -62,7 +62,7 @@ Start the daemon interval netween STUN keepalives .PP -\fB-l\fP, \fB--ice-lite\fP[=false] +\fB-L\fP, \fB--ice-lite\fP[=false] lite agents do not perform connectivity check and only provide host candidates .PP @@ -139,6 +139,10 @@ Start the daemon .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-monitor.3 b/docs/usage/man/wice-monitor.3 index bcd59ac8..8218774f 100644 --- a/docs/usage/man/wice-monitor.3 +++ b/docs/usage/man/wice-monitor.3 @@ -27,6 +27,10 @@ Monitor the WICE daemon for events .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-signal.3 b/docs/usage/man/wice-signal.3 index 4ee94672..81097510 100644 --- a/docs/usage/man/wice-signal.3 +++ b/docs/usage/man/wice-signal.3 @@ -22,11 +22,15 @@ Start gRPC signaling server help for signal .PP -\fB-l\fP, \fB--listen\fP=":443" +\fB-L\fP, \fB--listen\fP=":443" listen address .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-stop.3 b/docs/usage/man/wice-stop.3 index 56ca5bec..ace4cfa2 100644 --- a/docs/usage/man/wice-stop.3 +++ b/docs/usage/man/wice-stop.3 @@ -27,6 +27,10 @@ Shutdown the WICE daemon .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-sync.3 b/docs/usage/man/wice-sync.3 index b30a06f1..e7bad2fa 100644 --- a/docs/usage/man/wice-sync.3 +++ b/docs/usage/man/wice-sync.3 @@ -27,6 +27,10 @@ Synchronizes the internal daemon state with the state of the Wireguard interface .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-wg-genkey.3 b/docs/usage/man/wice-wg-genkey.3 index a918b9c4..20c0f755 100644 --- a/docs/usage/man/wice-wg-genkey.3 +++ b/docs/usage/man/wice-wg-genkey.3 @@ -23,6 +23,10 @@ Generates a new private key and writes it to stdout .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-wg-genpsk.3 b/docs/usage/man/wice-wg-genpsk.3 index 9808803b..af550c00 100644 --- a/docs/usage/man/wice-wg-genpsk.3 +++ b/docs/usage/man/wice-wg-genpsk.3 @@ -23,6 +23,10 @@ Generates a new preshared key and writes it to stdout .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-wg-pubkey.3 b/docs/usage/man/wice-wg-pubkey.3 index da4f90cb..7729dc40 100644 --- a/docs/usage/man/wice-wg-pubkey.3 +++ b/docs/usage/man/wice-wg-pubkey.3 @@ -23,6 +23,10 @@ Reads a private key from stdin and writes a public key to stdout .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-wg-show.3 b/docs/usage/man/wice-wg-show.3 index 4f1b6610..47508028 100644 --- a/docs/usage/man/wice-wg-show.3 +++ b/docs/usage/man/wice-wg-show.3 @@ -27,6 +27,10 @@ Shows the current configuration and device information .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice-wg.3 b/docs/usage/man/wice-wg.3 index a4200078..39a1e17d 100644 --- a/docs/usage/man/wice-wg.3 +++ b/docs/usage/man/wice-wg.3 @@ -23,6 +23,10 @@ Wireguard commands .SH OPTIONS INHERITED FROM PARENT COMMANDS +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") diff --git a/docs/usage/man/wice.3 b/docs/usage/man/wice.3 index 15db6a05..1a7cd9b2 100644 --- a/docs/usage/man/wice.3 +++ b/docs/usage/man/wice.3 @@ -21,6 +21,10 @@ Wireguard Interactive Connectitivty Establishment \fB-h\fP, \fB--help\fP[=false] help for wice +.PP +\fB-l\fP, \fB--log-file\fP="" + path of a file to write logs to + .PP \fB-d\fP, \fB--log-level\fP="info" log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") @@ -28,4 +32,4 @@ Wireguard Interactive Connectitivty Establishment .SH SEE ALSO .PP -\fBwice-completion(3)\fP, \fBwice-daemon(3)\fP, \fBwice-monitor(3)\fP, \fBwice-signal(3)\fP, \fBwice-stop(3)\fP, \fBwice-sync(3)\fP, \fBwice-wg(3)\fP +\fBwice-completion(3)\fP, \fBwice-daemon(3)\fP, \fBwice-interface(3)\fP, \fBwice-monitor(3)\fP, \fBwice-peer(3)\fP, \fBwice-signal(3)\fP, \fBwice-stop(3)\fP, \fBwice-sync(3)\fP, \fBwice-wg(3)\fP diff --git a/docs/usage/md/wice.md b/docs/usage/md/wice.md index 8a50fdf2..15ff2967 100644 --- a/docs/usage/md/wice.md +++ b/docs/usage/md/wice.md @@ -14,6 +14,7 @@ wice [flags] ``` -h, --help help for wice + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` @@ -21,7 +22,9 @@ wice [flags] * [wice completion](wice_completion.md) - Generate the autocompletion script for the specified shell * [wice daemon](wice_daemon.md) - Start the daemon +* [wice interface](wice_interface.md) - Manage Wireguard interfaces * [wice monitor](wice_monitor.md) - Monitor the WICE daemon for events +* [wice peer](wice_peer.md) - Manage Wireguard peers * [wice signal](wice_signal.md) - Start gRPC signaling server * [wice stop](wice_stop.md) - Shutdown the WICE daemon * [wice sync](wice_sync.md) - Synchronize interfaces diff --git a/docs/usage/md/wice_completion.md b/docs/usage/md/wice_completion.md index 7ab1aee4..eed8346d 100644 --- a/docs/usage/md/wice_completion.md +++ b/docs/usage/md/wice_completion.md @@ -17,6 +17,7 @@ See each sub-command's help for details on how to use the generated script. ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_completion_bash.md b/docs/usage/md/wice_completion_bash.md index ad560861..2cd4b6a9 100644 --- a/docs/usage/md/wice_completion_bash.md +++ b/docs/usage/md/wice_completion_bash.md @@ -40,6 +40,7 @@ wice completion bash ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_completion_fish.md b/docs/usage/md/wice_completion_fish.md index 6030624e..9498f4ac 100644 --- a/docs/usage/md/wice_completion_fish.md +++ b/docs/usage/md/wice_completion_fish.md @@ -31,6 +31,7 @@ wice completion fish [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_completion_powershell.md b/docs/usage/md/wice_completion_powershell.md index 724dca4d..4fb6e013 100644 --- a/docs/usage/md/wice_completion_powershell.md +++ b/docs/usage/md/wice_completion_powershell.md @@ -28,6 +28,7 @@ wice completion powershell [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_completion_zsh.md b/docs/usage/md/wice_completion_zsh.md index 3187f4ea..b1334333 100644 --- a/docs/usage/md/wice_completion_zsh.md +++ b/docs/usage/md/wice_completion_zsh.md @@ -38,6 +38,7 @@ wice completion zsh [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_daemon.md b/docs/usage/md/wice_daemon.md index 3874a3f6..4ca9ac0b 100644 --- a/docs/usage/md/wice_daemon.md +++ b/docs/usage/md/wice_daemon.md @@ -20,7 +20,7 @@ wice daemon [interfaces...] [flags] -k, --ice-insecure-skip-verify skip verification of TLS certificates for secure STUN/TURN servers --ice-interface-filter string regex for filtering local interfaces for ICE candidate gathering (e.g. "eth[0-9]+") (default ".*") --ice-keepalive-interval duration interval netween STUN keepalives (default 2s) - -l, --ice-lite lite agents do not perform connectivity check and only provide host candidates + -L, --ice-lite lite agents do not perform connectivity check and only provide host candidates --ice-max-binding-requests uint16 maximum number of binding request before considering a pair failed (default 7) -m, --ice-mdns enable local Multicast DNS discovery --ice-nat-1to1-ip ipSlice IP addresses which will be added as local server reflexive candidates (default []) @@ -44,6 +44,7 @@ wice daemon [interfaces...] [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_monitor.md b/docs/usage/md/wice_monitor.md index f75822b5..f7358607 100644 --- a/docs/usage/md/wice_monitor.md +++ b/docs/usage/md/wice_monitor.md @@ -16,6 +16,7 @@ wice monitor [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_signal.md b/docs/usage/md/wice_signal.md index 6eba4ab9..7a42019e 100644 --- a/docs/usage/md/wice_signal.md +++ b/docs/usage/md/wice_signal.md @@ -10,12 +10,13 @@ wice signal [flags] ``` -h, --help help for signal - -l, --listen string listen address (default ":443") + -L, --listen string listen address (default ":443") ``` ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_stop.md b/docs/usage/md/wice_stop.md index 308cce6d..1e8e0325 100644 --- a/docs/usage/md/wice_stop.md +++ b/docs/usage/md/wice_stop.md @@ -16,6 +16,7 @@ wice stop [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_sync.md b/docs/usage/md/wice_sync.md index 5562d5b9..2ba5ae70 100644 --- a/docs/usage/md/wice_sync.md +++ b/docs/usage/md/wice_sync.md @@ -20,6 +20,7 @@ wice sync [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_wg.md b/docs/usage/md/wice_wg.md index cac631df..c5288b5c 100644 --- a/docs/usage/md/wice_wg.md +++ b/docs/usage/md/wice_wg.md @@ -11,6 +11,7 @@ Wireguard commands ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_wg_genkey.md b/docs/usage/md/wice_wg_genkey.md index 476c3e33..00ebca8f 100644 --- a/docs/usage/md/wice_wg_genkey.md +++ b/docs/usage/md/wice_wg_genkey.md @@ -15,6 +15,7 @@ wice wg genkey [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_wg_genpsk.md b/docs/usage/md/wice_wg_genpsk.md index ce4be662..99c12bfa 100644 --- a/docs/usage/md/wice_wg_genpsk.md +++ b/docs/usage/md/wice_wg_genpsk.md @@ -15,6 +15,7 @@ wice wg genpsk [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_wg_pubkey.md b/docs/usage/md/wice_wg_pubkey.md index 13db5786..67cc1e2e 100644 --- a/docs/usage/md/wice_wg_pubkey.md +++ b/docs/usage/md/wice_wg_pubkey.md @@ -15,6 +15,7 @@ wice wg pubkey [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/docs/usage/md/wice_wg_show.md b/docs/usage/md/wice_wg_show.md index 68c19c34..8ed25ccf 100644 --- a/docs/usage/md/wice_wg_show.md +++ b/docs/usage/md/wice_wg_show.md @@ -16,6 +16,7 @@ wice wg show [flags] ### Options inherited from parent commands ``` + -l, --log-file string path of a file to write logs to -d, --log-level string log level (one of "debug", "info", "warn", "error", "dpanic", "panic", and "fatal") (default "info") ``` diff --git a/internal/common.go b/internal/common.go index e590314a..87f6c053 100644 --- a/internal/common.go +++ b/internal/common.go @@ -19,7 +19,7 @@ import ( "riasc.eu/wice/internal/log" ) -func SetupLogging(level zapcore.Level) *zap.Logger { +func SetupLogging(level zapcore.Level, file string) *zap.Logger { cfg := zap.NewDevelopmentConfig() cfg.Level = zap.NewAtomicLevelAt(level) @@ -27,6 +27,10 @@ func SetupLogging(level zapcore.Level) *zap.Logger { cfg.DisableCaller = true cfg.DisableStacktrace = true + if file != "" { + cfg.OutputPaths = append(cfg.OutputPaths, file) + } + logger, err := cfg.Build() if err != nil { panic(err) @@ -43,6 +47,7 @@ func SetupLogging(level zapcore.Level) *zap.Logger { glogger := logger.Named("grpc") grpclog.SetLoggerV2(log.NewGRPCLogger(glogger)) + zap.RedirectStdLog(logger) zap.ReplaceGlobals(logger) return logger diff --git a/internal/config/config.go b/internal/config/config.go index daccc758..5d49e92c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -153,7 +153,7 @@ func NewConfig(flags *pflag.FlagSet) *Config { flags.Uint16Var(&cfg.icePortMin, "ice-port-min", 0, "minimum port for allocation policy (range: 0-65535)") flags.Uint16Var(&cfg.icePortMax, "ice-port-max", 0, "maximum port for allocation policy (range: 0-65535)") - flags.BoolVarP(&cfg.iceLite, "ice-lite", "l", false, "lite agents do not perform connectivity check and only provide host candidates") + flags.BoolVarP(&cfg.iceLite, "ice-lite", "L", false, "lite agents do not perform connectivity check and only provide host candidates") flags.BoolVarP(&cfg.iceMdns, "ice-mdns", "m", false, "enable local Multicast DNS discovery") flags.Uint16Var(&cfg.iceMaxBindingRequests, "ice-max-binding-requests", defaultMaxBindingRequests, "maximum number of binding request before considering a pair failed") flags.BoolVarP(&cfg.iceInsecureSkipVerify, "ice-insecure-skip-verify", "k", false, "skip verification of TLS certificates for secure STUN/TURN servers") diff --git a/internal/config/types.go b/internal/config/types.go index 3e1b0163..0d81fb4d 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/pion/ice/v2" - "go.uber.org/zap" "riasc.eu/wice/pkg/proxy" ) @@ -144,16 +143,6 @@ func (pt *proxyType) Set(value string) error { return err } -type logLevel struct{ zap.AtomicLevel } - -func (ll *logLevel) Type() string { - return "string" -} - -func (ll *logLevel) Set(value string) error { - return ll.UnmarshalText([]byte(value)) -} - type regex struct{ *regexp.Regexp } func (re *regex) Type() string { diff --git a/internal/test/main.go b/internal/test/main.go index b96e74f5..892bdced 100644 --- a/internal/test/main.go +++ b/internal/test/main.go @@ -10,7 +10,7 @@ import ( func Main(m *testing.M) { internal.SetupRand() - logger := internal.SetupLogging(zapcore.DebugLevel) + logger := internal.SetupLogging(zapcore.DebugLevel, "logs/test.log") defer logger.Sync() os.Exit(m.Run())