diff options
author | Josh Bleecher Snyder <josh@tailscale.com> | 2021-01-22 14:11:17 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-26 22:40:20 +0100 |
commit | 7139279cd0b08ebbd2c0322bc01d5678aa00cd0e (patch) | |
tree | b49339aabb016e640f2f6088bc5753395d4239b8 /main.go | |
parent | 37efdcaccfb16e47137728b5462c90d0b2ae8460 (diff) |
device: change logging interface to use functions
This commit overhauls wireguard-go's logging.
The primary, motivating change is to use a function instead
of a *log.Logger as the basic unit of logging.
Using functions provides a lot more flexibility for
people to bring their own logging system.
It also introduces logging helper methods on Device.
These reduce line noise at the call site.
They also allow for log functions to be nil;
when nil, instead of generating a log line and throwing it away,
we don't bother generating it at all.
This spares allocation and pointless work.
This is a breaking change, although the fix required
of clients is fairly straightforward.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -143,12 +143,11 @@ func main() { fmt.Sprintf("(%s) ", interfaceName), ) - logger.Info.Println("Starting wireguard-go version", device.WireGuardGoVersion) - - logger.Debug.Println("Debug log enabled") + logger.Infof("Starting wireguard-go version %v", device.WireGuardGoVersion) + logger.Debugf("Debug log enabled") if err != nil { - logger.Error.Println("Failed to create TUN device:", err) + logger.Errorf("Failed to create TUN device: %v", err) os.Exit(ExitSetupFailed) } @@ -171,7 +170,7 @@ func main() { }() if err != nil { - logger.Error.Println("UAPI listen error:", err) + logger.Errorf("UAPI listen error: %v", err) os.Exit(ExitSetupFailed) return } @@ -206,7 +205,7 @@ func main() { path, err := os.Executable() if err != nil { - logger.Error.Println("Failed to determine executable:", err) + logger.Errorf("Failed to determine executable: %v", err) os.Exit(ExitSetupFailed) } @@ -216,7 +215,7 @@ func main() { attr, ) if err != nil { - logger.Error.Println("Failed to daemonize:", err) + logger.Errorf("Failed to daemonize: %v", err) os.Exit(ExitSetupFailed) } process.Release() @@ -225,14 +224,14 @@ func main() { device := device.NewDevice(tun, logger) - logger.Info.Println("Device started") + logger.Infof("Device started") errs := make(chan error) term := make(chan os.Signal, 1) uapi, err := ipc.UAPIListen(interfaceName, fileUAPI) if err != nil { - logger.Error.Println("Failed to listen on uapi socket:", err) + logger.Errorf("Failed to listen on uapi socket: %v", err) os.Exit(ExitSetupFailed) } @@ -247,7 +246,7 @@ func main() { } }() - logger.Info.Println("UAPI listener started") + logger.Infof("UAPI listener started") // wait for program to terminate @@ -265,5 +264,5 @@ func main() { uapi.Close() device.Close() - logger.Info.Println("Shutting down") + logger.Infof("Shutting down") } |