From 4482d307bf9f79c8d9c4c66864a7e2d35835247f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Mar 2016 17:16:03 +0000 Subject: [PATCH] tweak ipam plugin logging - log requests at info level instead of debug level - log errors at error level instead of debug level --- plugin/ipam/driver.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugin/ipam/driver.go b/plugin/ipam/driver.go index a4c0350e..60b25471 100644 --- a/plugin/ipam/driver.go +++ b/plugin/ipam/driver.go @@ -26,7 +26,7 @@ func (i *Ipam) GetDefaultAddressSpaces() (string, string, error) { 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) { i.logReq("RequestPool", addressSpace, pool, subPool, options) - defer func() { i.logRes("RequestPool", poolname, subnet, data, err) }() + defer func() { i.logRes("RequestPool", err, poolname, subnet, data) }() if pool == "" { subnet, err = i.weave.DefaultSubnet() } else { @@ -56,7 +56,7 @@ func (i *Ipam) ReleasePool(poolID string) error { func (i *Ipam) RequestAddress(poolID string, address net.IP, options map[string]string) (ip *net.IPNet, _ map[string]string, err error) { i.logReq("RequestAddress", poolID, address, options) - defer func() { i.logRes("RequestAddress", ip, err) }() + defer func() { i.logRes("RequestAddress", err, ip) }() // 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("_") @@ -107,9 +107,13 @@ func (i *Ipam) DiscoverDelete(discoverapi.DiscoveryType, interface{}) error { // logging func (i *Ipam) logReq(fun string, args ...interface{}) { - common.Log.Debugln(append([]interface{}{fmt.Sprintf("[ipam] %s", fun)}, args...)...) + common.Log.Infoln(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...)...) +func (i *Ipam) logRes(fun string, err error, args ...interface{}) { + if err == nil { + common.Log.Debugln(append([]interface{}{fmt.Sprintf("[ipam] %s result", fun)}, args...)...) + return + } + common.Log.Errorf("[ipam] %s: %s", fun, err) }