forked from hashicorp/consul-template
/
syslog.go
87 lines (71 loc) · 1.74 KB
/
syslog.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
package config
import "fmt"
const (
// DefaultSyslogFacility is the default facility to log to.
DefaultSyslogFacility = "LOCAL0"
)
// SyslogConfig is the configuration for syslog.
type SyslogConfig struct {
Enabled *bool `mapstructure:"enabled"`
Facility *string `mapstructure:"facility"`
}
// DefaultSyslogConfig returns a configuration that is populated with the
// default values.
func DefaultSyslogConfig() *SyslogConfig {
return &SyslogConfig{}
}
// Copy returns a deep copy of this configuration.
func (c *SyslogConfig) Copy() *SyslogConfig {
if c == nil {
return nil
}
var o SyslogConfig
o.Enabled = c.Enabled
o.Facility = c.Facility
return &o
}
// Merge combines all values in this configuration with the values in the other
// configuration, with values in the other configuration taking precedence.
// Maps and slices are merged, most other values are overwritten. Complex
// structs define their own merge functionality.
func (c *SyslogConfig) Merge(o *SyslogConfig) *SyslogConfig {
if c == nil {
if o == nil {
return nil
}
return o.Copy()
}
if o == nil {
return c.Copy()
}
r := c.Copy()
if o.Enabled != nil {
r.Enabled = o.Enabled
}
if o.Facility != nil {
r.Facility = o.Facility
}
return r
}
// Finalize ensures there no nil pointers.
func (c *SyslogConfig) Finalize() {
if c.Enabled == nil {
c.Enabled = Bool(StringPresent(c.Facility))
}
if c.Facility == nil {
c.Facility = String(DefaultSyslogFacility)
}
}
// GoString defines the printable version of this struct.
func (c *SyslogConfig) GoString() string {
if c == nil {
return "(*SyslogConfig)(nil)"
}
return fmt.Sprintf("&SyslogConfig{"+
"Enabled:%s, "+
"Facility:%s"+
"}",
BoolGoString(c.Enabled),
StringGoString(c.Facility),
)
}