diff --git a/common/docker/client.go b/common/docker/client.go index e5526a6e..71cdf316 100644 --- a/common/docker/client.go +++ b/common/docker/client.go @@ -36,7 +36,7 @@ func NewClient(apiPath string) (*Client, error) { if err != nil { return nil, err } - Info.Printf("[docker] Using Docker API on %s: %v", apiPath, env) + Log.Infof("[docker] Using Docker API on %s: %v", apiPath, env) return client, nil } diff --git a/common/logging.go b/common/logging.go index daf144e0..e2ef9d1a 100644 --- a/common/logging.go +++ b/common/logging.go @@ -38,21 +38,19 @@ var ( ) var ( - Log *logrus.Logger - Info *logrus.Logger + Log *logrus.Logger ) func InitLogging(level logrus.Level) { - if Info == nil { - Info = &logrus.Logger{ + if Log == nil { + Log = &logrus.Logger{ Out: os.Stderr, Formatter: standardTextFormatter, Hooks: make(logrus.LevelHooks), Level: level, } - Log = Info } - Info.Level = level + Log.Level = level } func InitDefaultLogging(debug bool) { diff --git a/common/sched_queue_test.go b/common/sched_queue_test.go index 54a89430..5c733355 100644 --- a/common/sched_queue_test.go +++ b/common/sched_queue_test.go @@ -11,7 +11,7 @@ import ( // Ensure we can add new calls while forwarding the clock func TestSchedCallsBasic(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestSchedCallsBasic starting") + Log.Infoln("TestSchedCallsBasic starting") const testSecs = 1000 clk := clock.NewMock() @@ -37,7 +37,7 @@ func TestSchedCallsBasic(t *testing.T) { // Ensure we can create a 100 seconds gap in the middle of the time travel func TestSchedCallsGap(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestSchedCallsGap starting") + Log.Infoln("TestSchedCallsGap starting") const testSecs = 1000 clk := clock.NewMock() @@ -65,7 +65,7 @@ func TestSchedCallsGap(t *testing.T) { func TestSchedCallsStop(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestSchedCallsStop starting") + Log.Infoln("TestSchedCallsStop starting") const testSecs = 1000 clk := clock.NewMock() diff --git a/common/signals.go b/common/signals.go index f92f3f60..e750a8ea 100644 --- a/common/signals.go +++ b/common/signals.go @@ -20,17 +20,17 @@ func SignalHandlerLoop(ss ...SignalReceiver) { for { switch <-sigs { case syscall.SIGINT: - Info.Printf("=== received SIGINT ===\n*** exiting\n") + Log.Infof("=== received SIGINT ===\n*** exiting\n") for _, subsystem := range ss { subsystem.Stop() } return case syscall.SIGQUIT: stacklen := runtime.Stack(buf, true) - Info.Printf("=== received SIGQUIT ===\n*** goroutine dump...\n%s\n*** end\n", buf[:stacklen]) + Log.Infof("=== received SIGQUIT ===\n*** goroutine dump...\n%s\n*** end\n", buf[:stacklen]) case syscall.SIGUSR1: for _, subsystem := range ss { - Info.Printf("=== received SIGUSR1 ===\n*** status...\n%s\n*** end\n", subsystem.Status()) + Log.Infof("=== received SIGUSR1 ===\n*** status...\n%s\n*** end\n", subsystem.Status()) } } } diff --git a/ipam/allocator_test.go b/ipam/allocator_test.go index 2176f643..fcd3027a 100644 --- a/ipam/allocator_test.go +++ b/ipam/allocator_test.go @@ -343,14 +343,14 @@ func TestAllocatorFuzz(t *testing.T) { allocIndex := rand.Int31n(nodes) alloc := allocs[allocIndex] - //common.Info.Printf("Allocate: asking allocator %d", allocIndex) + //common.Log.Infof("Allocate: asking allocator %d", allocIndex) addr, err := alloc.Allocate(name, subnet, nil) if err != nil { panic(fmt.Sprintf("Could not allocate addr")) } - //common.Info.Printf("Allocate: got address %s for name %s", addr, name) + //common.Log.Infof("Allocate: got address %s for name %s", addr, name) addrStr := addr.String() stateLock.Lock() @@ -387,7 +387,7 @@ func TestAllocatorFuzz(t *testing.T) { stateLock.Unlock() alloc := allocs[res.alloc] - //common.Info.Printf("Freeing %s (%s) on allocator %d", res.name, addr, res.alloc) + //common.Log.Infof("Freeing %s (%s) on allocator %d", res.name, addr, res.alloc) oldAddr, err := address.ParseIP(addr) if err != nil { @@ -412,7 +412,7 @@ func TestAllocatorFuzz(t *testing.T) { stateLock.Unlock() alloc := allocs[res.alloc] - //common.Info.Printf("Asking for %s (%s) on allocator %d again", res.name, addr, res.alloc) + //common.Log.Infof("Asking for %s (%s) on allocator %d again", res.name, addr, res.alloc) newAddr, _ := alloc.Allocate(res.name, subnet, nil) oldAddr, _ := address.ParseIP(addr) diff --git a/ipam/http.go b/ipam/http.go index 4218744c..0b665385 100644 --- a/ipam/http.go +++ b/ipam/http.go @@ -79,7 +79,7 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CID return } if dockerCli != nil && dockerCli.IsContainerNotRunning(ident) { - common.Info.Printf("[allocator] '%s' is not running: freeing %s", ident, addr) + common.Log.Infof("[allocator] '%s' is not running: freeing %s", ident, addr) alloc.Free(ident, addr) return } @@ -96,7 +96,7 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CID return } if dockerCli != nil && dockerCli.IsContainerNotRunning(ident) { - common.Info.Printf("[allocator] '%s' is not running: freeing %s", ident, newAddr) + common.Log.Infof("[allocator] '%s' is not running: freeing %s", ident, newAddr) alloc.Free(ident, newAddr) return } diff --git a/nameserver/addrs_test.go b/nameserver/addrs_test.go index 81392cdc..2118832b 100644 --- a/nameserver/addrs_test.go +++ b/nameserver/addrs_test.go @@ -10,7 +10,7 @@ import ( func TestAddrs(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestAddrs starting") + Log.Infoln("TestAddrs starting") ip, err := addrToIPv4("10.13.12.11") require.NoError(t, err) diff --git a/nameserver/cache_test.go b/nameserver/cache_test.go index 8b467488..f3a14cb0 100644 --- a/nameserver/cache_test.go +++ b/nameserver/cache_test.go @@ -15,7 +15,7 @@ import ( // Check that the cache keeps its intended capacity constant func TestCacheLength(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestCacheLength starting") + Log.Infoln("TestCacheLength starting") const cacheLen = 128 @@ -56,9 +56,9 @@ func TestCacheLength(t *testing.T) { // Check that the cache entries are ok func TestCacheEntries(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestCacheEntries starting") + Log.Infoln("TestCacheEntries starting") - Info.Println("Checking cache consistency") + Log.Infoln("Checking cache consistency") const cacheLen = 128 clk := clock.NewMock() diff --git a/nameserver/dns_test.go b/nameserver/dns_test.go index 3c46da41..1ec25147 100644 --- a/nameserver/dns_test.go +++ b/nameserver/dns_test.go @@ -12,7 +12,7 @@ import ( // Check that we can prune an answer func TestPrune(t *testing.T) { InitDefaultLogging(testing.Verbose()) - Info.Println("TestPrune starting") + Log.Infoln("TestPrune starting") questionMsg := new(dns.Msg) questionMsg.SetQuestion("name", dns.TypeA) diff --git a/nameserver/http.go b/nameserver/http.go index 3de340bc..42dd3231 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -61,10 +61,10 @@ func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerC domain := server.Zone.Domain() if !dns.IsSubDomain(domain, name) { - Info.Printf("[http] Ignoring name %s, not in %s", name, domain) + Log.Infof("[http] Ignoring name %s, not in %s", name, domain) return } - Info.Printf("[http] Adding %s -> %s", name, ipStr) + Log.Infof("[http] Adding %s -> %s", name, ipStr) if err := server.Zone.AddRecord(idStr, name, ip); err != nil { if _, ok := err.(DuplicateError); !ok { httpErrorAndLog( @@ -75,7 +75,7 @@ func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerC } if dockerCli != nil && dockerCli.IsContainerNotRunning(idStr) { - Info.Printf("[http] '%s' is not running: removing", idStr) + Log.Infof("[http] '%s' is not running: removing", idStr) server.Zone.DeleteRecords(idStr, name, ip) } }) @@ -95,7 +95,7 @@ func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerC fqdnStr, fqdn := extractFQDN(r) - Info.Printf("[http] Deleting ID %s, IP %s, FQDN %s", idStr, ipStr, fqdnStr) + Log.Infof("[http] Deleting ID %s, IP %s, FQDN %s", idStr, ipStr, fqdnStr) server.Zone.DeleteRecords(idStr, fqdn, ip) }) @@ -105,14 +105,14 @@ func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerC fqdnStr, fqdn := extractFQDN(r) - Info.Printf("[http] Deleting ID %s, IP *, FQDN %s", idStr, fqdnStr) + Log.Infof("[http] Deleting ID %s, IP *, FQDN %s", idStr, fqdnStr) server.Zone.DeleteRecords(idStr, fqdn, net.IP{}) }) muxRouter.Methods("DELETE").Path("/name").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fqdnStr, fqdn := extractFQDN(r) - Info.Printf("[http] Deleting ID *, IP *, FQDN %s", fqdnStr) + Log.Infof("[http] Deleting ID *, IP *, FQDN %s", fqdnStr) server.Zone.DeleteRecords("", fqdn, net.IP{}) }) diff --git a/nameserver/mdns_server_test.go b/nameserver/mdns_server_test.go index 7f94e5de..3fe89fe0 100644 --- a/nameserver/mdns_server_test.go +++ b/nameserver/mdns_server_test.go @@ -18,7 +18,7 @@ func TestServerSimpleQuery(t *testing.T) { ) InitDefaultLogging(testing.Verbose()) - Info.Println("TestServerSimpleQuery starting") + Log.Infoln("TestServerSimpleQuery starting") mzone := newMockedZoneWithRecords([]ZoneRecord{testRecord1, testRecord2}) mdnsServer, err := NewMDNSServer(mzone, true, DefaultLocalTTL) diff --git a/nameserver/server.go b/nameserver/server.go index a8955138..6f36aaf4 100644 --- a/nameserver/server.go +++ b/nameserver/server.go @@ -188,11 +188,11 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) { // Start the DNS server func (s *DNSServer) Start() error { - Info.Printf("[dns] Upstream server(s): %+v", s.Upstream) + Log.Infof("[dns] Upstream server(s): %+v", s.Upstream) if s.cacheDisabled { - Info.Printf("[dns] Cache: disabled") + Log.Infof("[dns] Cache: disabled") } else { - Info.Printf("[dns] Cache: %d entries", s.cache.Capacity()) + Log.Infof("[dns] Cache: %d entries", s.cache.Capacity()) } pc, err := net.ListenPacket("udp", s.ListenAddr) @@ -225,7 +225,7 @@ func (s *DNSServer) ActivateAndServe() { go func() { defer s.listenersWg.Done() - Info.Printf("[dns] Listening for DNS on %s (UDP)", s.ListenAddr) + Log.Infof("[dns] Listening for DNS on %s (UDP)", s.ListenAddr) err := s.udpSrv.ActivateAndServe() CheckFatal(err) Log.Debugf("[dns] DNS UDP server exiting...") @@ -234,7 +234,7 @@ func (s *DNSServer) ActivateAndServe() { go func() { defer s.listenersWg.Done() - Info.Printf("[dns] Listening for DNS on %s (TCP)", s.ListenAddr) + Log.Infof("[dns] Listening for DNS on %s (TCP)", s.ListenAddr) err := s.tcpSrv.ActivateAndServe() CheckFatal(err) Log.Debugf("[dns] DNS TCP server exiting...") @@ -243,7 +243,7 @@ func (s *DNSServer) ActivateAndServe() { // Waiting for all goroutines to finish (otherwise they die as main routine dies) s.listenersWg.Wait() - Info.Printf("[dns] Server exiting...") + Log.Infof("[dns] Server exiting...") } // Return status string @@ -284,7 +284,7 @@ func (s *DNSServer) createMux(proto dnsProtocol) *dns.ServeMux { } notUsHandler := s.notUsHandler(proto) notUsFallback := func(w dns.ResponseWriter, r *dns.Msg) { - Info.Printf("[dns msgid %d] -> sending to fallback server", r.MsgHdr.Id) + Log.Infof("[dns msgid %d] -> sending to fallback server", r.MsgHdr.Id) notUsHandler(w, r) } @@ -351,8 +351,9 @@ func (s *DNSServer) localHandler(proto dnsProtocol, kind string, qtype uint16, } if answers, err := lookup(q.Name); err != nil { - Info.Printf("[dns msgid %d] No results for type %s query for '%s' [caching no-local]", + Log.Infof("[dns msgid %d] No results for type %s query for '%s' [caching no-local]", r.MsgHdr.Id, dns.TypeToString[q.Qtype], q.Name) + maybeCache(nil, s.negLocalTTL, CacheNoLocalReplies) fallback(w, r) } else { diff --git a/nameserver/server_cache_test.go b/nameserver/server_cache_test.go index 8b0d8651..35f3dc82 100644 --- a/nameserver/server_cache_test.go +++ b/nameserver/server_cache_test.go @@ -20,7 +20,7 @@ func TestServerDbCacheInvalidation(t *testing.T) { ) InitDefaultLogging(testing.Verbose()) - Info.Println("TestServerDbCacheInvalidation starting") + Log.Infoln("TestServerDbCacheInvalidation starting") clk := newMockedClock() @@ -178,7 +178,7 @@ func TestServerCacheExpiration(t *testing.T) { ) InitDefaultLogging(testing.Verbose()) - Info.Println("TestServerCacheExpiration starting") + Log.Infoln("TestServerCacheExpiration starting") clk := newMockedClock() @@ -266,7 +266,7 @@ func TestServerCacheRefresh(t *testing.T) { ) InitDefaultLogging(testing.Verbose()) - Info.Println("TestServerCacheRefresh starting") + Log.Infoln("TestServerCacheRefresh starting") clk := newMockedClock() Log.Debugf("Creating 2 zone databases") diff --git a/nameserver/server_test.go b/nameserver/server_test.go index ce1d4a4c..ab19362b 100644 --- a/nameserver/server_test.go +++ b/nameserver/server_test.go @@ -41,7 +41,7 @@ func TestUDPDNSServer(t *testing.T) { testCIDR1 := testAddr1 + "/24" InitDefaultLogging(testing.Verbose()) - Info.Println("TestUDPDNSServer starting") + Log.Infoln("TestUDPDNSServer starting") zone, err := NewZoneDb(ZoneConfig{}) require.NoError(t, err) @@ -138,7 +138,7 @@ func TestTCPDNSServer(t *testing.T) { ) InitDefaultLogging(testing.Verbose()) - Info.Println("TestTCPDNSServer starting") + Log.Infoln("TestTCPDNSServer starting") zone, err := NewZoneDb(ZoneConfig{}) require.NoError(t, err) diff --git a/nameserver/zone.go b/nameserver/zone.go index 98fc76a0..e6598932 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -506,9 +506,9 @@ func NewZoneDb(config ZoneConfig) (zone *ZoneDb, err error) { // Start the zone database func (zone *ZoneDb) Start() (err error) { if zone.iface != nil { - Info.Printf("[zonedb] Using mDNS on %+v", zone.iface) + Log.Infof("[zonedb] Using mDNS on %+v", zone.iface) } else { - Info.Printf("[zonedb] Using mDNS on all interfaces") + Log.Infof("[zonedb] Using mDNS on all interfaces") } if err = zone.mdnsCli.Start(zone.iface); err != nil { @@ -638,7 +638,7 @@ func (zone *ZoneDb) String() string { // Notify that a container has died func (zone *ZoneDb) ContainerDied(ident string) error { - Info.Printf("[zonedb] Container %s down. Removing records", ident) + Log.Infof("[zonedb] Container %s down. Removing records", ident) zone.DeleteRecords(ident, "", net.IP{}) return nil } diff --git a/nameserver/zone_lookup_test.go b/nameserver/zone_lookup_test.go index eb48488e..5f86f34c 100644 --- a/nameserver/zone_lookup_test.go +++ b/nameserver/zone_lookup_test.go @@ -24,7 +24,7 @@ func TestZoneRefresh(t *testing.T) { ) InitDefaultLogging(testing.Verbose()) - Info.Println("TestZoneRefresh starting") + Log.Infoln("TestZoneRefresh starting") clk := newMockedClock() diff --git a/prog/weavedns/main.go b/prog/weavedns/main.go index dea87bc0..36763bc8 100644 --- a/prog/weavedns/main.go +++ b/prog/weavedns/main.go @@ -71,17 +71,17 @@ func main() { } InitDefaultLogging(debug) - Info.Printf("[main] WeaveDNS version %s\n", version) // first thing in log: the version + Log.Infof("[main] WeaveDNS version %s\n", version) // first thing in log: the version var iface *net.Interface if ifaceName != "" { var err error - Info.Println("[main] Waiting for mDNS interface", ifaceName, "to come up") + Log.Infoln("[main] Waiting for mDNS interface", ifaceName, "to come up") iface, err = weavenet.EnsureInterface(ifaceName, wait) if err != nil { Log.Fatal(err) } else { - Info.Println("[main] Interface", ifaceName, "is up") + Log.Infoln("[main] Interface", ifaceName, "is up") } } @@ -89,12 +89,12 @@ func main() { if httpIfaceName == "" { httpIP = "0.0.0.0" } else { - Info.Println("[main] Waiting for HTTP interface", httpIfaceName, "to come up") + Log.Infoln("[main] Waiting for HTTP interface", httpIfaceName, "to come up") httpIface, err := weavenet.EnsureInterface(httpIfaceName, wait) if err != nil { Log.Fatal(err) } - Info.Println("[main] Interface", httpIfaceName, "is up") + Log.Infoln("[main] Interface", httpIfaceName, "is up") addrs, err := httpIface.Addrs() if err != nil { @@ -173,7 +173,7 @@ func main() { if err != nil { Log.Fatal("[main] Unable to create http listener: ", err) } - Info.Println("[main] HTTP API listening on", httpAddr) + Log.Infoln("[main] HTTP API listening on", httpAddr) go SignalHandlerLoop(srv) go weavedns.ServeHTTP(httpListener, version, srv, dockerCli) diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index 6eecfa21..d4fdfcd8 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -50,8 +50,8 @@ func main() { InitDefaultLogging(true) } - Info.Println("weave proxy", version) - Info.Println("Command line arguments:", strings.Join(os.Args[1:], " ")) + Log.Infoln("weave proxy", version) + Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " ")) p, err := proxy.NewProxy(c) if err != nil { diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 69f5815b..66f9f1f5 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -45,7 +45,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { } if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config); ok { - Info.Printf("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " ")) + Log.Infof("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " ")) if container.HostConfig == nil { container.HostConfig = &docker.HostConfig{} } diff --git a/proxy/create_exec_interceptor.go b/proxy/create_exec_interceptor.go index 72e62730..5414346e 100644 --- a/proxy/create_exec_interceptor.go +++ b/proxy/create_exec_interceptor.go @@ -30,7 +30,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { } if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config); ok { - Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) + Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) cmd := append(weaveWaitEntrypoint, "-s") options.Cmd = append(cmd, options.Cmd...) } diff --git a/proxy/proxy.go b/proxy/proxy.go index 07be6faf..0812ab4b 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -72,7 +72,7 @@ func (proxy *Proxy) Dial() (net.Conn, error) { } func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { - Info.Printf("%s %s", r.Method, r.URL) + Log.Infof("%s %s", r.Method, r.URL) path := r.URL.Path var i interceptor switch { @@ -101,7 +101,7 @@ func (proxy *Proxy) ListenAndServe() { } for _, addr := range addrs { - Info.Println("proxy listening on", addr) + Log.Infoln("proxy listening on", addr) } errs := make(chan error) diff --git a/proxy/start_container_interceptor.go b/proxy/start_container_interceptor.go index 4d092512..b7da0505 100644 --- a/proxy/start_container_interceptor.go +++ b/proxy/start_container_interceptor.go @@ -26,7 +26,7 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error { Log.Debug("No Weave CIDR, ignoring") return nil } - Info.Printf("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " ")) + Log.Infof("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " ")) args := []string{"attach"} args = append(args, cidrs...) args = append(args, "--or-die", container.ID)