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_windows.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_windows.go')
-rw-r--r-- | main_windows.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/main_windows.go b/main_windows.go index 291b00d..fea1b16 100644 --- a/main_windows.go +++ b/main_windows.go @@ -34,8 +34,8 @@ func main() { device.LogLevelDebug, 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") tun, err := tun.CreateTUN(interfaceName, 0) if err == nil { @@ -44,17 +44,17 @@ func main() { interfaceName = realInterfaceName } } else { - logger.Error.Println("Failed to create TUN device:", err) + logger.Errorf("Failed to create TUN device: %v", err) os.Exit(ExitSetupFailed) } device := device.NewDevice(tun, logger) device.Up() - logger.Info.Println("Device started") + logger.Infof("Device started") uapi, err := ipc.UAPIListen(interfaceName) 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) } @@ -71,7 +71,7 @@ func main() { go device.IpcHandle(conn) } }() - logger.Info.Println("UAPI listener started") + logger.Infof("UAPI listener started") // wait for program to terminate @@ -90,5 +90,5 @@ func main() { uapi.Close() device.Close() - logger.Info.Println("Shutting down") + logger.Infof("Shutting down") } |