Merge pull request #1057 from weaveworks/329-log-level-choice

Give the user more choice of log levels

Closes #329
This commit is contained in:
Matthias Radestock committed 2015-07-04 03:46:59 +01:00
commit cf4fffa394
20 files changed
+52 -57

No files matched your search

-5
View File
@@ -1,5 +0,0 @@
package common
func init() {
InitDefaultLogging(false)
}
+19 -13
View File
@@ -41,22 +41,28 @@ var (
Log *logrus.Logger Log *logrus.Logger
) )
func InitLogging(level logrus.Level) { func init() {
if Log == nil { Log = &logrus.Logger{
Log = &logrus.Logger{ Out: os.Stderr,
Out: os.Stderr, Formatter: standardTextFormatter,
Formatter: standardTextFormatter, Hooks: make(logrus.LevelHooks),
Hooks: make(logrus.LevelHooks), }
Level: level, }
}
func SetLogLevel(levelname string) {
level, err := logrus.ParseLevel(levelname)
if err != nil {
Log.Fatal(err)
} }
Log.Level = level Log.Level = level
} }
func InitDefaultLogging(debug bool) { // For backwards-compatibility with code that only has a boolean
level := logrus.InfoLevel func EnableDebugLogging(flag bool) {
if debug { switch {
level = logrus.DebugLevel case flag && Log.Level < logrus.DebugLevel:
Log.Level = logrus.DebugLevel
case !flag && Log.Level >= logrus.DebugLevel:
Log.Level = logrus.InfoLevel
} }
InitLogging(level)
} }
+3 -3
View File
@@ -10,7 +10,7 @@ import (
// Ensure we can add new calls while forwarding the clock // Ensure we can add new calls while forwarding the clock
func TestSchedCallsBasic(t *testing.T) { func TestSchedCallsBasic(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestSchedCallsBasic starting") Log.Infoln("TestSchedCallsBasic starting")
const testSecs = 1000 const testSecs = 1000
@@ -36,7 +36,7 @@ func TestSchedCallsBasic(t *testing.T) {
// Ensure we can create a 100 seconds gap in the middle of the time travel // Ensure we can create a 100 seconds gap in the middle of the time travel
func TestSchedCallsGap(t *testing.T) { func TestSchedCallsGap(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestSchedCallsGap starting") Log.Infoln("TestSchedCallsGap starting")
const testSecs = 1000 const testSecs = 1000
@@ -64,7 +64,7 @@ func TestSchedCallsGap(t *testing.T) {
} }
func TestSchedCallsStop(t *testing.T) { func TestSchedCallsStop(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestSchedCallsStop starting") Log.Infoln("TestSchedCallsStop starting")
const testSecs = 1000 const testSecs = 1000
-4
View File
@@ -71,7 +71,6 @@ func TestAllocFree(t *testing.T) {
} }
func TestBootstrap(t *testing.T) { func TestBootstrap(t *testing.T) {
common.InitDefaultLogging(false)
const ( const (
donateSize = 5 donateSize = 5
donateStart = "10.0.1.7" donateStart = "10.0.1.7"
@@ -163,7 +162,6 @@ func (alloc *Allocator) pause() func() {
} }
func TestCancel(t *testing.T) { func TestCancel(t *testing.T) {
common.InitDefaultLogging(false)
const ( const (
CIDR = "10.0.1.7/26" CIDR = "10.0.1.7/26"
) )
@@ -276,7 +274,6 @@ func TestTransfer(t *testing.T) {
} }
func TestFakeRouterSimple(t *testing.T) { func TestFakeRouterSimple(t *testing.T) {
common.InitDefaultLogging(false)
const ( const (
cidr = "10.0.1.7/22" cidr = "10.0.1.7/22"
) )
@@ -291,7 +288,6 @@ func TestFakeRouterSimple(t *testing.T) {
} }
func TestAllocatorFuzz(t *testing.T) { func TestAllocatorFuzz(t *testing.T) {
common.InitDefaultLogging(false)
const ( const (
firstpass = 1000 firstpass = 1000
secondpass = 20000 secondpass = 20000
-1
View File
@@ -151,7 +151,6 @@ func TestHTTPCancel(t *testing.T) {
} }
func impTestHTTPCancel(t *testing.T) { func impTestHTTPCancel(t *testing.T) {
common.InitDefaultLogging(true)
var ( var (
containerID = "deadbeef" containerID = "deadbeef"
testCIDR1 = "10.0.3.0/29" testCIDR1 = "10.0.3.0/29"
+1 -1
View File
@@ -9,7 +9,7 @@ import (
) )
func TestAddrs(t *testing.T) { func TestAddrs(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestAddrs starting") Log.Infoln("TestAddrs starting")
ip, err := addrToIPv4("10.13.12.11") ip, err := addrToIPv4("10.13.12.11")
+2 -2
View File
@@ -14,7 +14,7 @@ import (
// Check that the cache keeps its intended capacity constant // Check that the cache keeps its intended capacity constant
func TestCacheLength(t *testing.T) { func TestCacheLength(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestCacheLength starting") Log.Infoln("TestCacheLength starting")
const cacheLen = 128 const cacheLen = 128
@@ -55,7 +55,7 @@ func TestCacheLength(t *testing.T) {
// Check that the cache entries are ok // Check that the cache entries are ok
func TestCacheEntries(t *testing.T) { func TestCacheEntries(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestCacheEntries starting") Log.Infoln("TestCacheEntries starting")
Log.Infoln("Checking cache consistency") Log.Infoln("Checking cache consistency")
+1 -1
View File
@@ -11,7 +11,7 @@ import (
// Check that we can prune an answer // Check that we can prune an answer
func TestPrune(t *testing.T) { func TestPrune(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestPrune starting") Log.Infoln("TestPrune starting")
questionMsg := new(dns.Msg) questionMsg := new(dns.Msg)
+1 -1
View File
@@ -78,7 +78,7 @@ func RunLocalMulticastServer() (*dns.Server, error) {
} }
func setup(t *testing.T) (*MDNSClient, *dns.Server, error) { func setup(t *testing.T) (*MDNSClient, *dns.Server, error) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
server, err := RunLocalMulticastServer() server, err := RunLocalMulticastServer()
if err != nil { if err != nil {
+1 -1
View File
@@ -17,7 +17,7 @@ func TestServerSimpleQuery(t *testing.T) {
testInAddr1 = "10.20.20.10.in-addr.arpa." testInAddr1 = "10.20.20.10.in-addr.arpa."
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestServerSimpleQuery starting") Log.Infoln("TestServerSimpleQuery starting")
mzone := newMockedZoneWithRecords([]ZoneRecord{testRecord1, testRecord2}) mzone := newMockedZoneWithRecords([]ZoneRecord{testRecord1, testRecord2})
+2 -2
View File
@@ -12,7 +12,7 @@ import (
// Check that we can use a regular mDNS server with a regular mDNS client // Check that we can use a regular mDNS server with a regular mDNS client
func TestClientServerSimpleQuery(t *testing.T) { func TestClientServerSimpleQuery(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
testRecord1 := Record{"test.weave.local.", net.ParseIP("10.2.2.1"), 0, 0, 0} testRecord1 := Record{"test.weave.local.", net.ParseIP("10.2.2.1"), 0, 0, 0}
testInAddr1 := "1.2.2.10.in-addr.arpa." testInAddr1 := "1.2.2.10.in-addr.arpa."
@@ -86,7 +86,7 @@ func TestClientServerSimpleQuery(t *testing.T) {
// Check that we can use a use "insistent" queries // Check that we can use a use "insistent" queries
func TestClientServerInsistentQuery(t *testing.T) { func TestClientServerInsistentQuery(t *testing.T) {
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
testRecord1 := Record{"test.weave.local.", net.ParseIP("10.2.2.1"), 0, 0, 0} testRecord1 := Record{"test.weave.local.", net.ParseIP("10.2.2.1"), 0, 0, 0}
testInAddr1 := "1.2.2.10.in-addr.arpa." testInAddr1 := "1.2.2.10.in-addr.arpa."
+3 -3
View File
@@ -19,7 +19,7 @@ func TestServerDbCacheInvalidation(t *testing.T) {
testName2 = "second.weave.local." testName2 = "second.weave.local."
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestServerDbCacheInvalidation starting") Log.Infoln("TestServerDbCacheInvalidation starting")
clk := newMockedClock() clk := newMockedClock()
@@ -177,7 +177,7 @@ func TestServerCacheExpiration(t *testing.T) {
negativeLocalTTL = 10 negativeLocalTTL = 10
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestServerCacheExpiration starting") Log.Infoln("TestServerCacheExpiration starting")
clk := newMockedClock() clk := newMockedClock()
@@ -265,7 +265,7 @@ func TestServerCacheRefresh(t *testing.T) {
refreshInterval = int(DefaultLocalTTL) / 3 refreshInterval = int(DefaultLocalTTL) / 3
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestServerCacheRefresh starting") Log.Infoln("TestServerCacheRefresh starting")
clk := newMockedClock() clk := newMockedClock()
+2 -2
View File
@@ -40,7 +40,7 @@ func TestUDPDNSServer(t *testing.T) {
) )
testCIDR1 := testAddr1 + "/24" testCIDR1 := testAddr1 + "/24"
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestUDPDNSServer starting") Log.Infoln("TestUDPDNSServer starting")
zone, err := NewZoneDb(ZoneConfig{}) zone, err := NewZoneDb(ZoneConfig{})
@@ -137,7 +137,7 @@ func TestTCPDNSServer(t *testing.T) {
nonLocalName = "weave.works." nonLocalName = "weave.works."
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestTCPDNSServer starting") Log.Infoln("TestTCPDNSServer starting")
zone, err := NewZoneDb(ZoneConfig{}) zone, err := NewZoneDb(ZoneConfig{})
+1 -1
View File
@@ -23,7 +23,7 @@ func TestZoneRefresh(t *testing.T) {
addr4 = "10.2.8.7" addr4 = "10.2.8.7"
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
Log.Infoln("TestZoneRefresh starting") Log.Infoln("TestZoneRefresh starting")
clk := newMockedClock() clk := newMockedClock()
+2 -2
View File
@@ -20,7 +20,7 @@ func TestZone(t *testing.T) {
revName1Addr1 = "1.2.9.10.in-addr.arpa." revName1Addr1 = "1.2.9.10.in-addr.arpa."
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
zone, err := NewZoneDb(ZoneConfig{}) zone, err := NewZoneDb(ZoneConfig{})
require.NoError(t, err) require.NoError(t, err)
@@ -136,7 +136,7 @@ func TestDeleteRecords(t *testing.T) {
addr2 = "10.2.7.8/24" addr2 = "10.2.7.8/24"
) )
InitDefaultLogging(testing.Verbose()) EnableDebugLogging(testing.Verbose())
zone, err := NewZoneDb(ZoneConfig{}) zone, err := NewZoneDb(ZoneConfig{})
require.NoError(t, err) require.NoError(t, err)
+3 -3
View File
@@ -38,7 +38,7 @@ func main() {
cacheLen int cacheLen int
cacheDisabled bool cacheDisabled bool
watch bool watch bool
debug bool logLevel string
err error err error
) )
@@ -53,7 +53,7 @@ func main() {
flag.IntVar(&cacheLen, "cache", weavedns.DefaultCacheLen, "cache length") flag.IntVar(&cacheLen, "cache", weavedns.DefaultCacheLen, "cache length")
flag.IntVar(&ttl, "ttl", weavedns.DefaultLocalTTL, "TTL (in secs) for responses for local names") flag.IntVar(&ttl, "ttl", weavedns.DefaultLocalTTL, "TTL (in secs) for responses for local names")
flag.BoolVar(&watch, "watch", true, "watch the docker socket for container events") flag.BoolVar(&watch, "watch", true, "watch the docker socket for container events")
flag.BoolVar(&debug, "debug", false, "output debugging info to stderr") flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
// advanced options // advanced options
flag.IntVar(&negTTL, "neg-ttl", 0, "negative TTL (in secs) for unanswered queries for local names (0=same value as -ttl") flag.IntVar(&negTTL, "neg-ttl", 0, "negative TTL (in secs) for unanswered queries for local names (0=same value as -ttl")
flag.IntVar(&refreshInterval, "refresh", weavedns.DefaultRefreshInterval, "refresh interval (in secs) for local names (0=disable)") flag.IntVar(&refreshInterval, "refresh", weavedns.DefaultRefreshInterval, "refresh interval (in secs) for local names (0=disable)")
@@ -70,7 +70,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
InitDefaultLogging(debug) SetLogLevel(logLevel)
Log.Infof("[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 var iface *net.Interface
+3 -5
View File
@@ -17,14 +17,14 @@ var (
func main() { func main() {
var ( var (
debug bool
justVersion bool justVersion bool
logLevel = "info"
c = proxy.Config{ListenAddrs: defaultListenAddrs} c = proxy.Config{ListenAddrs: defaultListenAddrs}
) )
c.Version = version c.Version = version
getopt.BoolVarLong(&debug, "debug", 'd', "log debugging information")
getopt.BoolVarLong(&justVersion, "version", 0, "print version and exit") getopt.BoolVarLong(&justVersion, "version", 0, "print version and exit")
getopt.StringVarLong(&logLevel, "log-level", 0, "logging level (debug, info, warning, error)", "info")
getopt.ListVar(&c.ListenAddrs, 'H', fmt.Sprintf("address on which to listen (default %s)", defaultListenAddrs)) getopt.ListVar(&c.ListenAddrs, 'H', fmt.Sprintf("address on which to listen (default %s)", defaultListenAddrs))
getopt.BoolVarLong(&c.NoDefaultIPAM, "no-default-ipalloc", 0, "do not automatically allocate addresses for containers without a WEAVE_CIDR") getopt.BoolVarLong(&c.NoDefaultIPAM, "no-default-ipalloc", 0, "do not automatically allocate addresses for containers without a WEAVE_CIDR")
getopt.BoolVarLong(&c.NoDefaultIPAM, "no-default-ipam", 0, "do not automatically allocate addresses for containers without a WEAVE_CIDR (deprecated; please use --no-default-ipalloc") getopt.BoolVarLong(&c.NoDefaultIPAM, "no-default-ipam", 0, "do not automatically allocate addresses for containers without a WEAVE_CIDR (deprecated; please use --no-default-ipalloc")
@@ -46,9 +46,7 @@ func main() {
Log.Fatalf("Cannot use both '--with-dns' and '--without-dns' flags") Log.Fatalf("Cannot use both '--with-dns' and '--without-dns' flags")
} }
if debug { SetLogLevel(logLevel)
InitDefaultLogging(true)
}
Log.Infoln("weave proxy", version) Log.Infoln("weave proxy", version)
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " ")) Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
+3 -3
View File
@@ -39,8 +39,8 @@ func main() {
nickName string nickName string
password string password string
wait int wait int
debug bool
pktdebug bool pktdebug bool
logLevel string
prof string prof string
bufSzMB int bufSzMB int
noDiscovery bool noDiscovery bool
@@ -59,7 +59,7 @@ func main() {
flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)") flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)")
flag.StringVar(&password, "password", "", "network password") flag.StringVar(&password, "password", "", "network password")
flag.IntVar(&wait, "wait", -1, "number of seconds to wait for interface to come up (0=don't wait, -1=wait forever)") flag.IntVar(&wait, "wait", -1, "number of seconds to wait for interface to come up (0=don't wait, -1=wait forever)")
flag.BoolVar(&debug, "debug", false, "enable debug logging") flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
flag.BoolVar(&pktdebug, "pktdebug", false, "enable per-packet debug logging") flag.BoolVar(&pktdebug, "pktdebug", false, "enable per-packet debug logging")
flag.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path") flag.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path")
flag.IntVar(&config.ConnLimit, "connlimit", 30, "connection limit (0 for unlimited)") flag.IntVar(&config.ConnLimit, "connlimit", 30, "connection limit (0 for unlimited)")
@@ -73,7 +73,7 @@ func main() {
flag.Parse() flag.Parse()
peers = flag.Args() peers = flag.Args()
InitDefaultLogging(debug) SetLogLevel(logLevel)
if justVersion { if justVersion {
fmt.Printf("weave router %s\n", version) fmt.Printf("weave router %s\n", version)
os.Exit(0) os.Exit(0)
+4 -3
View File
@@ -20,9 +20,10 @@ Check the weave container logs with
A reasonable amount of information, and all errors, get logged there. A reasonable amount of information, and all errors, get logged there.
The log verbosity can be increased by supplying the `-debug` flag when The log verbosity can be increased by supplying the
launching weave. To log information on a per-packet basis use `--log-level=debug` option when launching weave. To log information on
`-pktdebug` - be warned, this can produce a lot of output. a per-packet basis use `-pktdebug` - be warned, this can produce a lot
of output.
Another useful debugging technique is to attach standard packet Another useful debugging technique is to attach standard packet
capture and analysis tools, such as tcpdump and wireshark, to the capture and analysis tools, such as tcpdump and wireshark, to the
+1 -1
View File
@@ -43,7 +43,7 @@ CHECK_ETHWE_UP="grep ^1$ /sys/class/net/ethwe/carrier"
DOCKER_PORT=2375 DOCKER_PORT=2375
WEAVEDNS_ARGS="--no-cache" WEAVEDNS_ARGS="--no-cache"
[ -n "$DEBUG" ] && WEAVEDNS_ARGS="$WEAVEDNS_ARGS --debug" [ -n "$DEBUG" ] && WEAVEDNS_ARGS="$WEAVEDNS_ARGS --log-level=debug"
upload_executable() { upload_executable() {