-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmodule.go
63 lines (53 loc) · 1.27 KB
/
module.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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package loggo
// Do not change rootName: modules.resolve() will misbehave if it isn't "".
const (
rootString = "<root>"
)
type module struct {
name string
level Level
parent *module
context *Context
tags []string
tagsLookup map[string]struct{}
labels Labels
}
// Name returns the module's name.
func (m *module) Name() string {
if m.name == "" {
return rootString
}
return m.name
}
func (m *module) willWrite(level Level) bool {
if level < TRACE || level > CRITICAL {
return false
}
return level >= m.getEffectiveLogLevel()
}
func (m *module) getEffectiveLogLevel() Level {
// Note: the root module is guaranteed to have a
// specified logging level, so acts as a suitable sentinel
// for this loop.
for {
if level := m.level.get(); level != UNSPECIFIED {
return level
}
m = m.parent
}
}
// setLevel sets the severity level of the given module.
// The root module cannot be set to UNSPECIFIED level.
func (m *module) setLevel(level Level) {
// The root module can't be unspecified.
if m.name == "" && level == UNSPECIFIED {
level = WARNING
}
m.level.set(level)
}
func (m *module) write(entry Entry) {
entry.Module = m.name
m.context.write(entry)
}