From c48eefa82d67145c0042959dfe4adfefb26cee58 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 18 Mar 2016 16:47:47 +0000 Subject: [PATCH] refactor(ish): extract allocator logging commonality and add warnf --- ipam/allocator.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index 196bccae..79229c03 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -934,14 +934,20 @@ func (alloc *Allocator) syncOwned(ids map[string]struct{}) { // Logging func (alloc *Allocator) fatalf(fmt string, args ...interface{}) { - common.Log.Fatalf("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...) + alloc.logf(common.Log.Fatalf, fmt, args...) +} +func (alloc *Allocator) warnf(fmt string, args ...interface{}) { + alloc.logf(common.Log.Warnf, fmt, args...) } func (alloc *Allocator) infof(fmt string, args ...interface{}) { - common.Log.Infof("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...) + alloc.logf(common.Log.Infof, fmt, args...) +} +func (alloc *Allocator) debugf(fmt string, args ...interface{}) { + alloc.logf(common.Log.Debugf, fmt, args...) +} +func (alloc *Allocator) logf(f func(string, ...interface{}), fmt string, args ...interface{}) { + f("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...) } func (alloc *Allocator) debugln(args ...interface{}) { common.Log.Debugln(append([]interface{}{fmt.Sprintf("[allocator %s]:", alloc.ourName)}, args...)...) } -func (alloc *Allocator) debugf(fmt string, args ...interface{}) { - common.Log.Debugf("[allocator %s] "+fmt, append([]interface{}{alloc.ourName}, args...)...) -}