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 /device/device.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 'device/device.go')
-rw-r--r-- | device/device.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/device/device.go b/device/device.go index 5d11766..27c42f2 100644 --- a/device/device.go +++ b/device/device.go @@ -177,7 +177,7 @@ func deviceUpdateState(device *Device) { switch newIsUp { case true: if err := device.BindUpdate(); err != nil { - device.log.Error.Println("Unable to update bind:", err) + device.errorf("Unable to update bind: %v", err) device.isUp.Set(false) break } @@ -303,7 +303,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger) *Device { device.tun.device = tunDevice mtu, err := device.tun.device.MTU() if err != nil { - logger.Error.Println("Trouble determining MTU, assuming default:", err) + device.errorf("Trouble determining MTU, assuming default: %v", err) mtu = DefaultMTU } device.tun.mtu = int32(mtu) @@ -397,7 +397,7 @@ func (device *Device) Close() { return } - device.log.Info.Println("Device closing") + device.infof("Device closing") device.state.changing.Set(true) device.state.Lock() defer device.state.Unlock() @@ -422,7 +422,7 @@ func (device *Device) Close() { device.rate.limiter.Close() device.state.changing.Set(false) - device.log.Info.Println("Interface closed") + device.infof("Interface closed") } func (device *Device) Wait() chan struct{} { @@ -562,7 +562,7 @@ func (device *Device) BindUpdate() error { go device.RoutineReceiveIncoming(ipv4.Version, netc.bind) go device.RoutineReceiveIncoming(ipv6.Version, netc.bind) - device.log.Debug.Println("UDP bind has been updated") + device.debugf("UDP bind has been updated") } return nil |