-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
69 lines (59 loc) · 1.79 KB
/
Copy pathconfig.go
File metadata and controls
69 lines (59 loc) · 1.79 KB
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
package logger
// Config defines the logging configuration for the context it is attached to.
type Config struct {
Main systemConfig
Active systemConfig
IncludedSubSystems map[string]bool // If true, log in main log
SubSystems map[string]systemConfig // SubSystem specific loggers
}
func (c Config) Copy() Config {
result := c
result.IncludedSubSystems = make(map[string]bool)
for k, v := range c.IncludedSubSystems {
result.IncludedSubSystems[k] = v
}
result.SubSystems = make(map[string]systemConfig)
for k, v := range c.SubSystems {
result.SubSystems[k] = v
}
return result
}
// NewConfig creates a new config with the specified values.
func NewConfig(isDevelopment, isText bool, filePath string) Config {
result := Config{
IncludedSubSystems: make(map[string]bool),
SubSystems: make(map[string]systemConfig),
}
var err error
result.Main, err = newSystemConfig(isDevelopment, isText, filePath)
if err != nil {
return result
}
result.Active = result.Main.Copy()
return result
}
// NewConfigFromSetup creates a new config from a setup config.
func NewConfigFromSetup(setup SetupConfig) Config {
result := Config{
IncludedSubSystems: make(map[string]bool),
SubSystems: make(map[string]systemConfig),
}
var err error
result.Main, err = newSystemConfigFromSetup(setup)
if err != nil {
return result
}
result.Active = result.Main.Copy()
return result
}
// NewEmptyConfig creates a new config that doesn't log.
func NewEmptyConfig() Config {
return Config{
IncludedSubSystems: make(map[string]bool),
SubSystems: make(map[string]systemConfig),
}
}
// EnableSubSystem enables a subsytem to log to the main log
func (config *Config) EnableSubSystem(subsystem string) {
config.IncludedSubSystems[subsystem] = true
}