-
Notifications
You must be signed in to change notification settings - Fork 34
/
global_test.go
93 lines (72 loc) · 2.63 KB
/
global_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package loggo_test
import (
gc "gopkg.in/check.v1"
"github.com/juju/loggo/v2"
)
type GlobalSuite struct{}
var _ = gc.Suite(&GlobalSuite{})
func (*GlobalSuite) SetUpTest(c *gc.C) {
loggo.ResetDefaultContext()
}
func (*GlobalSuite) TestRootLogger(c *gc.C) {
var root loggo.Logger
got := loggo.GetLogger("")
c.Check(got.Name(), gc.Equals, root.Name())
c.Check(got.LogLevel(), gc.Equals, root.LogLevel())
}
func (*GlobalSuite) TestModuleName(c *gc.C) {
logger := loggo.GetLogger("loggo.testing")
c.Check(logger.Name(), gc.Equals, "loggo.testing")
}
func (*GlobalSuite) TestLevel(c *gc.C) {
logger := loggo.GetLogger("testing")
level := logger.LogLevel()
c.Check(level, gc.Equals, loggo.UNSPECIFIED)
}
func (*GlobalSuite) TestEffectiveLevel(c *gc.C) {
logger := loggo.GetLogger("testing")
level := logger.EffectiveLogLevel()
c.Check(level, gc.Equals, loggo.WARNING)
}
func (*GlobalSuite) TestLevelsSharedForSameModule(c *gc.C) {
logger1 := loggo.GetLogger("testing.module")
logger2 := loggo.GetLogger("testing.module")
logger1.SetLogLevel(loggo.INFO)
c.Assert(logger1.IsInfoEnabled(), gc.Equals, true)
c.Assert(logger2.IsInfoEnabled(), gc.Equals, true)
}
func (*GlobalSuite) TestModuleLowered(c *gc.C) {
logger1 := loggo.GetLogger("TESTING.MODULE")
logger2 := loggo.GetLogger("Testing")
c.Assert(logger1.Name(), gc.Equals, "testing.module")
c.Assert(logger2.Name(), gc.Equals, "testing")
}
func (s *GlobalSuite) TestConfigureLoggers(c *gc.C) {
err := loggo.ConfigureLoggers("testing.module=debug")
c.Assert(err, gc.IsNil)
expected := "<root>=WARNING;testing.module=DEBUG"
c.Assert(loggo.DefaultContext().Config().String(), gc.Equals, expected)
c.Assert(loggo.LoggerInfo(), gc.Equals, expected)
}
func (*GlobalSuite) TestRegisterWriterExistingName(c *gc.C) {
err := loggo.RegisterWriter("default", &writer{})
c.Assert(err, gc.ErrorMatches, `context already has a writer named "default"`)
}
func (*GlobalSuite) TestReplaceDefaultWriter(c *gc.C) {
oldWriter, err := loggo.ReplaceDefaultWriter(&writer{})
c.Assert(oldWriter, gc.NotNil)
c.Assert(err, gc.IsNil)
c.Assert(loggo.DefaultContext().WriterNames(), gc.DeepEquals, []string{"default"})
}
func (*GlobalSuite) TestRemoveWriter(c *gc.C) {
oldWriter, err := loggo.RemoveWriter("default")
c.Assert(oldWriter, gc.NotNil)
c.Assert(err, gc.IsNil)
c.Assert(loggo.DefaultContext().WriterNames(), gc.HasLen, 0)
}
func (s *GlobalSuite) TestGetLoggerWithTags(c *gc.C) {
logger := loggo.GetLoggerWithTags("parent", "labela", "labelb")
c.Check(logger.Tags(), gc.DeepEquals, []string{"labela", "labelb"})
}