From 5aa2a7a14ceea290bf6f504088d4cd04bc06dc82 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Mar 2016 17:14:13 +0000 Subject: [PATCH] refactor(ish) of ipam plugin logging prefix all log entries with "[ipam]" Also eliminate a dot import. --- plugin/ipam/driver.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index 79ab1077..a4c0350e 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -8,7 +8,7 @@ import ( "github.com/docker/libnetwork/discoverapi" "github.com/docker/libnetwork/netlabel" "github.com/weaveworks/weave/api" - . "github.com/weaveworks/weave/common" + "github.com/weaveworks/weave/common" ) type Ipam struct { @@ -20,13 +20,13 @@ func NewIpam(weave *api.Client) *Ipam { } func (i *Ipam) GetDefaultAddressSpaces() (string, string, error) { - Log.Debugln("GetDefaultAddressSpaces") + i.logReq("GetDefaultAddressSpaces") return "weavelocal", "weaveglobal", nil } func (i *Ipam) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (poolname string, subnet *net.IPNet, data map[string]string, err error) { - Log.Debugln("RequestPool", addressSpace, pool, subPool, options) - defer func() { Log.Debugln("RequestPool returning", poolname, subnet, data, err) }() + i.logReq("RequestPool", addressSpace, pool, subPool, options) + defer func() { i.logRes("RequestPool", poolname, subnet, data, err) }() if pool == "" { subnet, err = i.weave.DefaultSubnet() } else { @@ -50,13 +50,13 @@ func (i *Ipam) RequestPool(addressSpace, pool, subPool string, options map[strin } func (i *Ipam) ReleasePool(poolID string) error { - Log.Debugln("ReleasePool", poolID) + i.logReq("ReleasePool", poolID) return nil } func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]string) (ip *net.IPNet, _ map[string]string, err error) { - Log.Debugln("RequestAddress", poolID, address, options) - defer func() { Log.Debugln("allocateIP returned", ip, err) }() + i.logReq("RequestAddress", poolID, address, options) + defer func() { i.logRes("RequestAddress", ip, err) }() // If we pass magic string "_" to weave IPAM it stores the address under its own string if poolID == "weavepool" { // old-style ip, err = i.weave.AllocateIP("_") @@ -90,7 +90,7 @@ func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string] } func (i *Ipam) ReleaseAddress(poolID string, address net.IP) error { - Log.Debugln("ReleaseAddress", poolID, address) + i.logReq("ReleaseAddress", poolID, address) return i.weave.ReleaseIPsFor(address.String()) } @@ -103,3 +103,13 @@ func (i *Ipam) DiscoverNew(discoverapi.DiscoveryType, interface{}) error { func (i *Ipam) DiscoverDelete(discoverapi.DiscoveryType, interface{}) error { return nil } + +// logging + +func (i *Ipam) logReq(fun string, args ...interface{}) { + common.Log.Debugln(append([]interface{}{fmt.Sprintf("[ipam] %s", fun)}, args...)...) +} + +func (i *Ipam) logRes(fun string, args ...interface{}) { + common.Log.Debugln(append([]interface{}{fmt.Sprintf("[ipam] %s result", fun)}, args...)...) +}