diff options
author | Ben Ye <yb532204897@gmail.com> | 2019-12-31 11:19:37 -0500 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2019-12-31 17:19:37 +0100 |
commit | 2477c5c67dff7e7655a9d466450235e9c9eac193 (patch) | |
tree | 198cb44d48f454df765984bc614e1b1972a646e8 | |
parent | a80b7d0bc5ee93e704bab22e7592ed8b7d65899e (diff) | |
download | prometheus_node_collector-2477c5c67dff7e7655a9d466450235e9c9eac193.tar.bz2 prometheus_node_collector-2477c5c67dff7e7655a9d466450235e9c9eac193.tar.xz prometheus_node_collector-2477c5c67dff7e7655a9d466450235e9c9eac193.zip |
switch to go-kit/log (#1575)
Signed-off-by: yeya24 <yb532204897@gmail.com>
158 files changed, 3434 insertions, 4636 deletions
diff --git a/collector/arp_linux.go b/collector/arp_linux.go index 49c437e..6a18879 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go | |||
@@ -22,11 +22,13 @@ import ( | |||
22 | "os" | 22 | "os" |
23 | "strings" | 23 | "strings" |
24 | 24 | ||
25 | "github.com/go-kit/kit/log" | ||
25 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
26 | ) | 27 | ) |
27 | 28 | ||
28 | type arpCollector struct { | 29 | type arpCollector struct { |
29 | entries *prometheus.Desc | 30 | entries *prometheus.Desc |
31 | logger log.Logger | ||
30 | } | 32 | } |
31 | 33 | ||
32 | func init() { | 34 | func init() { |
@@ -34,13 +36,14 @@ func init() { | |||
34 | } | 36 | } |
35 | 37 | ||
36 | // NewARPCollector returns a new Collector exposing ARP stats. | 38 | // NewARPCollector returns a new Collector exposing ARP stats. |
37 | func NewARPCollector() (Collector, error) { | 39 | func NewARPCollector(logger log.Logger) (Collector, error) { |
38 | return &arpCollector{ | 40 | return &arpCollector{ |
39 | entries: prometheus.NewDesc( | 41 | entries: prometheus.NewDesc( |
40 | prometheus.BuildFQName(namespace, "arp", "entries"), | 42 | prometheus.BuildFQName(namespace, "arp", "entries"), |
41 | "ARP entries by device", | 43 | "ARP entries by device", |
42 | []string{"device"}, nil, | 44 | []string{"device"}, nil, |
43 | ), | 45 | ), |
46 | logger: logger, | ||
44 | }, nil | 47 | }, nil |
45 | } | 48 | } |
46 | 49 | ||
diff --git a/collector/bcache_linux.go b/collector/bcache_linux.go index da4eab5..20995c7 100644 --- a/collector/bcache_linux.go +++ b/collector/bcache_linux.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/prometheus/procfs/bcache" | 23 | "github.com/prometheus/procfs/bcache" |
23 | ) | 24 | ) |
@@ -28,19 +29,21 @@ func init() { | |||
28 | 29 | ||
29 | // A bcacheCollector is a Collector which gathers metrics from Linux bcache. | 30 | // A bcacheCollector is a Collector which gathers metrics from Linux bcache. |
30 | type bcacheCollector struct { | 31 | type bcacheCollector struct { |
31 | fs bcache.FS | 32 | fs bcache.FS |
33 | logger log.Logger | ||
32 | } | 34 | } |
33 | 35 | ||
34 | // NewBcacheCollector returns a newly allocated bcacheCollector. | 36 | // NewBcacheCollector returns a newly allocated bcacheCollector. |
35 | // It exposes a number of Linux bcache statistics. | 37 | // It exposes a number of Linux bcache statistics. |
36 | func NewBcacheCollector() (Collector, error) { | 38 | func NewBcacheCollector(logger log.Logger) (Collector, error) { |
37 | fs, err := bcache.NewFS(*sysPath) | 39 | fs, err := bcache.NewFS(*sysPath) |
38 | if err != nil { | 40 | if err != nil { |
39 | return nil, fmt.Errorf("failed to open sysfs: %w", err) | 41 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
40 | } | 42 | } |
41 | 43 | ||
42 | return &bcacheCollector{ | 44 | return &bcacheCollector{ |
43 | fs: fs, | 45 | fs: fs, |
46 | logger: logger, | ||
44 | }, nil | 47 | }, nil |
45 | } | 48 | } |
46 | 49 | ||
diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index f67e2a3..771786b 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go | |||
@@ -22,12 +22,14 @@ import ( | |||
22 | "path/filepath" | 22 | "path/filepath" |
23 | "strings" | 23 | "strings" |
24 | 24 | ||
25 | "github.com/go-kit/kit/log" | ||
26 | "github.com/go-kit/kit/log/level" | ||
25 | "github.com/prometheus/client_golang/prometheus" | 27 | "github.com/prometheus/client_golang/prometheus" |
26 | "github.com/prometheus/common/log" | ||
27 | ) | 28 | ) |
28 | 29 | ||
29 | type bondingCollector struct { | 30 | type bondingCollector struct { |
30 | slaves, active typedDesc | 31 | slaves, active typedDesc |
32 | logger log.Logger | ||
31 | } | 33 | } |
32 | 34 | ||
33 | func init() { | 35 | func init() { |
@@ -36,7 +38,7 @@ func init() { | |||
36 | 38 | ||
37 | // NewBondingCollector returns a newly allocated bondingCollector. | 39 | // NewBondingCollector returns a newly allocated bondingCollector. |
38 | // It exposes the number of configured and active slave of linux bonding interfaces. | 40 | // It exposes the number of configured and active slave of linux bonding interfaces. |
39 | func NewBondingCollector() (Collector, error) { | 41 | func NewBondingCollector(logger log.Logger) (Collector, error) { |
40 | return &bondingCollector{ | 42 | return &bondingCollector{ |
41 | slaves: typedDesc{prometheus.NewDesc( | 43 | slaves: typedDesc{prometheus.NewDesc( |
42 | prometheus.BuildFQName(namespace, "bonding", "slaves"), | 44 | prometheus.BuildFQName(namespace, "bonding", "slaves"), |
@@ -48,6 +50,7 @@ func NewBondingCollector() (Collector, error) { | |||
48 | "Number of active slaves per bonding interface.", | 50 | "Number of active slaves per bonding interface.", |
49 | []string{"master"}, nil, | 51 | []string{"master"}, nil, |
50 | ), prometheus.GaugeValue}, | 52 | ), prometheus.GaugeValue}, |
53 | logger: logger, | ||
51 | }, nil | 54 | }, nil |
52 | } | 55 | } |
53 | 56 | ||
@@ -57,7 +60,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error { | |||
57 | bondingStats, err := readBondingStats(statusfile) | 60 | bondingStats, err := readBondingStats(statusfile) |
58 | if err != nil { | 61 | if err != nil { |
59 | if os.IsNotExist(err) { | 62 | if os.IsNotExist(err) { |
60 | log.Debugf("Not collecting bonding, file does not exist: %s", statusfile) | 63 | level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile) |
61 | return nil | 64 | return nil |
62 | } | 65 | } |
63 | return err | 66 | return err |
diff --git a/collector/boot_time_bsd.go b/collector/boot_time_bsd.go index cc2e895..74d4bce 100644 --- a/collector/boot_time_bsd.go +++ b/collector/boot_time_bsd.go | |||
@@ -17,17 +17,21 @@ | |||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "github.com/go-kit/kit/log" | ||
20 | "github.com/prometheus/client_golang/prometheus" | 21 | "github.com/prometheus/client_golang/prometheus" |
21 | ) | 22 | ) |
22 | 23 | ||
23 | type bootTimeCollector struct{ boottime bsdSysctl } | 24 | type bootTimeCollector struct { |
25 | boottime bsdSysctl | ||
26 | logger log.Logger | ||
27 | } | ||
24 | 28 | ||
25 | func init() { | 29 | func init() { |
26 | registerCollector("boottime", defaultEnabled, newBootTimeCollector) | 30 | registerCollector("boottime", defaultEnabled, newBootTimeCollector) |
27 | } | 31 | } |
28 | 32 | ||
29 | // newBootTimeCollector returns a new Collector exposing system boot time on BSD systems. | 33 | // newBootTimeCollector returns a new Collector exposing system boot time on BSD systems. |
30 | func newBootTimeCollector() (Collector, error) { | 34 | func newBootTimeCollector(logger log.Logger) (Collector, error) { |
31 | return &bootTimeCollector{ | 35 | return &bootTimeCollector{ |
32 | boottime: bsdSysctl{ | 36 | boottime: bsdSysctl{ |
33 | name: "boot_time_seconds", | 37 | name: "boot_time_seconds", |
@@ -35,6 +39,7 @@ func newBootTimeCollector() (Collector, error) { | |||
35 | mib: "kern.boottime", | 39 | mib: "kern.boottime", |
36 | dataType: bsdSysctlTypeStructTimeval, | 40 | dataType: bsdSysctlTypeStructTimeval, |
37 | }, | 41 | }, |
42 | logger: logger, | ||
38 | }, nil | 43 | }, nil |
39 | } | 44 | } |
40 | 45 | ||
diff --git a/collector/boot_time_solaris.go b/collector/boot_time_solaris.go index ea0c50a..eb27034 100644 --- a/collector/boot_time_solaris.go +++ b/collector/boot_time_solaris.go | |||
@@ -17,19 +17,21 @@ | |||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "github.com/go-kit/kit/log" | ||
20 | "github.com/prometheus/client_golang/prometheus" | 21 | "github.com/prometheus/client_golang/prometheus" |
21 | "github.com/siebenmann/go-kstat" | 22 | "github.com/siebenmann/go-kstat" |
22 | ) | 23 | ) |
23 | 24 | ||
24 | type bootTimeCollector struct { | 25 | type bootTimeCollector struct { |
25 | boottime typedDesc | 26 | boottime typedDesc |
27 | logger log.Logger | ||
26 | } | 28 | } |
27 | 29 | ||
28 | func init() { | 30 | func init() { |
29 | registerCollector("boottime", defaultEnabled, newBootTimeCollector) | 31 | registerCollector("boottime", defaultEnabled, newBootTimeCollector) |
30 | } | 32 | } |
31 | 33 | ||
32 | func newBootTimeCollector() (Collector, error) { | 34 | func newBootTimeCollector(logger log.Logger) (Collector, error) { |
33 | return &bootTimeCollector{ | 35 | return &bootTimeCollector{ |
34 | boottime: typedDesc{ | 36 | boottime: typedDesc{ |
35 | prometheus.NewDesc( | 37 | prometheus.NewDesc( |
@@ -37,6 +39,7 @@ func newBootTimeCollector() (Collector, error) { | |||
37 | "Unix time of last boot, including microseconds.", | 39 | "Unix time of last boot, including microseconds.", |
38 | nil, nil, | 40 | nil, nil, |
39 | ), prometheus.GaugeValue}, | 41 | ), prometheus.GaugeValue}, |
42 | logger: logger, | ||
40 | }, nil | 43 | }, nil |
41 | } | 44 | } |
42 | 45 | ||
diff --git a/collector/buddyinfo.go b/collector/buddyinfo.go index 316766e..e94e283 100644 --- a/collector/buddyinfo.go +++ b/collector/buddyinfo.go | |||
@@ -20,8 +20,9 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/common/log" | ||
25 | "github.com/prometheus/procfs" | 26 | "github.com/prometheus/procfs" |
26 | ) | 27 | ) |
27 | 28 | ||
@@ -30,8 +31,9 @@ const ( | |||
30 | ) | 31 | ) |
31 | 32 | ||
32 | type buddyinfoCollector struct { | 33 | type buddyinfoCollector struct { |
33 | fs procfs.FS | 34 | fs procfs.FS |
34 | desc *prometheus.Desc | 35 | desc *prometheus.Desc |
36 | logger log.Logger | ||
35 | } | 37 | } |
36 | 38 | ||
37 | func init() { | 39 | func init() { |
@@ -39,7 +41,7 @@ func init() { | |||
39 | } | 41 | } |
40 | 42 | ||
41 | // NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats. | 43 | // NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats. |
42 | func NewBuddyinfoCollector() (Collector, error) { | 44 | func NewBuddyinfoCollector(logger log.Logger) (Collector, error) { |
43 | desc := prometheus.NewDesc( | 45 | desc := prometheus.NewDesc( |
44 | prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"), | 46 | prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"), |
45 | "Count of free blocks according to size.", | 47 | "Count of free blocks according to size.", |
@@ -49,7 +51,7 @@ func NewBuddyinfoCollector() (Collector, error) { | |||
49 | if err != nil { | 51 | if err != nil { |
50 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 52 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
51 | } | 53 | } |
52 | return &buddyinfoCollector{fs, desc}, nil | 54 | return &buddyinfoCollector{fs, desc, logger}, nil |
53 | } | 55 | } |
54 | 56 | ||
55 | // Update calls (*buddyinfoCollector).getBuddyInfo to get the platform specific | 57 | // Update calls (*buddyinfoCollector).getBuddyInfo to get the platform specific |
@@ -60,7 +62,7 @@ func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error { | |||
60 | return fmt.Errorf("couldn't get buddyinfo: %s", err) | 62 | return fmt.Errorf("couldn't get buddyinfo: %s", err) |
61 | } | 63 | } |
62 | 64 | ||
63 | log.Debugf("Set node_buddy: %#v", buddyInfo) | 65 | level.Debug(c.logger).Log("msg", "Set node_buddy", "buddyInfo", buddyInfo) |
64 | for _, entry := range buddyInfo { | 66 | for _, entry := range buddyInfo { |
65 | for size, value := range entry.Sizes { | 67 | for size, value := range entry.Sizes { |
66 | ch <- prometheus.MustNewConstMetric( | 68 | ch <- prometheus.MustNewConstMetric( |
diff --git a/collector/collector.go b/collector/collector.go index 4b74b89..af8712c 100644 --- a/collector/collector.go +++ b/collector/collector.go | |||
@@ -19,8 +19,9 @@ import ( | |||
19 | "sync" | 19 | "sync" |
20 | "time" | 20 | "time" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
23 | "github.com/go-kit/kit/log/level" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | ||
24 | "gopkg.in/alecthomas/kingpin.v2" | 25 | "gopkg.in/alecthomas/kingpin.v2" |
25 | ) | 26 | ) |
26 | 27 | ||
@@ -48,11 +49,11 @@ const ( | |||
48 | ) | 49 | ) |
49 | 50 | ||
50 | var ( | 51 | var ( |
51 | factories = make(map[string]func() (Collector, error)) | 52 | factories = make(map[string]func(logger log.Logger) (Collector, error)) |
52 | collectorState = make(map[string]*bool) | 53 | collectorState = make(map[string]*bool) |
53 | ) | 54 | ) |
54 | 55 | ||
55 | func registerCollector(collector string, isDefaultEnabled bool, factory func() (Collector, error)) { | 56 | func registerCollector(collector string, isDefaultEnabled bool, factory func(logger log.Logger) (Collector, error)) { |
56 | var helpDefaultState string | 57 | var helpDefaultState string |
57 | if isDefaultEnabled { | 58 | if isDefaultEnabled { |
58 | helpDefaultState = "enabled" | 59 | helpDefaultState = "enabled" |
@@ -73,10 +74,11 @@ func registerCollector(collector string, isDefaultEnabled bool, factory func() ( | |||
73 | // NodeCollector implements the prometheus.Collector interface. | 74 | // NodeCollector implements the prometheus.Collector interface. |
74 | type NodeCollector struct { | 75 | type NodeCollector struct { |
75 | Collectors map[string]Collector | 76 | Collectors map[string]Collector |
77 | logger log.Logger | ||
76 | } | 78 | } |
77 | 79 | ||
78 | // NewNodeCollector creates a new NodeCollector. | 80 | // NewNodeCollector creates a new NodeCollector. |
79 | func NewNodeCollector(filters ...string) (*NodeCollector, error) { | 81 | func NewNodeCollector(logger log.Logger, filters ...string) (*NodeCollector, error) { |
80 | f := make(map[string]bool) | 82 | f := make(map[string]bool) |
81 | for _, filter := range filters { | 83 | for _, filter := range filters { |
82 | enabled, exist := collectorState[filter] | 84 | enabled, exist := collectorState[filter] |
@@ -91,7 +93,7 @@ func NewNodeCollector(filters ...string) (*NodeCollector, error) { | |||
91 | collectors := make(map[string]Collector) | 93 | collectors := make(map[string]Collector) |
92 | for key, enabled := range collectorState { | 94 | for key, enabled := range collectorState { |
93 | if *enabled { | 95 | if *enabled { |
94 | collector, err := factories[key]() | 96 | collector, err := factories[key](log.With(logger, "collector", key)) |
95 | if err != nil { | 97 | if err != nil { |
96 | return nil, err | 98 | return nil, err |
97 | } | 99 | } |
@@ -100,7 +102,7 @@ func NewNodeCollector(filters ...string) (*NodeCollector, error) { | |||
100 | } | 102 | } |
101 | } | 103 | } |
102 | } | 104 | } |
103 | return &NodeCollector{Collectors: collectors}, nil | 105 | return &NodeCollector{Collectors: collectors, logger: logger}, nil |
104 | } | 106 | } |
105 | 107 | ||
106 | // Describe implements the prometheus.Collector interface. | 108 | // Describe implements the prometheus.Collector interface. |
@@ -115,24 +117,24 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) { | |||
115 | wg.Add(len(n.Collectors)) | 117 | wg.Add(len(n.Collectors)) |
116 | for name, c := range n.Collectors { | 118 | for name, c := range n.Collectors { |
117 | go func(name string, c Collector) { | 119 | go func(name string, c Collector) { |
118 | execute(name, c, ch) | 120 | execute(name, c, ch, n.logger) |
119 | wg.Done() | 121 | wg.Done() |
120 | }(name, c) | 122 | }(name, c) |
121 | } | 123 | } |
122 | wg.Wait() | 124 | wg.Wait() |
123 | } | 125 | } |
124 | 126 | ||
125 | func execute(name string, c Collector, ch chan<- prometheus.Metric) { | 127 | func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.Logger) { |
126 | begin := time.Now() | 128 | begin := time.Now() |
127 | err := c.Update(ch) | 129 | err := c.Update(ch) |
128 | duration := time.Since(begin) | 130 | duration := time.Since(begin) |
129 | var success float64 | 131 | var success float64 |
130 | 132 | ||
131 | if err != nil { | 133 | if err != nil { |
132 | log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err) | 134 | level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err) |
133 | success = 0 | 135 | success = 0 |
134 | } else { | 136 | } else { |
135 | log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds()) | 137 | level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds()) |
136 | success = 1 | 138 | success = 1 |
137 | } | 139 | } |
138 | ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name) | 140 | ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name) |
diff --git a/collector/conntrack_linux.go b/collector/conntrack_linux.go index 4a0e375..9dc8114 100644 --- a/collector/conntrack_linux.go +++ b/collector/conntrack_linux.go | |||
@@ -16,12 +16,14 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "github.com/go-kit/kit/log" | ||
19 | "github.com/prometheus/client_golang/prometheus" | 20 | "github.com/prometheus/client_golang/prometheus" |
20 | ) | 21 | ) |
21 | 22 | ||
22 | type conntrackCollector struct { | 23 | type conntrackCollector struct { |
23 | current *prometheus.Desc | 24 | current *prometheus.Desc |
24 | limit *prometheus.Desc | 25 | limit *prometheus.Desc |
26 | logger log.Logger | ||
25 | } | 27 | } |
26 | 28 | ||
27 | func init() { | 29 | func init() { |
@@ -29,7 +31,7 @@ func init() { | |||
29 | } | 31 | } |
30 | 32 | ||
31 | // NewConntrackCollector returns a new Collector exposing conntrack stats. | 33 | // NewConntrackCollector returns a new Collector exposing conntrack stats. |
32 | func NewConntrackCollector() (Collector, error) { | 34 | func NewConntrackCollector(logger log.Logger) (Collector, error) { |
33 | return &conntrackCollector{ | 35 | return &conntrackCollector{ |
34 | current: prometheus.NewDesc( | 36 | current: prometheus.NewDesc( |
35 | prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"), | 37 | prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"), |
@@ -41,6 +43,7 @@ func NewConntrackCollector() (Collector, error) { | |||
41 | "Maximum size of connection tracking table.", | 43 | "Maximum size of connection tracking table.", |
42 | nil, nil, | 44 | nil, nil, |
43 | ), | 45 | ), |
46 | logger: logger, | ||
44 | }, nil | 47 | }, nil |
45 | } | 48 | } |
46 | 49 | ||
diff --git a/collector/cpu_darwin.go b/collector/cpu_darwin.go index 74afafd..ba4ba80 100644 --- a/collector/cpu_darwin.go +++ b/collector/cpu_darwin.go | |||
@@ -25,6 +25,7 @@ import ( | |||
25 | "strconv" | 25 | "strconv" |
26 | "unsafe" | 26 | "unsafe" |
27 | 27 | ||
28 | "github.com/go-kit/kit/log" | ||
28 | "github.com/prometheus/client_golang/prometheus" | 29 | "github.com/prometheus/client_golang/prometheus" |
29 | ) | 30 | ) |
30 | 31 | ||
@@ -49,7 +50,8 @@ import "C" | |||
49 | const ClocksPerSec = float64(C.CLK_TCK) | 50 | const ClocksPerSec = float64(C.CLK_TCK) |
50 | 51 | ||
51 | type statCollector struct { | 52 | type statCollector struct { |
52 | cpu *prometheus.Desc | 53 | cpu *prometheus.Desc |
54 | logger log.Logger | ||
53 | } | 55 | } |
54 | 56 | ||
55 | func init() { | 57 | func init() { |
@@ -57,9 +59,10 @@ func init() { | |||
57 | } | 59 | } |
58 | 60 | ||
59 | // NewCPUCollector returns a new Collector exposing CPU stats. | 61 | // NewCPUCollector returns a new Collector exposing CPU stats. |
60 | func NewCPUCollector() (Collector, error) { | 62 | func NewCPUCollector(logger log.Logger) (Collector, error) { |
61 | return &statCollector{ | 63 | return &statCollector{ |
62 | cpu: nodeCPUSecondsDesc, | 64 | cpu: nodeCPUSecondsDesc, |
65 | logger: logger, | ||
63 | }, nil | 66 | }, nil |
64 | } | 67 | } |
65 | 68 | ||
diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index b8c4c06..beef390 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go | |||
@@ -20,6 +20,7 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "unsafe" | 21 | "unsafe" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | ) | 25 | ) |
25 | 26 | ||
@@ -75,7 +76,8 @@ import "C" | |||
75 | const maxCPUTimesLen = C.MAXCPU * C.CPUSTATES | 76 | const maxCPUTimesLen = C.MAXCPU * C.CPUSTATES |
76 | 77 | ||
77 | type statCollector struct { | 78 | type statCollector struct { |
78 | cpu *prometheus.Desc | 79 | cpu *prometheus.Desc |
80 | logger log.Logger | ||
79 | } | 81 | } |
80 | 82 | ||
81 | func init() { | 83 | func init() { |
@@ -83,9 +85,10 @@ func init() { | |||
83 | } | 85 | } |
84 | 86 | ||
85 | // NewStatCollector returns a new Collector exposing CPU stats. | 87 | // NewStatCollector returns a new Collector exposing CPU stats. |
86 | func NewStatCollector() (Collector, error) { | 88 | func NewStatCollector(logger log.Logger) (Collector, error) { |
87 | return &statCollector{ | 89 | return &statCollector{ |
88 | cpu: nodeCPUSecondsDesc, | 90 | cpu: nodeCPUSecondsDesc, |
91 | logger: logger, | ||
89 | }, nil | 92 | }, nil |
90 | } | 93 | } |
91 | 94 | ||
diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index dc3d6a1..41573e4 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go | |||
@@ -21,8 +21,9 @@ import ( | |||
21 | "strconv" | 21 | "strconv" |
22 | "unsafe" | 22 | "unsafe" |
23 | 23 | ||
24 | "github.com/go-kit/kit/log" | ||
25 | "github.com/go-kit/kit/log/level" | ||
24 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
25 | "github.com/prometheus/common/log" | ||
26 | "golang.org/x/sys/unix" | 27 | "golang.org/x/sys/unix" |
27 | ) | 28 | ) |
28 | 29 | ||
@@ -81,8 +82,9 @@ func getCPUTimes() ([]cputime, error) { | |||
81 | } | 82 | } |
82 | 83 | ||
83 | type statCollector struct { | 84 | type statCollector struct { |
84 | cpu typedDesc | 85 | cpu typedDesc |
85 | temp typedDesc | 86 | temp typedDesc |
87 | logger log.Logger | ||
86 | } | 88 | } |
87 | 89 | ||
88 | func init() { | 90 | func init() { |
@@ -90,7 +92,7 @@ func init() { | |||
90 | } | 92 | } |
91 | 93 | ||
92 | // NewStatCollector returns a new Collector exposing CPU stats. | 94 | // NewStatCollector returns a new Collector exposing CPU stats. |
93 | func NewStatCollector() (Collector, error) { | 95 | func NewStatCollector(logger log.Logger) (Collector, error) { |
94 | return &statCollector{ | 96 | return &statCollector{ |
95 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, | 97 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, |
96 | temp: typedDesc{prometheus.NewDesc( | 98 | temp: typedDesc{prometheus.NewDesc( |
@@ -98,6 +100,7 @@ func NewStatCollector() (Collector, error) { | |||
98 | "CPU temperature", | 100 | "CPU temperature", |
99 | []string{"cpu"}, nil, | 101 | []string{"cpu"}, nil, |
100 | ), prometheus.GaugeValue}, | 102 | ), prometheus.GaugeValue}, |
103 | logger: logger, | ||
101 | }, nil | 104 | }, nil |
102 | } | 105 | } |
103 | 106 | ||
@@ -130,11 +133,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { | |||
130 | if err != nil { | 133 | if err != nil { |
131 | if err == unix.ENOENT { | 134 | if err == unix.ENOENT { |
132 | // No temperature information for this CPU | 135 | // No temperature information for this CPU |
133 | log.Debugf("no temperature information for CPU %d", cpu) | 136 | level.Debug(c.logger).Log("msg", "no temperature information for CPU", "cpu", cpu) |
134 | } else { | 137 | } else { |
135 | // Unexpected error | 138 | // Unexpected error |
136 | ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu) | 139 | ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu) |
137 | log.Errorf("failed to query CPU temperature for CPU %d: %s", cpu, err) | 140 | level.Error(c.logger).Log("msg", "failed to query CPU temperature for CPU", "cpu", cpu, "err", err) |
138 | } | 141 | } |
139 | continue | 142 | continue |
140 | } | 143 | } |
diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index c946520..1cb6f2c 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go | |||
@@ -20,10 +20,11 @@ import ( | |||
20 | "path/filepath" | 20 | "path/filepath" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/common/log" | ||
25 | "github.com/prometheus/procfs" | 26 | "github.com/prometheus/procfs" |
26 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 27 | "gopkg.in/alecthomas/kingpin.v2" |
27 | ) | 28 | ) |
28 | 29 | ||
29 | type cpuCollector struct { | 30 | type cpuCollector struct { |
@@ -33,6 +34,7 @@ type cpuCollector struct { | |||
33 | cpuGuest *prometheus.Desc | 34 | cpuGuest *prometheus.Desc |
34 | cpuCoreThrottle *prometheus.Desc | 35 | cpuCoreThrottle *prometheus.Desc |
35 | cpuPackageThrottle *prometheus.Desc | 36 | cpuPackageThrottle *prometheus.Desc |
37 | logger log.Logger | ||
36 | } | 38 | } |
37 | 39 | ||
38 | var ( | 40 | var ( |
@@ -44,7 +46,7 @@ func init() { | |||
44 | } | 46 | } |
45 | 47 | ||
46 | // NewCPUCollector returns a new Collector exposing kernel/system statistics. | 48 | // NewCPUCollector returns a new Collector exposing kernel/system statistics. |
47 | func NewCPUCollector() (Collector, error) { | 49 | func NewCPUCollector(logger log.Logger) (Collector, error) { |
48 | fs, err := procfs.NewFS(*procPath) | 50 | fs, err := procfs.NewFS(*procPath) |
49 | if err != nil { | 51 | if err != nil { |
50 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 52 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -72,6 +74,7 @@ func NewCPUCollector() (Collector, error) { | |||
72 | "Number of times this cpu package has been throttled.", | 74 | "Number of times this cpu package has been throttled.", |
73 | []string{"package"}, nil, | 75 | []string{"package"}, nil, |
74 | ), | 76 | ), |
77 | logger: logger, | ||
75 | }, nil | 78 | }, nil |
76 | } | 79 | } |
77 | 80 | ||
@@ -134,12 +137,12 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error | |||
134 | 137 | ||
135 | // topology/physical_package_id | 138 | // topology/physical_package_id |
136 | if physicalPackageID, err = readUintFromFile(filepath.Join(cpu, "topology", "physical_package_id")); err != nil { | 139 | if physicalPackageID, err = readUintFromFile(filepath.Join(cpu, "topology", "physical_package_id")); err != nil { |
137 | log.Debugf("CPU %v is missing physical_package_id", cpu) | 140 | level.Debug(c.logger).Log("msg", "CPU is missing physical_package_id", "cpu", cpu) |
138 | continue | 141 | continue |
139 | } | 142 | } |
140 | // topology/core_id | 143 | // topology/core_id |
141 | if coreID, err = readUintFromFile(filepath.Join(cpu, "topology", "core_id")); err != nil { | 144 | if coreID, err = readUintFromFile(filepath.Join(cpu, "topology", "core_id")); err != nil { |
142 | log.Debugf("CPU %v is missing core_id", cpu) | 145 | level.Debug(c.logger).Log("msg", "CPU is missing core_id", "cpu", cpu) |
143 | continue | 146 | continue |
144 | } | 147 | } |
145 | 148 | ||
@@ -157,7 +160,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error | |||
157 | if coreThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err == nil { | 160 | if coreThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err == nil { |
158 | packageCoreThrottles[physicalPackageID][coreID] = coreThrottleCount | 161 | packageCoreThrottles[physicalPackageID][coreID] = coreThrottleCount |
159 | } else { | 162 | } else { |
160 | log.Debugf("CPU %v is missing core_throttle_count", cpu) | 163 | level.Debug(c.logger).Log("msg", "CPU is missing core_throttle_count", "cpu", cpu) |
161 | } | 164 | } |
162 | } | 165 | } |
163 | 166 | ||
@@ -167,7 +170,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error | |||
167 | if packageThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "package_throttle_count")); err == nil { | 170 | if packageThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "package_throttle_count")); err == nil { |
168 | packageThrottles[physicalPackageID] = packageThrottleCount | 171 | packageThrottles[physicalPackageID] = packageThrottleCount |
169 | } else { | 172 | } else { |
170 | log.Debugf("CPU %v is missing package_throttle_count", cpu) | 173 | level.Debug(c.logger).Log("msg", "CPU is missing package_throttle_count", "cpu", cpu) |
171 | } | 174 | } |
172 | } | 175 | } |
173 | } | 176 | } |
diff --git a/collector/cpu_openbsd.go b/collector/cpu_openbsd.go index cddc204..b7d7688 100644 --- a/collector/cpu_openbsd.go +++ b/collector/cpu_openbsd.go | |||
@@ -19,6 +19,7 @@ import ( | |||
19 | "strconv" | 19 | "strconv" |
20 | "unsafe" | 20 | "unsafe" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | "golang.org/x/sys/unix" | 24 | "golang.org/x/sys/unix" |
24 | ) | 25 | ) |
@@ -30,16 +31,18 @@ import ( | |||
30 | import "C" | 31 | import "C" |
31 | 32 | ||
32 | type cpuCollector struct { | 33 | type cpuCollector struct { |
33 | cpu typedDesc | 34 | cpu typedDesc |
35 | logger log.Logger | ||
34 | } | 36 | } |
35 | 37 | ||
36 | func init() { | 38 | func init() { |
37 | registerCollector("cpu", defaultEnabled, NewCPUCollector) | 39 | registerCollector("cpu", defaultEnabled, NewCPUCollector) |
38 | } | 40 | } |
39 | 41 | ||
40 | func NewCPUCollector() (Collector, error) { | 42 | func NewCPUCollector(logger log.Logger) (Collector, error) { |
41 | return &cpuCollector{ | 43 | return &cpuCollector{ |
42 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, | 44 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, |
45 | logger: logger, | ||
43 | }, nil | 46 | }, nil |
44 | } | 47 | } |
45 | 48 | ||
diff --git a/collector/cpu_solaris.go b/collector/cpu_solaris.go index f772765..0624454 100644 --- a/collector/cpu_solaris.go +++ b/collector/cpu_solaris.go | |||
@@ -19,6 +19,7 @@ package collector | |||
19 | import ( | 19 | import ( |
20 | "strconv" | 20 | "strconv" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | kstat "github.com/siebenmann/go-kstat" | 24 | kstat "github.com/siebenmann/go-kstat" |
24 | ) | 25 | ) |
@@ -27,16 +28,18 @@ import ( | |||
27 | import "C" | 28 | import "C" |
28 | 29 | ||
29 | type cpuCollector struct { | 30 | type cpuCollector struct { |
30 | cpu typedDesc | 31 | cpu typedDesc |
32 | logger log.Logger | ||
31 | } | 33 | } |
32 | 34 | ||
33 | func init() { | 35 | func init() { |
34 | registerCollector("cpu", defaultEnabled, NewCpuCollector) | 36 | registerCollector("cpu", defaultEnabled, NewCpuCollector) |
35 | } | 37 | } |
36 | 38 | ||
37 | func NewCpuCollector() (Collector, error) { | 39 | func NewCpuCollector(logger log.Logger) (Collector, error) { |
38 | return &cpuCollector{ | 40 | return &cpuCollector{ |
39 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, | 41 | cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, |
42 | logger: logger, | ||
40 | }, nil | 43 | }, nil |
41 | } | 44 | } |
42 | 45 | ||
diff --git a/collector/cpufreq_linux.go b/collector/cpufreq_linux.go index c4de4d5..aa32ad2 100644 --- a/collector/cpufreq_linux.go +++ b/collector/cpufreq_linux.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/prometheus/procfs/sysfs" | 23 | "github.com/prometheus/procfs/sysfs" |
23 | ) | 24 | ) |
@@ -30,6 +31,7 @@ type cpuFreqCollector struct { | |||
30 | scalingFreq *prometheus.Desc | 31 | scalingFreq *prometheus.Desc |
31 | scalingFreqMin *prometheus.Desc | 32 | scalingFreqMin *prometheus.Desc |
32 | scalingFreqMax *prometheus.Desc | 33 | scalingFreqMax *prometheus.Desc |
34 | logger log.Logger | ||
33 | } | 35 | } |
34 | 36 | ||
35 | func init() { | 37 | func init() { |
@@ -37,7 +39,7 @@ func init() { | |||
37 | } | 39 | } |
38 | 40 | ||
39 | // NewCPUFreqCollector returns a new Collector exposing kernel/system statistics. | 41 | // NewCPUFreqCollector returns a new Collector exposing kernel/system statistics. |
40 | func NewCPUFreqCollector() (Collector, error) { | 42 | func NewCPUFreqCollector(logger log.Logger) (Collector, error) { |
41 | fs, err := sysfs.NewFS(*sysPath) | 43 | fs, err := sysfs.NewFS(*sysPath) |
42 | if err != nil { | 44 | if err != nil { |
43 | return nil, fmt.Errorf("failed to open sysfs: %w", err) | 45 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
@@ -75,6 +77,7 @@ func NewCPUFreqCollector() (Collector, error) { | |||
75 | "Maximum scaled cpu thread frequency in hertz.", | 77 | "Maximum scaled cpu thread frequency in hertz.", |
76 | []string{"cpu"}, nil, | 78 | []string{"cpu"}, nil, |
77 | ), | 79 | ), |
80 | logger: logger, | ||
78 | }, nil | 81 | }, nil |
79 | } | 82 | } |
80 | 83 | ||
diff --git a/collector/cpufreq_solaris.go b/collector/cpufreq_solaris.go index 77ac3ab..7c614ff 100644 --- a/collector/cpufreq_solaris.go +++ b/collector/cpufreq_solaris.go | |||
@@ -20,6 +20,7 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | kstat "github.com/siebenmann/go-kstat" | 25 | kstat "github.com/siebenmann/go-kstat" |
25 | ) | 26 | ) |
@@ -30,13 +31,14 @@ import "C" | |||
30 | type cpuFreqCollector struct { | 31 | type cpuFreqCollector struct { |
31 | cpuFreq *prometheus.Desc | 32 | cpuFreq *prometheus.Desc |
32 | cpuFreqMax *prometheus.Desc | 33 | cpuFreqMax *prometheus.Desc |
34 | logger log.Logger | ||
33 | } | 35 | } |
34 | 36 | ||
35 | func init() { | 37 | func init() { |
36 | registerCollector("cpufreq", defaultEnabled, NewCpuFreqCollector) | 38 | registerCollector("cpufreq", defaultEnabled, NewCpuFreqCollector) |
37 | } | 39 | } |
38 | 40 | ||
39 | func NewFreqCpuCollector() (Collector, error) { | 41 | func NewFreqCpuCollector(logger log.Logger) (Collector, error) { |
40 | return &cpuFreqCollector{ | 42 | return &cpuFreqCollector{ |
41 | cpuFreq: prometheus.NewDesc( | 43 | cpuFreq: prometheus.NewDesc( |
42 | prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_hertz"), | 44 | prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_hertz"), |
@@ -48,6 +50,7 @@ func NewFreqCpuCollector() (Collector, error) { | |||
48 | "Maximum cpu thread frequency in hertz.", | 50 | "Maximum cpu thread frequency in hertz.", |
49 | []string{"cpu"}, nil, | 51 | []string{"cpu"}, nil, |
50 | ), | 52 | ), |
53 | logger: logger, | ||
51 | }, nil | 54 | }, nil |
52 | } | 55 | } |
53 | 56 | ||
diff --git a/collector/devstat_dragonfly.go b/collector/devstat_dragonfly.go index d2cc6cd..69e24ba 100644 --- a/collector/devstat_dragonfly.go +++ b/collector/devstat_dragonfly.go | |||
@@ -19,6 +19,7 @@ import ( | |||
19 | "errors" | 19 | "errors" |
20 | "fmt" | 20 | "fmt" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | ) | 24 | ) |
24 | 25 | ||
@@ -96,6 +97,7 @@ type devstatCollector struct { | |||
96 | bytesDesc *prometheus.Desc | 97 | bytesDesc *prometheus.Desc |
97 | transfersDesc *prometheus.Desc | 98 | transfersDesc *prometheus.Desc |
98 | blocksDesc *prometheus.Desc | 99 | blocksDesc *prometheus.Desc |
100 | logger log.Logger | ||
99 | } | 101 | } |
100 | 102 | ||
101 | func init() { | 103 | func init() { |
@@ -103,7 +105,7 @@ func init() { | |||
103 | } | 105 | } |
104 | 106 | ||
105 | // NewDevstatCollector returns a new Collector exposing Device stats. | 107 | // NewDevstatCollector returns a new Collector exposing Device stats. |
106 | func NewDevstatCollector() (Collector, error) { | 108 | func NewDevstatCollector(logger log.Logger) (Collector, error) { |
107 | return &devstatCollector{ | 109 | return &devstatCollector{ |
108 | bytesDesc: prometheus.NewDesc( | 110 | bytesDesc: prometheus.NewDesc( |
109 | prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"), | 111 | prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"), |
@@ -120,6 +122,7 @@ func NewDevstatCollector() (Collector, error) { | |||
120 | "The total number of bytes given in terms of the devices blocksize.", | 122 | "The total number of bytes given in terms of the devices blocksize.", |
121 | []string{"device"}, nil, | 123 | []string{"device"}, nil, |
122 | ), | 124 | ), |
125 | logger: logger, | ||
123 | }, nil | 126 | }, nil |
124 | } | 127 | } |
125 | 128 | ||
diff --git a/collector/devstat_freebsd.go b/collector/devstat_freebsd.go index d394f34..dfa18d1 100644 --- a/collector/devstat_freebsd.go +++ b/collector/devstat_freebsd.go | |||
@@ -21,6 +21,7 @@ import ( | |||
21 | "sync" | 21 | "sync" |
22 | "unsafe" | 22 | "unsafe" |
23 | 23 | ||
24 | "github.com/go-kit/kit/log" | ||
24 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
25 | ) | 26 | ) |
26 | 27 | ||
@@ -41,6 +42,7 @@ type devstatCollector struct { | |||
41 | duration typedDesc | 42 | duration typedDesc |
42 | busyTime typedDesc | 43 | busyTime typedDesc |
43 | blocks typedDesc | 44 | blocks typedDesc |
45 | logger log.Logger | ||
44 | } | 46 | } |
45 | 47 | ||
46 | func init() { | 48 | func init() { |
@@ -48,7 +50,7 @@ func init() { | |||
48 | } | 50 | } |
49 | 51 | ||
50 | // NewDevstatCollector returns a new Collector exposing Device stats. | 52 | // NewDevstatCollector returns a new Collector exposing Device stats. |
51 | func NewDevstatCollector() (Collector, error) { | 53 | func NewDevstatCollector(logger log.Logger) (Collector, error) { |
52 | return &devstatCollector{ | 54 | return &devstatCollector{ |
53 | devinfo: &C.struct_devinfo{}, | 55 | devinfo: &C.struct_devinfo{}, |
54 | bytes: typedDesc{prometheus.NewDesc( | 56 | bytes: typedDesc{prometheus.NewDesc( |
@@ -76,6 +78,7 @@ func NewDevstatCollector() (Collector, error) { | |||
76 | "The total number of blocks transferred.", | 78 | "The total number of blocks transferred.", |
77 | []string{"device"}, nil, | 79 | []string{"device"}, nil, |
78 | ), prometheus.CounterValue}, | 80 | ), prometheus.CounterValue}, |
81 | logger: logger, | ||
79 | }, nil | 82 | }, nil |
80 | } | 83 | } |
81 | 84 | ||
diff --git a/collector/diskstats_darwin.go b/collector/diskstats_darwin.go index 2c76582..8b11812 100644 --- a/collector/diskstats_darwin.go +++ b/collector/diskstats_darwin.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/lufia/iostat" | 22 | "github.com/lufia/iostat" |
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | ) | 24 | ) |
@@ -28,7 +29,8 @@ type typedDescFunc struct { | |||
28 | } | 29 | } |
29 | 30 | ||
30 | type diskstatsCollector struct { | 31 | type diskstatsCollector struct { |
31 | descs []typedDescFunc | 32 | descs []typedDescFunc |
33 | logger log.Logger | ||
32 | } | 34 | } |
33 | 35 | ||
34 | func init() { | 36 | func init() { |
@@ -36,7 +38,7 @@ func init() { | |||
36 | } | 38 | } |
37 | 39 | ||
38 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. | 40 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. |
39 | func NewDiskstatsCollector() (Collector, error) { | 41 | func NewDiskstatsCollector(logger log.Logger) (Collector, error) { |
40 | var diskLabelNames = []string{"device"} | 42 | var diskLabelNames = []string{"device"} |
41 | 43 | ||
42 | return &diskstatsCollector{ | 44 | return &diskstatsCollector{ |
@@ -124,6 +126,7 @@ func NewDiskstatsCollector() (Collector, error) { | |||
124 | }, | 126 | }, |
125 | }, | 127 | }, |
126 | }, | 128 | }, |
129 | logger: logger, | ||
127 | }, nil | 130 | }, nil |
128 | } | 131 | } |
129 | 132 | ||
diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 32bb90c..5d71422 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go | |||
@@ -24,8 +24,9 @@ import ( | |||
24 | "strconv" | 24 | "strconv" |
25 | "strings" | 25 | "strings" |
26 | 26 | ||
27 | "github.com/go-kit/kit/log" | ||
28 | "github.com/go-kit/kit/log/level" | ||
27 | "github.com/prometheus/client_golang/prometheus" | 29 | "github.com/prometheus/client_golang/prometheus" |
28 | "github.com/prometheus/common/log" | ||
29 | "gopkg.in/alecthomas/kingpin.v2" | 30 | "gopkg.in/alecthomas/kingpin.v2" |
30 | ) | 31 | ) |
31 | 32 | ||
@@ -54,6 +55,7 @@ func (d *typedFactorDesc) mustNewConstMetric(value float64, labels ...string) pr | |||
54 | type diskstatsCollector struct { | 55 | type diskstatsCollector struct { |
55 | ignoredDevicesPattern *regexp.Regexp | 56 | ignoredDevicesPattern *regexp.Regexp |
56 | descs []typedFactorDesc | 57 | descs []typedFactorDesc |
58 | logger log.Logger | ||
57 | } | 59 | } |
58 | 60 | ||
59 | func init() { | 61 | func init() { |
@@ -62,7 +64,7 @@ func init() { | |||
62 | 64 | ||
63 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. | 65 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. |
64 | // Docs from https://www.kernel.org/doc/Documentation/iostats.txt | 66 | // Docs from https://www.kernel.org/doc/Documentation/iostats.txt |
65 | func NewDiskstatsCollector() (Collector, error) { | 67 | func NewDiskstatsCollector(logger log.Logger) (Collector, error) { |
66 | var diskLabelNames = []string{"device"} | 68 | var diskLabelNames = []string{"device"} |
67 | 69 | ||
68 | return &diskstatsCollector{ | 70 | return &diskstatsCollector{ |
@@ -178,6 +180,7 @@ func NewDiskstatsCollector() (Collector, error) { | |||
178 | factor: .001, | 180 | factor: .001, |
179 | }, | 181 | }, |
180 | }, | 182 | }, |
183 | logger: logger, | ||
181 | }, nil | 184 | }, nil |
182 | } | 185 | } |
183 | 186 | ||
@@ -189,7 +192,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { | |||
189 | 192 | ||
190 | for dev, stats := range diskStats { | 193 | for dev, stats := range diskStats { |
191 | if c.ignoredDevicesPattern.MatchString(dev) { | 194 | if c.ignoredDevicesPattern.MatchString(dev) { |
192 | log.Debugf("Ignoring device: %s", dev) | 195 | level.Debug(c.logger).Log("msg", "Ignoring device", "device", dev) |
193 | continue | 196 | continue |
194 | } | 197 | } |
195 | 198 | ||
diff --git a/collector/diskstats_openbsd.go b/collector/diskstats_openbsd.go index f17e2a8..3385f37 100644 --- a/collector/diskstats_openbsd.go +++ b/collector/diskstats_openbsd.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "unsafe" | 19 | "unsafe" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | "golang.org/x/sys/unix" | 23 | "golang.org/x/sys/unix" |
23 | ) | 24 | ) |
@@ -34,6 +35,7 @@ type diskstatsCollector struct { | |||
34 | wxfer typedDesc | 35 | wxfer typedDesc |
35 | wbytes typedDesc | 36 | wbytes typedDesc |
36 | time typedDesc | 37 | time typedDesc |
38 | logger log.Logger | ||
37 | } | 39 | } |
38 | 40 | ||
39 | func init() { | 41 | func init() { |
@@ -41,13 +43,14 @@ func init() { | |||
41 | } | 43 | } |
42 | 44 | ||
43 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. | 45 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. |
44 | func NewDiskstatsCollector() (Collector, error) { | 46 | func NewDiskstatsCollector(logger log.Logger) (Collector, error) { |
45 | return &diskstatsCollector{ | 47 | return &diskstatsCollector{ |
46 | rxfer: typedDesc{readsCompletedDesc, prometheus.CounterValue}, | 48 | rxfer: typedDesc{readsCompletedDesc, prometheus.CounterValue}, |
47 | rbytes: typedDesc{readBytesDesc, prometheus.CounterValue}, | 49 | rbytes: typedDesc{readBytesDesc, prometheus.CounterValue}, |
48 | wxfer: typedDesc{writesCompletedDesc, prometheus.CounterValue}, | 50 | wxfer: typedDesc{writesCompletedDesc, prometheus.CounterValue}, |
49 | wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue}, | 51 | wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue}, |
50 | time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue}, | 52 | time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue}, |
53 | logger: logger, | ||
51 | }, nil | 54 | }, nil |
52 | } | 55 | } |
53 | 56 | ||
diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go index 521f2e2..5a340b9 100644 --- a/collector/drbd_linux.go +++ b/collector/drbd_linux.go | |||
@@ -20,8 +20,9 @@ import ( | |||
20 | "strconv" | 20 | "strconv" |
21 | "strings" | 21 | "strings" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/common/log" | ||
25 | ) | 26 | ) |
26 | 27 | ||
27 | // Numerical metric provided by /proc/drbd. | 28 | // Numerical metric provided by /proc/drbd. |
@@ -74,13 +75,14 @@ type drbdCollector struct { | |||
74 | numerical map[string]drbdNumericalMetric | 75 | numerical map[string]drbdNumericalMetric |
75 | stringPair map[string]drbdStringPairMetric | 76 | stringPair map[string]drbdStringPairMetric |
76 | connected *prometheus.Desc | 77 | connected *prometheus.Desc |
78 | logger log.Logger | ||
77 | } | 79 | } |
78 | 80 | ||
79 | func init() { | 81 | func init() { |
80 | registerCollector("drbd", defaultDisabled, newDRBDCollector) | 82 | registerCollector("drbd", defaultDisabled, newDRBDCollector) |
81 | } | 83 | } |
82 | 84 | ||
83 | func newDRBDCollector() (Collector, error) { | 85 | func newDRBDCollector(logger log.Logger) (Collector, error) { |
84 | return &drbdCollector{ | 86 | return &drbdCollector{ |
85 | numerical: map[string]drbdNumericalMetric{ | 87 | numerical: map[string]drbdNumericalMetric{ |
86 | "ns": newDRBDNumericalMetric( | 88 | "ns": newDRBDNumericalMetric( |
@@ -176,6 +178,7 @@ func newDRBDCollector() (Collector, error) { | |||
176 | []string{"device"}, | 178 | []string{"device"}, |
177 | nil, | 179 | nil, |
178 | ), | 180 | ), |
181 | logger: logger, | ||
179 | }, nil | 182 | }, nil |
180 | } | 183 | } |
181 | 184 | ||
@@ -184,7 +187,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { | |||
184 | file, err := os.Open(statsFile) | 187 | file, err := os.Open(statsFile) |
185 | if err != nil { | 188 | if err != nil { |
186 | if os.IsNotExist(err) { | 189 | if os.IsNotExist(err) { |
187 | log.Debugf("drbd: %s does not exist, skipping: %s", statsFile, err) | 190 | level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err) |
188 | return nil | 191 | return nil |
189 | } | 192 | } |
190 | 193 | ||
@@ -201,7 +204,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { | |||
201 | 204 | ||
202 | kv := strings.Split(field, ":") | 205 | kv := strings.Split(field, ":") |
203 | if len(kv) != 2 { | 206 | if len(kv) != 2 { |
204 | log.Debugf("drbd: skipping invalid key:value pair %q", field) | 207 | level.Debug(c.logger).Log("msg", "skipping invalid key:value pair", "field", field) |
205 | continue | 208 | continue |
206 | } | 209 | } |
207 | 210 | ||
@@ -267,7 +270,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { | |||
267 | continue | 270 | continue |
268 | } | 271 | } |
269 | 272 | ||
270 | log.Debugf("drbd: unhandled key-value pair: [%s: %q]", kv[0], kv[1]) | 273 | level.Debug(c.logger).Log("msg", "unhandled key-value pair", "key", kv[0], "value", kv[1]) |
271 | } | 274 | } |
272 | 275 | ||
273 | return scanner.Err() | 276 | return scanner.Err() |
diff --git a/collector/edac_linux.go b/collector/edac_linux.go index de33873..91b9510 100644 --- a/collector/edac_linux.go +++ b/collector/edac_linux.go | |||
@@ -20,6 +20,7 @@ import ( | |||
20 | "path/filepath" | 20 | "path/filepath" |
21 | "regexp" | 21 | "regexp" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | ) | 25 | ) |
25 | 26 | ||
@@ -37,6 +38,7 @@ type edacCollector struct { | |||
37 | ueCount *prometheus.Desc | 38 | ueCount *prometheus.Desc |
38 | csRowCECount *prometheus.Desc | 39 | csRowCECount *prometheus.Desc |
39 | csRowUECount *prometheus.Desc | 40 | csRowUECount *prometheus.Desc |
41 | logger log.Logger | ||
40 | } | 42 | } |
41 | 43 | ||
42 | func init() { | 44 | func init() { |
@@ -44,7 +46,7 @@ func init() { | |||
44 | } | 46 | } |
45 | 47 | ||
46 | // NewEdacCollector returns a new Collector exposing edac stats. | 48 | // NewEdacCollector returns a new Collector exposing edac stats. |
47 | func NewEdacCollector() (Collector, error) { | 49 | func NewEdacCollector(logger log.Logger) (Collector, error) { |
48 | return &edacCollector{ | 50 | return &edacCollector{ |
49 | ceCount: prometheus.NewDesc( | 51 | ceCount: prometheus.NewDesc( |
50 | prometheus.BuildFQName(namespace, edacSubsystem, "correctable_errors_total"), | 52 | prometheus.BuildFQName(namespace, edacSubsystem, "correctable_errors_total"), |
@@ -66,6 +68,7 @@ func NewEdacCollector() (Collector, error) { | |||
66 | "Total uncorrectable memory errors for this csrow.", | 68 | "Total uncorrectable memory errors for this csrow.", |
67 | []string{"controller", "csrow"}, nil, | 69 | []string{"controller", "csrow"}, nil, |
68 | ), | 70 | ), |
71 | logger: logger, | ||
69 | }, nil | 72 | }, nil |
70 | } | 73 | } |
71 | 74 | ||
diff --git a/collector/entropy_linux.go b/collector/entropy_linux.go index 455615b..e68eb95 100644 --- a/collector/entropy_linux.go +++ b/collector/entropy_linux.go | |||
@@ -18,11 +18,13 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | ) | 23 | ) |
23 | 24 | ||
24 | type entropyCollector struct { | 25 | type entropyCollector struct { |
25 | entropyAvail *prometheus.Desc | 26 | entropyAvail *prometheus.Desc |
27 | logger log.Logger | ||
26 | } | 28 | } |
27 | 29 | ||
28 | func init() { | 30 | func init() { |
@@ -30,13 +32,14 @@ func init() { | |||
30 | } | 32 | } |
31 | 33 | ||
32 | // NewEntropyCollector returns a new Collector exposing entropy stats. | 34 | // NewEntropyCollector returns a new Collector exposing entropy stats. |
33 | func NewEntropyCollector() (Collector, error) { | 35 | func NewEntropyCollector(logger log.Logger) (Collector, error) { |
34 | return &entropyCollector{ | 36 | return &entropyCollector{ |
35 | entropyAvail: prometheus.NewDesc( | 37 | entropyAvail: prometheus.NewDesc( |
36 | prometheus.BuildFQName(namespace, "", "entropy_available_bits"), | 38 | prometheus.BuildFQName(namespace, "", "entropy_available_bits"), |
37 | "Bits of available entropy.", | 39 | "Bits of available entropy.", |
38 | nil, nil, | 40 | nil, nil, |
39 | ), | 41 | ), |
42 | logger: logger, | ||
40 | }, nil | 43 | }, nil |
41 | } | 44 | } |
42 | 45 | ||
diff --git a/collector/exec_bsd.go b/collector/exec_bsd.go index e4b780b..c7bcb74 100644 --- a/collector/exec_bsd.go +++ b/collector/exec_bsd.go | |||
@@ -17,11 +17,13 @@ | |||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "github.com/go-kit/kit/log" | ||
20 | "github.com/prometheus/client_golang/prometheus" | 21 | "github.com/prometheus/client_golang/prometheus" |
21 | ) | 22 | ) |
22 | 23 | ||
23 | type execCollector struct { | 24 | type execCollector struct { |
24 | sysctls []bsdSysctl | 25 | sysctls []bsdSysctl |
26 | logger log.Logger | ||
25 | } | 27 | } |
26 | 28 | ||
27 | func init() { | 29 | func init() { |
@@ -29,7 +31,7 @@ func init() { | |||
29 | } | 31 | } |
30 | 32 | ||
31 | // NewExecCollector returns a new Collector exposing system execution statistics. | 33 | // NewExecCollector returns a new Collector exposing system execution statistics. |
32 | func NewExecCollector() (Collector, error) { | 34 | func NewExecCollector(logger log.Logger) (Collector, error) { |
33 | // From sys/vm/vm_meter.c: | 35 | // From sys/vm/vm_meter.c: |
34 | // All are of type CTLTYPE_UINT. | 36 | // All are of type CTLTYPE_UINT. |
35 | // | 37 | // |
@@ -73,6 +75,7 @@ func NewExecCollector() (Collector, error) { | |||
73 | mib: "vm.stats.vm.v_forks", | 75 | mib: "vm.stats.vm.v_forks", |
74 | }, | 76 | }, |
75 | }, | 77 | }, |
78 | logger: logger, | ||
76 | }, nil | 79 | }, nil |
77 | } | 80 | } |
78 | 81 | ||
diff --git a/collector/filefd_linux.go b/collector/filefd_linux.go index 1d34889..f8d3fce 100644 --- a/collector/filefd_linux.go +++ b/collector/filefd_linux.go | |||
@@ -22,6 +22,7 @@ import ( | |||
22 | "os" | 22 | "os" |
23 | "strconv" | 23 | "strconv" |
24 | 24 | ||
25 | "github.com/go-kit/kit/log" | ||
25 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
26 | ) | 27 | ) |
27 | 28 | ||
@@ -29,15 +30,17 @@ const ( | |||
29 | fileFDStatSubsystem = "filefd" | 30 | fileFDStatSubsystem = "filefd" |
30 | ) | 31 | ) |
31 | 32 | ||
32 | type fileFDStatCollector struct{} | 33 | type fileFDStatCollector struct { |
34 | logger log.Logger | ||
35 | } | ||
33 | 36 | ||
34 | func init() { | 37 | func init() { |
35 | registerCollector(fileFDStatSubsystem, defaultEnabled, NewFileFDStatCollector) | 38 | registerCollector(fileFDStatSubsystem, defaultEnabled, NewFileFDStatCollector) |
36 | } | 39 | } |
37 | 40 | ||
38 | // NewFileFDStatCollector returns a new Collector exposing file-nr stats. | 41 | // NewFileFDStatCollector returns a new Collector exposing file-nr stats. |
39 | func NewFileFDStatCollector() (Collector, error) { | 42 | func NewFileFDStatCollector(logger log.Logger) (Collector, error) { |
40 | return &fileFDStatCollector{}, nil | 43 | return &fileFDStatCollector{logger}, nil |
41 | } | 44 | } |
42 | 45 | ||
43 | func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error { | 46 | func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) error { |
diff --git a/collector/filesystem_bsd.go b/collector/filesystem_bsd.go index b9aa1cc..7b30904 100644 --- a/collector/filesystem_bsd.go +++ b/collector/filesystem_bsd.go | |||
@@ -20,7 +20,7 @@ import ( | |||
20 | "errors" | 20 | "errors" |
21 | "unsafe" | 21 | "unsafe" |
22 | 22 | ||
23 | "github.com/prometheus/common/log" | 23 | "github.com/go-kit/kit/log/level" |
24 | ) | 24 | ) |
25 | 25 | ||
26 | /* | 26 | /* |
@@ -50,14 +50,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { | |||
50 | for i := 0; i < int(count); i++ { | 50 | for i := 0; i < int(count); i++ { |
51 | mountpoint := C.GoString(&mnt[i].f_mntonname[0]) | 51 | mountpoint := C.GoString(&mnt[i].f_mntonname[0]) |
52 | if c.ignoredMountPointsPattern.MatchString(mountpoint) { | 52 | if c.ignoredMountPointsPattern.MatchString(mountpoint) { |
53 | log.Debugf("Ignoring mount point: %s", mountpoint) | 53 | level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) |
54 | continue | 54 | continue |
55 | } | 55 | } |
56 | 56 | ||
57 | device := C.GoString(&mnt[i].f_mntfromname[0]) | 57 | device := C.GoString(&mnt[i].f_mntfromname[0]) |
58 | fstype := C.GoString(&mnt[i].f_fstypename[0]) | 58 | fstype := C.GoString(&mnt[i].f_fstypename[0]) |
59 | if c.ignoredFSTypesPattern.MatchString(fstype) { | 59 | if c.ignoredFSTypesPattern.MatchString(fstype) { |
60 | log.Debugf("Ignoring fs type: %s", fstype) | 60 | level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) |
61 | continue | 61 | continue |
62 | } | 62 | } |
63 | 63 | ||
diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index da4cecd..6971f44 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go | |||
@@ -19,6 +19,7 @@ package collector | |||
19 | import ( | 19 | import ( |
20 | "regexp" | 20 | "regexp" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | "gopkg.in/alecthomas/kingpin.v2" | 24 | "gopkg.in/alecthomas/kingpin.v2" |
24 | ) | 25 | ) |
@@ -48,6 +49,7 @@ type filesystemCollector struct { | |||
48 | sizeDesc, freeDesc, availDesc *prometheus.Desc | 49 | sizeDesc, freeDesc, availDesc *prometheus.Desc |
49 | filesDesc, filesFreeDesc *prometheus.Desc | 50 | filesDesc, filesFreeDesc *prometheus.Desc |
50 | roDesc, deviceErrorDesc *prometheus.Desc | 51 | roDesc, deviceErrorDesc *prometheus.Desc |
52 | logger log.Logger | ||
51 | } | 53 | } |
52 | 54 | ||
53 | type filesystemLabels struct { | 55 | type filesystemLabels struct { |
@@ -66,7 +68,7 @@ func init() { | |||
66 | } | 68 | } |
67 | 69 | ||
68 | // NewFilesystemCollector returns a new Collector exposing filesystems stats. | 70 | // NewFilesystemCollector returns a new Collector exposing filesystems stats. |
69 | func NewFilesystemCollector() (Collector, error) { | 71 | func NewFilesystemCollector(logger log.Logger) (Collector, error) { |
70 | subsystem := "filesystem" | 72 | subsystem := "filesystem" |
71 | mountPointPattern := regexp.MustCompile(*ignoredMountPoints) | 73 | mountPointPattern := regexp.MustCompile(*ignoredMountPoints) |
72 | filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes) | 74 | filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes) |
@@ -123,6 +125,7 @@ func NewFilesystemCollector() (Collector, error) { | |||
123 | filesFreeDesc: filesFreeDesc, | 125 | filesFreeDesc: filesFreeDesc, |
124 | roDesc: roDesc, | 126 | roDesc: roDesc, |
125 | deviceErrorDesc: deviceErrorDesc, | 127 | deviceErrorDesc: deviceErrorDesc, |
128 | logger: logger, | ||
126 | }, nil | 129 | }, nil |
127 | } | 130 | } |
128 | 131 | ||
diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index 47c4833..8fceba7 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go | |||
@@ -19,7 +19,7 @@ import ( | |||
19 | "bytes" | 19 | "bytes" |
20 | "unsafe" | 20 | "unsafe" |
21 | 21 | ||
22 | "github.com/prometheus/common/log" | 22 | "github.com/go-kit/kit/log/level" |
23 | "golang.org/x/sys/unix" | 23 | "golang.org/x/sys/unix" |
24 | ) | 24 | ) |
25 | 25 | ||
@@ -54,14 +54,14 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
54 | for _, fs := range buf { | 54 | for _, fs := range buf { |
55 | mountpoint := gostring(fs.Mntonname[:]) | 55 | mountpoint := gostring(fs.Mntonname[:]) |
56 | if c.ignoredMountPointsPattern.MatchString(mountpoint) { | 56 | if c.ignoredMountPointsPattern.MatchString(mountpoint) { |
57 | log.Debugf("Ignoring mount point: %s", mountpoint) | 57 | level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) |
58 | continue | 58 | continue |
59 | } | 59 | } |
60 | 60 | ||
61 | device := gostring(fs.Mntfromname[:]) | 61 | device := gostring(fs.Mntfromname[:]) |
62 | fstype := gostring(fs.Fstypename[:]) | 62 | fstype := gostring(fs.Fstypename[:]) |
63 | if c.ignoredFSTypesPattern.MatchString(fstype) { | 63 | if c.ignoredFSTypesPattern.MatchString(fstype) { |
64 | log.Debugf("Ignoring fs type: %s", fstype) | 64 | level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) |
65 | continue | 65 | continue |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 98e51b8..e83b27a 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go | |||
@@ -24,9 +24,10 @@ import ( | |||
24 | "sync" | 24 | "sync" |
25 | "time" | 25 | "time" |
26 | 26 | ||
27 | "github.com/prometheus/common/log" | 27 | "github.com/go-kit/kit/log" |
28 | "github.com/go-kit/kit/log/level" | ||
28 | "golang.org/x/sys/unix" | 29 | "golang.org/x/sys/unix" |
29 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 30 | "gopkg.in/alecthomas/kingpin.v2" |
30 | ) | 31 | ) |
31 | 32 | ||
32 | const ( | 33 | const ( |
@@ -42,18 +43,18 @@ var stuckMountsMtx = &sync.Mutex{} | |||
42 | 43 | ||
43 | // GetStats returns filesystem stats. | 44 | // GetStats returns filesystem stats. |
44 | func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | 45 | func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { |
45 | mps, err := mountPointDetails() | 46 | mps, err := mountPointDetails(c.logger) |
46 | if err != nil { | 47 | if err != nil { |
47 | return nil, err | 48 | return nil, err |
48 | } | 49 | } |
49 | stats := []filesystemStats{} | 50 | stats := []filesystemStats{} |
50 | for _, labels := range mps { | 51 | for _, labels := range mps { |
51 | if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) { | 52 | if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) { |
52 | log.Debugf("Ignoring mount point: %s", labels.mountPoint) | 53 | level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", labels.mountPoint) |
53 | continue | 54 | continue |
54 | } | 55 | } |
55 | if c.ignoredFSTypesPattern.MatchString(labels.fsType) { | 56 | if c.ignoredFSTypesPattern.MatchString(labels.fsType) { |
56 | log.Debugf("Ignoring fs type: %s", labels.fsType) | 57 | level.Debug(c.logger).Log("msg", "Ignoring fs", "type", labels.fsType) |
57 | continue | 58 | continue |
58 | } | 59 | } |
59 | stuckMountsMtx.Lock() | 60 | stuckMountsMtx.Lock() |
@@ -62,7 +63,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
62 | labels: labels, | 63 | labels: labels, |
63 | deviceError: 1, | 64 | deviceError: 1, |
64 | }) | 65 | }) |
65 | log.Debugf("Mount point %q is in an unresponsive state", labels.mountPoint) | 66 | level.Debug(c.logger).Log("msg", "Mount point is in an unresponsive state", "mountpoint", labels.mountPoint) |
66 | stuckMountsMtx.Unlock() | 67 | stuckMountsMtx.Unlock() |
67 | continue | 68 | continue |
68 | } | 69 | } |
@@ -71,7 +72,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
71 | // The success channel is used do tell the "watcher" that the stat | 72 | // The success channel is used do tell the "watcher" that the stat |
72 | // finished successfully. The channel is closed on success. | 73 | // finished successfully. The channel is closed on success. |
73 | success := make(chan struct{}) | 74 | success := make(chan struct{}) |
74 | go stuckMountWatcher(labels.mountPoint, success) | 75 | go stuckMountWatcher(labels.mountPoint, success, c.logger) |
75 | 76 | ||
76 | buf := new(unix.Statfs_t) | 77 | buf := new(unix.Statfs_t) |
77 | err = unix.Statfs(rootfsFilePath(labels.mountPoint), buf) | 78 | err = unix.Statfs(rootfsFilePath(labels.mountPoint), buf) |
@@ -79,7 +80,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
79 | close(success) | 80 | close(success) |
80 | // If the mount has been marked as stuck, unmark it and log it's recovery. | 81 | // If the mount has been marked as stuck, unmark it and log it's recovery. |
81 | if _, ok := stuckMounts[labels.mountPoint]; ok { | 82 | if _, ok := stuckMounts[labels.mountPoint]; ok { |
82 | log.Debugf("Mount point %q has recovered, monitoring will resume", labels.mountPoint) | 83 | level.Debug(c.logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", labels.mountPoint) |
83 | delete(stuckMounts, labels.mountPoint) | 84 | delete(stuckMounts, labels.mountPoint) |
84 | } | 85 | } |
85 | stuckMountsMtx.Unlock() | 86 | stuckMountsMtx.Unlock() |
@@ -89,7 +90,8 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
89 | labels: labels, | 90 | labels: labels, |
90 | deviceError: 1, | 91 | deviceError: 1, |
91 | }) | 92 | }) |
92 | log.Debugf("Error on statfs() system call for %q: %s", rootfsFilePath(labels.mountPoint), err) | 93 | |
94 | level.Debug(c.logger).Log("msg", "Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err) | ||
93 | continue | 95 | continue |
94 | } | 96 | } |
95 | 97 | ||
@@ -117,7 +119,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
117 | // stuckMountWatcher listens on the given success channel and if the channel closes | 119 | // stuckMountWatcher listens on the given success channel and if the channel closes |
118 | // then the watcher does nothing. If instead the timeout is reached, the | 120 | // then the watcher does nothing. If instead the timeout is reached, the |
119 | // mount point that is being watched is marked as stuck. | 121 | // mount point that is being watched is marked as stuck. |
120 | func stuckMountWatcher(mountPoint string, success chan struct{}) { | 122 | func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logger) { |
121 | select { | 123 | select { |
122 | case <-success: | 124 | case <-success: |
123 | // Success | 125 | // Success |
@@ -128,18 +130,18 @@ func stuckMountWatcher(mountPoint string, success chan struct{}) { | |||
128 | case <-success: | 130 | case <-success: |
129 | // Success came in just after the timeout was reached, don't label the mount as stuck | 131 | // Success came in just after the timeout was reached, don't label the mount as stuck |
130 | default: | 132 | default: |
131 | log.Debugf("Mount point %q timed out, it is being labeled as stuck and will not be monitored", mountPoint) | 133 | level.Debug(logger).Log("msg", "Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint) |
132 | stuckMounts[mountPoint] = struct{}{} | 134 | stuckMounts[mountPoint] = struct{}{} |
133 | } | 135 | } |
134 | stuckMountsMtx.Unlock() | 136 | stuckMountsMtx.Unlock() |
135 | } | 137 | } |
136 | } | 138 | } |
137 | 139 | ||
138 | func mountPointDetails() ([]filesystemLabels, error) { | 140 | func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { |
139 | file, err := os.Open(procFilePath("1/mounts")) | 141 | file, err := os.Open(procFilePath("1/mounts")) |
140 | if os.IsNotExist(err) { | 142 | if os.IsNotExist(err) { |
141 | // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. | 143 | // Fallback to `/proc/mounts` if `/proc/1/mounts` is missing due hidepid. |
142 | log.Debugf("Got %q reading root mounts, falling back to system mounts", err) | 144 | level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to system mounts", "err", err) |
143 | file, err = os.Open(procFilePath("mounts")) | 145 | file, err = os.Open(procFilePath("mounts")) |
144 | } | 146 | } |
145 | if err != nil { | 147 | if err != nil { |
diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 6271c19..973cd14 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "github.com/go-kit/kit/log" | ||
19 | "strings" | 20 | "strings" |
20 | "testing" | 21 | "testing" |
21 | 22 | ||
@@ -80,7 +81,7 @@ func TestMountPointDetails(t *testing.T) { | |||
80 | "/var/lib/kubelet/plugins/kubernetes.io/vsphere-volume/mounts/[vsanDatastore] bafb9e5a-8856-7e6c-699c-801844e77a4a/kubernetes-dynamic-pvc-3eba5bba-48a3-11e8-89ab-005056b92113.vmdk": "", | 81 | "/var/lib/kubelet/plugins/kubernetes.io/vsphere-volume/mounts/[vsanDatastore] bafb9e5a-8856-7e6c-699c-801844e77a4a/kubernetes-dynamic-pvc-3eba5bba-48a3-11e8-89ab-005056b92113.vmdk": "", |
81 | } | 82 | } |
82 | 83 | ||
83 | filesystems, err := mountPointDetails() | 84 | filesystems, err := mountPointDetails(log.NewNopLogger()) |
84 | if err != nil { | 85 | if err != nil { |
85 | t.Log(err) | 86 | t.Log(err) |
86 | } | 87 | } |
@@ -101,7 +102,7 @@ func TestMountsFallback(t *testing.T) { | |||
101 | "/": "", | 102 | "/": "", |
102 | } | 103 | } |
103 | 104 | ||
104 | filesystems, err := mountPointDetails() | 105 | filesystems, err := mountPointDetails(log.NewNopLogger()) |
105 | if err != nil { | 106 | if err != nil { |
106 | t.Log(err) | 107 | t.Log(err) |
107 | } | 108 | } |
@@ -129,7 +130,7 @@ func TestPathRootfs(t *testing.T) { | |||
129 | "/sys/fs/cgroup": "", | 130 | "/sys/fs/cgroup": "", |
130 | } | 131 | } |
131 | 132 | ||
132 | filesystems, err := mountPointDetails() | 133 | filesystems, err := mountPointDetails(log.NewNopLogger()) |
133 | if err != nil { | 134 | if err != nil { |
134 | t.Log(err) | 135 | t.Log(err) |
135 | } | 136 | } |
diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index a6eb3b9..31dbd22 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go | |||
@@ -24,8 +24,9 @@ import ( | |||
24 | "strconv" | 24 | "strconv" |
25 | "strings" | 25 | "strings" |
26 | 26 | ||
27 | "github.com/go-kit/kit/log" | ||
28 | "github.com/go-kit/kit/log/level" | ||
27 | "github.com/prometheus/client_golang/prometheus" | 29 | "github.com/prometheus/client_golang/prometheus" |
28 | "github.com/prometheus/common/log" | ||
29 | "golang.org/x/sys/unix" | 30 | "golang.org/x/sys/unix" |
30 | ) | 31 | ) |
31 | 32 | ||
@@ -45,12 +46,14 @@ func init() { | |||
45 | registerCollector("hwmon", defaultEnabled, NewHwMonCollector) | 46 | registerCollector("hwmon", defaultEnabled, NewHwMonCollector) |
46 | } | 47 | } |
47 | 48 | ||
48 | type hwMonCollector struct{} | 49 | type hwMonCollector struct { |
50 | logger log.Logger | ||
51 | } | ||
49 | 52 | ||
50 | // NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats | 53 | // NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats |
51 | // (similar to lm-sensors). | 54 | // (similar to lm-sensors). |
52 | func NewHwMonCollector() (Collector, error) { | 55 | func NewHwMonCollector(logger log.Logger) (Collector, error) { |
53 | return &hwMonCollector{}, nil | 56 | return &hwMonCollector{logger}, nil |
54 | } | 57 | } |
55 | 58 | ||
56 | func cleanMetricName(name string) string { | 59 | func cleanMetricName(name string) string { |
@@ -422,7 +425,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error { | |||
422 | hwmonFiles, err := ioutil.ReadDir(hwmonPathName) | 425 | hwmonFiles, err := ioutil.ReadDir(hwmonPathName) |
423 | if err != nil { | 426 | if err != nil { |
424 | if os.IsNotExist(err) { | 427 | if os.IsNotExist(err) { |
425 | log.Debug("hwmon collector metrics are not available for this system") | 428 | level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system") |
426 | return nil | 429 | return nil |
427 | } | 430 | } |
428 | 431 | ||
diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go index 52bf9a2..9d3ff60 100644 --- a/collector/infiniband_linux.go +++ b/collector/infiniband_linux.go | |||
@@ -20,6 +20,7 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/procfs/sysfs" | 25 | "github.com/prometheus/procfs/sysfs" |
25 | ) | 26 | ) |
@@ -27,6 +28,7 @@ import ( | |||
27 | type infinibandCollector struct { | 28 | type infinibandCollector struct { |
28 | fs sysfs.FS | 29 | fs sysfs.FS |
29 | metricDescs map[string]*prometheus.Desc | 30 | metricDescs map[string]*prometheus.Desc |
31 | logger log.Logger | ||
30 | } | 32 | } |
31 | 33 | ||
32 | func init() { | 34 | func init() { |
@@ -34,7 +36,7 @@ func init() { | |||
34 | } | 36 | } |
35 | 37 | ||
36 | // NewInfiniBandCollector returns a new Collector exposing InfiniBand stats. | 38 | // NewInfiniBandCollector returns a new Collector exposing InfiniBand stats. |
37 | func NewInfiniBandCollector() (Collector, error) { | 39 | func NewInfiniBandCollector(logger log.Logger) (Collector, error) { |
38 | var i infinibandCollector | 40 | var i infinibandCollector |
39 | var err error | 41 | var err error |
40 | 42 | ||
@@ -42,6 +44,7 @@ func NewInfiniBandCollector() (Collector, error) { | |||
42 | if err != nil { | 44 | if err != nil { |
43 | return nil, fmt.Errorf("failed to open sysfs: %w", err) | 45 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
44 | } | 46 | } |
47 | i.logger = logger | ||
45 | 48 | ||
46 | // Detailed description for all metrics. | 49 | // Detailed description for all metrics. |
47 | descriptions := map[string]string{ | 50 | descriptions := map[string]string{ |
diff --git a/collector/interrupts_common.go b/collector/interrupts_common.go index 9e48829..e681cfc 100644 --- a/collector/interrupts_common.go +++ b/collector/interrupts_common.go | |||
@@ -16,10 +16,14 @@ | |||
16 | 16 | ||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import "github.com/prometheus/client_golang/prometheus" | 19 | import ( |
20 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | ||
22 | ) | ||
20 | 23 | ||
21 | type interruptsCollector struct { | 24 | type interruptsCollector struct { |
22 | desc typedDesc | 25 | desc typedDesc |
26 | logger log.Logger | ||
23 | } | 27 | } |
24 | 28 | ||
25 | func init() { | 29 | func init() { |
@@ -27,12 +31,13 @@ func init() { | |||
27 | } | 31 | } |
28 | 32 | ||
29 | // NewInterruptsCollector returns a new Collector exposing interrupts stats. | 33 | // NewInterruptsCollector returns a new Collector exposing interrupts stats. |
30 | func NewInterruptsCollector() (Collector, error) { | 34 | func NewInterruptsCollector(logger log.Logger) (Collector, error) { |
31 | return &interruptsCollector{ | 35 | return &interruptsCollector{ |
32 | desc: typedDesc{prometheus.NewDesc( | 36 | desc: typedDesc{prometheus.NewDesc( |
33 | namespace+"_interrupts_total", | 37 | namespace+"_interrupts_total", |
34 | "Interrupt details.", | 38 | "Interrupt details.", |
35 | interruptLabelNames, nil, | 39 | interruptLabelNames, nil, |
36 | ), prometheus.CounterValue}, | 40 | ), prometheus.CounterValue}, |
41 | logger: logger, | ||
37 | }, nil | 42 | }, nil |
38 | } | 43 | } |
diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index 6ac48b1..89469e5 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go | |||
@@ -20,8 +20,9 @@ import ( | |||
20 | "os" | 20 | "os" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/common/log" | ||
25 | "github.com/prometheus/procfs" | 26 | "github.com/prometheus/procfs" |
26 | ) | 27 | ) |
27 | 28 | ||
@@ -30,6 +31,7 @@ type ipvsCollector struct { | |||
30 | fs procfs.FS | 31 | fs procfs.FS |
31 | backendConnectionsActive, backendConnectionsInact, backendWeight typedDesc | 32 | backendConnectionsActive, backendConnectionsInact, backendWeight typedDesc |
32 | connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes typedDesc | 33 | connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes typedDesc |
34 | logger log.Logger | ||
33 | } | 35 | } |
34 | 36 | ||
35 | func init() { | 37 | func init() { |
@@ -38,11 +40,11 @@ func init() { | |||
38 | 40 | ||
39 | // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the | 41 | // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the |
40 | // "procfs" config parameter to override the default proc location (/proc). | 42 | // "procfs" config parameter to override the default proc location (/proc). |
41 | func NewIPVSCollector() (Collector, error) { | 43 | func NewIPVSCollector(logger log.Logger) (Collector, error) { |
42 | return newIPVSCollector() | 44 | return newIPVSCollector(logger) |
43 | } | 45 | } |
44 | 46 | ||
45 | func newIPVSCollector() (*ipvsCollector, error) { | 47 | func newIPVSCollector(logger log.Logger) (*ipvsCollector, error) { |
46 | var ( | 48 | var ( |
47 | ipvsBackendLabelNames = []string{ | 49 | ipvsBackendLabelNames = []string{ |
48 | "local_address", | 50 | "local_address", |
@@ -57,6 +59,7 @@ func newIPVSCollector() (*ipvsCollector, error) { | |||
57 | subsystem = "ipvs" | 59 | subsystem = "ipvs" |
58 | ) | 60 | ) |
59 | 61 | ||
62 | c.logger = logger | ||
60 | c.fs, err = procfs.NewFS(*procPath) | 63 | c.fs, err = procfs.NewFS(*procPath) |
61 | if err != nil { | 64 | if err != nil { |
62 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 65 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -111,7 +114,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { | |||
111 | if err != nil { | 114 | if err != nil { |
112 | // Cannot access ipvs metrics, report no error. | 115 | // Cannot access ipvs metrics, report no error. |
113 | if os.IsNotExist(err) { | 116 | if os.IsNotExist(err) { |
114 | log.Debug("ipvs collector metrics are not available for this system") | 117 | level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system") |
115 | return nil | 118 | return nil |
116 | } | 119 | } |
117 | return fmt.Errorf("could not get IPVS stats: %s", err) | 120 | return fmt.Errorf("could not get IPVS stats: %s", err) |
diff --git a/collector/ipvs_linux_test.go b/collector/ipvs_linux_test.go index 5cb934a..a1c0cba 100644 --- a/collector/ipvs_linux_test.go +++ b/collector/ipvs_linux_test.go | |||
@@ -15,6 +15,7 @@ package collector | |||
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "fmt" | 17 | "fmt" |
18 | "github.com/go-kit/kit/log" | ||
18 | "io/ioutil" | 19 | "io/ioutil" |
19 | "net/http" | 20 | "net/http" |
20 | "net/http/httptest" | 21 | "net/http/httptest" |
@@ -30,7 +31,7 @@ func TestIPVSCollector(t *testing.T) { | |||
30 | if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil { | 31 | if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil { |
31 | t.Fatal(err) | 32 | t.Fatal(err) |
32 | } | 33 | } |
33 | collector, err := newIPVSCollector() | 34 | collector, err := newIPVSCollector(log.NewNopLogger()) |
34 | if err != nil { | 35 | if err != nil { |
35 | t.Fatal(err) | 36 | t.Fatal(err) |
36 | } | 37 | } |
@@ -79,7 +80,7 @@ func TestIPVSCollectorResponse(t *testing.T) { | |||
79 | if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil { | 80 | if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil { |
80 | t.Fatal(err) | 81 | t.Fatal(err) |
81 | } | 82 | } |
82 | collector, err := NewIPVSCollector() | 83 | collector, err := NewIPVSCollector(log.NewNopLogger()) |
83 | if err != nil { | 84 | if err != nil { |
84 | t.Fatal(err) | 85 | t.Fatal(err) |
85 | } | 86 | } |
diff --git a/collector/ksmd_linux.go b/collector/ksmd_linux.go index 857664f..44d6f8d 100644 --- a/collector/ksmd_linux.go +++ b/collector/ksmd_linux.go | |||
@@ -19,6 +19,7 @@ import ( | |||
19 | "fmt" | 19 | "fmt" |
20 | "path/filepath" | 20 | "path/filepath" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | ) | 24 | ) |
24 | 25 | ||
@@ -29,6 +30,7 @@ var ( | |||
29 | 30 | ||
30 | type ksmdCollector struct { | 31 | type ksmdCollector struct { |
31 | metricDescs map[string]*prometheus.Desc | 32 | metricDescs map[string]*prometheus.Desc |
33 | logger log.Logger | ||
32 | } | 34 | } |
33 | 35 | ||
34 | func init() { | 36 | func init() { |
@@ -47,7 +49,7 @@ func getCanonicalMetricName(filename string) string { | |||
47 | } | 49 | } |
48 | 50 | ||
49 | // NewKsmdCollector returns a new Collector exposing kernel/system statistics. | 51 | // NewKsmdCollector returns a new Collector exposing kernel/system statistics. |
50 | func NewKsmdCollector() (Collector, error) { | 52 | func NewKsmdCollector(logger log.Logger) (Collector, error) { |
51 | subsystem := "ksmd" | 53 | subsystem := "ksmd" |
52 | descs := make(map[string]*prometheus.Desc) | 54 | descs := make(map[string]*prometheus.Desc) |
53 | 55 | ||
@@ -56,7 +58,7 @@ func NewKsmdCollector() (Collector, error) { | |||
56 | prometheus.BuildFQName(namespace, subsystem, getCanonicalMetricName(n)), | 58 | prometheus.BuildFQName(namespace, subsystem, getCanonicalMetricName(n)), |
57 | fmt.Sprintf("ksmd '%s' file.", n), nil, nil) | 59 | fmt.Sprintf("ksmd '%s' file.", n), nil, nil) |
58 | } | 60 | } |
59 | return &ksmdCollector{descs}, nil | 61 | return &ksmdCollector{descs, logger}, nil |
60 | } | 62 | } |
61 | 63 | ||
62 | // Update implements Collector and exposes kernel and system statistics. | 64 | // Update implements Collector and exposes kernel and system statistics. |
diff --git a/collector/loadavg.go b/collector/loadavg.go index 5568faa..7c8bcff 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go | |||
@@ -19,12 +19,14 @@ package collector | |||
19 | import ( | 19 | import ( |
20 | "fmt" | 20 | "fmt" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
23 | "github.com/go-kit/kit/log/level" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | ||
24 | ) | 25 | ) |
25 | 26 | ||
26 | type loadavgCollector struct { | 27 | type loadavgCollector struct { |
27 | metric []typedDesc | 28 | metric []typedDesc |
29 | logger log.Logger | ||
28 | } | 30 | } |
29 | 31 | ||
30 | func init() { | 32 | func init() { |
@@ -32,13 +34,14 @@ func init() { | |||
32 | } | 34 | } |
33 | 35 | ||
34 | // NewLoadavgCollector returns a new Collector exposing load average stats. | 36 | // NewLoadavgCollector returns a new Collector exposing load average stats. |
35 | func NewLoadavgCollector() (Collector, error) { | 37 | func NewLoadavgCollector(logger log.Logger) (Collector, error) { |
36 | return &loadavgCollector{ | 38 | return &loadavgCollector{ |
37 | metric: []typedDesc{ | 39 | metric: []typedDesc{ |
38 | {prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue}, | 40 | {prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue}, |
39 | {prometheus.NewDesc(namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue}, | 41 | {prometheus.NewDesc(namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue}, |
40 | {prometheus.NewDesc(namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue}, | 42 | {prometheus.NewDesc(namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue}, |
41 | }, | 43 | }, |
44 | logger: logger, | ||
42 | }, nil | 45 | }, nil |
43 | } | 46 | } |
44 | 47 | ||
@@ -48,7 +51,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { | |||
48 | return fmt.Errorf("couldn't get load: %s", err) | 51 | return fmt.Errorf("couldn't get load: %s", err) |
49 | } | 52 | } |
50 | for i, load := range loads { | 53 | for i, load := range loads { |
51 | log.Debugf("return load %d: %f", i, load) | 54 | level.Debug(c.logger).Log("msg", "return load", "index", i, "load", load) |
52 | ch <- c.metric[i].mustNewConstMetric(load) | 55 | ch <- c.metric[i].mustNewConstMetric(load) |
53 | } | 56 | } |
54 | return err | 57 | return err |
diff --git a/collector/logind_linux.go b/collector/logind_linux.go index ba23f11..fb3cb57 100644 --- a/collector/logind_linux.go +++ b/collector/logind_linux.go | |||
@@ -20,6 +20,7 @@ import ( | |||
20 | "os" | 20 | "os" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/godbus/dbus" | 24 | "github.com/godbus/dbus" |
24 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
25 | ) | 26 | ) |
@@ -43,7 +44,9 @@ var ( | |||
43 | ) | 44 | ) |
44 | ) | 45 | ) |
45 | 46 | ||
46 | type logindCollector struct{} | 47 | type logindCollector struct { |
48 | logger log.Logger | ||
49 | } | ||
47 | 50 | ||
48 | type logindDbus struct { | 51 | type logindDbus struct { |
49 | conn *dbus.Conn | 52 | conn *dbus.Conn |
@@ -82,8 +85,8 @@ func init() { | |||
82 | } | 85 | } |
83 | 86 | ||
84 | // NewLogindCollector returns a new Collector exposing logind statistics. | 87 | // NewLogindCollector returns a new Collector exposing logind statistics. |
85 | func NewLogindCollector() (Collector, error) { | 88 | func NewLogindCollector(logger log.Logger) (Collector, error) { |
86 | return &logindCollector{}, nil | 89 | return &logindCollector{logger}, nil |
87 | } | 90 | } |
88 | 91 | ||
89 | func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { | 92 | func (lc *logindCollector) Update(ch chan<- prometheus.Metric) error { |
diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go index aced6cd..faf1cee 100644 --- a/collector/mdadm_linux.go +++ b/collector/mdadm_linux.go | |||
@@ -19,20 +19,23 @@ import ( | |||
19 | "fmt" | 19 | "fmt" |
20 | "os" | 20 | "os" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
23 | "github.com/go-kit/kit/log/level" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | ||
24 | "github.com/prometheus/procfs" | 25 | "github.com/prometheus/procfs" |
25 | ) | 26 | ) |
26 | 27 | ||
27 | type mdadmCollector struct{} | 28 | type mdadmCollector struct { |
29 | logger log.Logger | ||
30 | } | ||
28 | 31 | ||
29 | func init() { | 32 | func init() { |
30 | registerCollector("mdadm", defaultEnabled, NewMdadmCollector) | 33 | registerCollector("mdadm", defaultEnabled, NewMdadmCollector) |
31 | } | 34 | } |
32 | 35 | ||
33 | // NewMdadmCollector returns a new Collector exposing raid statistics. | 36 | // NewMdadmCollector returns a new Collector exposing raid statistics. |
34 | func NewMdadmCollector() (Collector, error) { | 37 | func NewMdadmCollector(logger log.Logger) (Collector, error) { |
35 | return &mdadmCollector{}, nil | 38 | return &mdadmCollector{logger}, nil |
36 | } | 39 | } |
37 | 40 | ||
38 | var ( | 41 | var ( |
@@ -101,7 +104,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { | |||
101 | 104 | ||
102 | if err != nil { | 105 | if err != nil { |
103 | if os.IsNotExist(err) { | 106 | if os.IsNotExist(err) { |
104 | log.Debugf("Not collecting mdstat, file does not exist: %s", *procPath) | 107 | level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath) |
105 | return nil | 108 | return nil |
106 | } | 109 | } |
107 | 110 | ||
@@ -109,7 +112,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { | |||
109 | } | 112 | } |
110 | 113 | ||
111 | for _, mdStat := range mdStats { | 114 | for _, mdStat := range mdStats { |
112 | log.Debugf("collecting metrics for device %s", mdStat.Name) | 115 | level.Debug(c.logger).Log("msg", "collecting metrics for device", "device", mdStat.Name) |
113 | 116 | ||
114 | stateVals := make(map[string]float64) | 117 | stateVals := make(map[string]float64) |
115 | stateVals[mdStat.ActivityState] = 1 | 118 | stateVals[mdStat.ActivityState] = 1 |
diff --git a/collector/meminfo.go b/collector/meminfo.go index 1652b8b..d3d3b8d 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go | |||
@@ -20,23 +20,26 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "strings" | 21 | "strings" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/common/log" | ||
25 | ) | 26 | ) |
26 | 27 | ||
27 | const ( | 28 | const ( |
28 | memInfoSubsystem = "memory" | 29 | memInfoSubsystem = "memory" |
29 | ) | 30 | ) |
30 | 31 | ||
31 | type meminfoCollector struct{} | 32 | type meminfoCollector struct { |
33 | logger log.Logger | ||
34 | } | ||
32 | 35 | ||
33 | func init() { | 36 | func init() { |
34 | registerCollector("meminfo", defaultEnabled, NewMeminfoCollector) | 37 | registerCollector("meminfo", defaultEnabled, NewMeminfoCollector) |
35 | } | 38 | } |
36 | 39 | ||
37 | // NewMeminfoCollector returns a new Collector exposing memory stats. | 40 | // NewMeminfoCollector returns a new Collector exposing memory stats. |
38 | func NewMeminfoCollector() (Collector, error) { | 41 | func NewMeminfoCollector(logger log.Logger) (Collector, error) { |
39 | return &meminfoCollector{}, nil | 42 | return &meminfoCollector{logger}, nil |
40 | } | 43 | } |
41 | 44 | ||
42 | // Update calls (*meminfoCollector).getMemInfo to get the platform specific | 45 | // Update calls (*meminfoCollector).getMemInfo to get the platform specific |
@@ -47,7 +50,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { | |||
47 | if err != nil { | 50 | if err != nil { |
48 | return fmt.Errorf("couldn't get meminfo: %s", err) | 51 | return fmt.Errorf("couldn't get meminfo: %s", err) |
49 | } | 52 | } |
50 | log.Debugf("Set node_mem: %#v", memInfo) | 53 | level.Debug(c.logger).Log("msg", "Set node_mem", "memInfo", memInfo) |
51 | for k, v := range memInfo { | 54 | for k, v := range memInfo { |
52 | if strings.HasSuffix(k, "_total") { | 55 | if strings.HasSuffix(k, "_total") { |
53 | metricType = prometheus.CounterValue | 56 | metricType = prometheus.CounterValue |
diff --git a/collector/meminfo_numa_linux.go b/collector/meminfo_numa_linux.go index 3d121bd..d36f6a0 100644 --- a/collector/meminfo_numa_linux.go +++ b/collector/meminfo_numa_linux.go | |||
@@ -25,6 +25,7 @@ import ( | |||
25 | "strconv" | 25 | "strconv" |
26 | "strings" | 26 | "strings" |
27 | 27 | ||
28 | "github.com/go-kit/kit/log" | ||
28 | "github.com/prometheus/client_golang/prometheus" | 29 | "github.com/prometheus/client_golang/prometheus" |
29 | ) | 30 | ) |
30 | 31 | ||
@@ -43,6 +44,7 @@ type meminfoMetric struct { | |||
43 | 44 | ||
44 | type meminfoNumaCollector struct { | 45 | type meminfoNumaCollector struct { |
45 | metricDescs map[string]*prometheus.Desc | 46 | metricDescs map[string]*prometheus.Desc |
47 | logger log.Logger | ||
46 | } | 48 | } |
47 | 49 | ||
48 | func init() { | 50 | func init() { |
@@ -50,9 +52,10 @@ func init() { | |||
50 | } | 52 | } |
51 | 53 | ||
52 | // NewMeminfoNumaCollector returns a new Collector exposing memory stats. | 54 | // NewMeminfoNumaCollector returns a new Collector exposing memory stats. |
53 | func NewMeminfoNumaCollector() (Collector, error) { | 55 | func NewMeminfoNumaCollector(logger log.Logger) (Collector, error) { |
54 | return &meminfoNumaCollector{ | 56 | return &meminfoNumaCollector{ |
55 | metricDescs: map[string]*prometheus.Desc{}, | 57 | metricDescs: map[string]*prometheus.Desc{}, |
58 | logger: logger, | ||
56 | }, nil | 59 | }, nil |
57 | } | 60 | } |
58 | 61 | ||
diff --git a/collector/memory_bsd.go b/collector/memory_bsd.go index cc6bc08..4be5ddd 100644 --- a/collector/memory_bsd.go +++ b/collector/memory_bsd.go | |||
@@ -19,6 +19,7 @@ package collector | |||
19 | import ( | 19 | import ( |
20 | "fmt" | 20 | "fmt" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | "golang.org/x/sys/unix" | 24 | "golang.org/x/sys/unix" |
24 | ) | 25 | ) |
@@ -31,6 +32,7 @@ type memoryCollector struct { | |||
31 | pageSize uint64 | 32 | pageSize uint64 |
32 | sysctls []bsdSysctl | 33 | sysctls []bsdSysctl |
33 | kvm kvm | 34 | kvm kvm |
35 | logger log.Logger | ||
34 | } | 36 | } |
35 | 37 | ||
36 | func init() { | 38 | func init() { |
@@ -38,7 +40,7 @@ func init() { | |||
38 | } | 40 | } |
39 | 41 | ||
40 | // NewMemoryCollector returns a new Collector exposing memory stats. | 42 | // NewMemoryCollector returns a new Collector exposing memory stats. |
41 | func NewMemoryCollector() (Collector, error) { | 43 | func NewMemoryCollector(logger log.Logger) (Collector, error) { |
42 | tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size") | 44 | tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size") |
43 | if err != nil { | 45 | if err != nil { |
44 | return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err) | 46 | return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err) |
@@ -57,6 +59,7 @@ func NewMemoryCollector() (Collector, error) { | |||
57 | } | 59 | } |
58 | 60 | ||
59 | return &memoryCollector{ | 61 | return &memoryCollector{ |
62 | logger: logger, | ||
60 | pageSize: uint64(tmp32), | 63 | pageSize: uint64(tmp32), |
61 | sysctls: []bsdSysctl{ | 64 | sysctls: []bsdSysctl{ |
62 | // Descriptions via: https://wiki.freebsd.org/Memory | 65 | // Descriptions via: https://wiki.freebsd.org/Memory |
diff --git a/collector/mountstats_linux.go b/collector/mountstats_linux.go index eeb01b7..3fa1597 100644 --- a/collector/mountstats_linux.go +++ b/collector/mountstats_linux.go | |||
@@ -16,8 +16,9 @@ package collector | |||
16 | import ( | 16 | import ( |
17 | "fmt" | 17 | "fmt" |
18 | 18 | ||
19 | "github.com/go-kit/kit/log" | ||
20 | "github.com/go-kit/kit/log/level" | ||
19 | "github.com/prometheus/client_golang/prometheus" | 21 | "github.com/prometheus/client_golang/prometheus" |
20 | "github.com/prometheus/common/log" | ||
21 | "github.com/prometheus/procfs" | 22 | "github.com/prometheus/procfs" |
22 | ) | 23 | ) |
23 | 24 | ||
@@ -91,6 +92,8 @@ type mountStatsCollector struct { | |||
91 | NFSEventPNFSWriteTotal *prometheus.Desc | 92 | NFSEventPNFSWriteTotal *prometheus.Desc |
92 | 93 | ||
93 | proc procfs.Proc | 94 | proc procfs.Proc |
95 | |||
96 | logger log.Logger | ||
94 | } | 97 | } |
95 | 98 | ||
96 | // used to uniquely identify an NFS mount to prevent duplicates | 99 | // used to uniquely identify an NFS mount to prevent duplicates |
@@ -105,7 +108,7 @@ func init() { | |||
105 | } | 108 | } |
106 | 109 | ||
107 | // NewMountStatsCollector returns a new Collector exposing NFS statistics. | 110 | // NewMountStatsCollector returns a new Collector exposing NFS statistics. |
108 | func NewMountStatsCollector() (Collector, error) { | 111 | func NewMountStatsCollector(logger log.Logger) (Collector, error) { |
109 | fs, err := procfs.NewFS(*procPath) | 112 | fs, err := procfs.NewFS(*procPath) |
110 | if err != nil { | 113 | if err != nil { |
111 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 114 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -498,7 +501,8 @@ func NewMountStatsCollector() (Collector, error) { | |||
498 | nil, | 501 | nil, |
499 | ), | 502 | ), |
500 | 503 | ||
501 | proc: proc, | 504 | proc: proc, |
505 | logger: logger, | ||
502 | }, nil | 506 | }, nil |
503 | } | 507 | } |
504 | 508 | ||
@@ -534,7 +538,7 @@ func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error { | |||
534 | deviceIdentifier := nfsDeviceIdentifier{m.Device, stats.Transport.Protocol, mountAddress} | 538 | deviceIdentifier := nfsDeviceIdentifier{m.Device, stats.Transport.Protocol, mountAddress} |
535 | i := deviceList[deviceIdentifier] | 539 | i := deviceList[deviceIdentifier] |
536 | if i { | 540 | if i { |
537 | log.Debugf("Skipping duplicate device entry %q", deviceIdentifier) | 541 | level.Debug(c.logger).Log("msg", "Skipping duplicate device entry", "device", deviceIdentifier) |
538 | continue | 542 | continue |
539 | } | 543 | } |
540 | 544 | ||
diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index af4b487..8d8a984 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go | |||
@@ -20,9 +20,10 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "regexp" | 21 | "regexp" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/procfs/sysfs" | 25 | "github.com/prometheus/procfs/sysfs" |
25 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 26 | "gopkg.in/alecthomas/kingpin.v2" |
26 | ) | 27 | ) |
27 | 28 | ||
28 | var ( | 29 | var ( |
@@ -34,6 +35,7 @@ type netClassCollector struct { | |||
34 | subsystem string | 35 | subsystem string |
35 | ignoredDevicesPattern *regexp.Regexp | 36 | ignoredDevicesPattern *regexp.Regexp |
36 | metricDescs map[string]*prometheus.Desc | 37 | metricDescs map[string]*prometheus.Desc |
38 | logger log.Logger | ||
37 | } | 39 | } |
38 | 40 | ||
39 | func init() { | 41 | func init() { |
@@ -41,7 +43,7 @@ func init() { | |||
41 | } | 43 | } |
42 | 44 | ||
43 | // NewNetClassCollector returns a new Collector exposing network class stats. | 45 | // NewNetClassCollector returns a new Collector exposing network class stats. |
44 | func NewNetClassCollector() (Collector, error) { | 46 | func NewNetClassCollector(logger log.Logger) (Collector, error) { |
45 | fs, err := sysfs.NewFS(*sysPath) | 47 | fs, err := sysfs.NewFS(*sysPath) |
46 | if err != nil { | 48 | if err != nil { |
47 | return nil, fmt.Errorf("failed to open sysfs: %w", err) | 49 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
@@ -52,6 +54,7 @@ func NewNetClassCollector() (Collector, error) { | |||
52 | subsystem: "network", | 54 | subsystem: "network", |
53 | ignoredDevicesPattern: pattern, | 55 | ignoredDevicesPattern: pattern, |
54 | metricDescs: map[string]*prometheus.Desc{}, | 56 | metricDescs: map[string]*prometheus.Desc{}, |
57 | logger: logger, | ||
55 | }, nil | 58 | }, nil |
56 | } | 59 | } |
57 | 60 | ||
diff --git a/collector/netdev_bsd.go b/collector/netdev_bsd.go index 18eca22..8bed2e1 100644 --- a/collector/netdev_bsd.go +++ b/collector/netdev_bsd.go | |||
@@ -21,7 +21,8 @@ import ( | |||
21 | "regexp" | 21 | "regexp" |
22 | "strconv" | 22 | "strconv" |
23 | 23 | ||
24 | "github.com/prometheus/common/log" | 24 | "github.com/go-kit/kit/log" |
25 | "github.com/go-kit/kit/log/level" | ||
25 | ) | 26 | ) |
26 | 27 | ||
27 | /* | 28 | /* |
@@ -34,7 +35,7 @@ import ( | |||
34 | */ | 35 | */ |
35 | import "C" | 36 | import "C" |
36 | 37 | ||
37 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]map[string]string, error) { | 38 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp, logger log.Logger) (map[string]map[string]string, error) { |
38 | netDev := map[string]map[string]string{} | 39 | netDev := map[string]map[string]string{} |
39 | 40 | ||
40 | var ifap, ifa *C.struct_ifaddrs | 41 | var ifap, ifa *C.struct_ifaddrs |
@@ -47,11 +48,11 @@ func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]ma | |||
47 | if ifa.ifa_addr.sa_family == C.AF_LINK { | 48 | if ifa.ifa_addr.sa_family == C.AF_LINK { |
48 | dev := C.GoString(ifa.ifa_name) | 49 | dev := C.GoString(ifa.ifa_name) |
49 | if ignore != nil && ignore.MatchString(dev) { | 50 | if ignore != nil && ignore.MatchString(dev) { |
50 | log.Debugf("Ignoring device: %s", dev) | 51 | level.Debug(logger).Log("msg", "Ignoring device", "device", dev) |
51 | continue | 52 | continue |
52 | } | 53 | } |
53 | if accept != nil && !accept.MatchString(dev) { | 54 | if accept != nil && !accept.MatchString(dev) { |
54 | log.Debugf("Ignoring device: %s", dev) | 55 | level.Debug(logger).Log("msg", "Ignoring device", "device", dev) |
55 | continue | 56 | continue |
56 | } | 57 | } |
57 | 58 | ||
diff --git a/collector/netdev_common.go b/collector/netdev_common.go index 0c11023..e634c90 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go | |||
@@ -22,6 +22,7 @@ import ( | |||
22 | "regexp" | 22 | "regexp" |
23 | "strconv" | 23 | "strconv" |
24 | 24 | ||
25 | "github.com/go-kit/kit/log" | ||
25 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
26 | "gopkg.in/alecthomas/kingpin.v2" | 27 | "gopkg.in/alecthomas/kingpin.v2" |
27 | ) | 28 | ) |
@@ -36,6 +37,7 @@ type netDevCollector struct { | |||
36 | ignoredDevicesPattern *regexp.Regexp | 37 | ignoredDevicesPattern *regexp.Regexp |
37 | acceptDevicesPattern *regexp.Regexp | 38 | acceptDevicesPattern *regexp.Regexp |
38 | metricDescs map[string]*prometheus.Desc | 39 | metricDescs map[string]*prometheus.Desc |
40 | logger log.Logger | ||
39 | } | 41 | } |
40 | 42 | ||
41 | func init() { | 43 | func init() { |
@@ -43,7 +45,7 @@ func init() { | |||
43 | } | 45 | } |
44 | 46 | ||
45 | // NewNetDevCollector returns a new Collector exposing network device stats. | 47 | // NewNetDevCollector returns a new Collector exposing network device stats. |
46 | func NewNetDevCollector() (Collector, error) { | 48 | func NewNetDevCollector(logger log.Logger) (Collector, error) { |
47 | if *netdevIgnoredDevices != "" && *netdevAcceptDevices != "" { | 49 | if *netdevIgnoredDevices != "" && *netdevAcceptDevices != "" { |
48 | return nil, errors.New("device-blacklist & accept-devices are mutually exclusive") | 50 | return nil, errors.New("device-blacklist & accept-devices are mutually exclusive") |
49 | } | 51 | } |
@@ -63,11 +65,12 @@ func NewNetDevCollector() (Collector, error) { | |||
63 | ignoredDevicesPattern: ignorePattern, | 65 | ignoredDevicesPattern: ignorePattern, |
64 | acceptDevicesPattern: acceptPattern, | 66 | acceptDevicesPattern: acceptPattern, |
65 | metricDescs: map[string]*prometheus.Desc{}, | 67 | metricDescs: map[string]*prometheus.Desc{}, |
68 | logger: logger, | ||
66 | }, nil | 69 | }, nil |
67 | } | 70 | } |
68 | 71 | ||
69 | func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { | 72 | func (c *netDevCollector) Update(ch chan<- prometheus.Metric) error { |
70 | netDev, err := getNetDevStats(c.ignoredDevicesPattern, c.acceptDevicesPattern) | 73 | netDev, err := getNetDevStats(c.ignoredDevicesPattern, c.acceptDevicesPattern, c.logger) |
71 | if err != nil { | 74 | if err != nil { |
72 | return fmt.Errorf("couldn't get netstats: %s", err) | 75 | return fmt.Errorf("couldn't get netstats: %s", err) |
73 | } | 76 | } |
diff --git a/collector/netdev_darwin.go b/collector/netdev_darwin.go index dd25963..4970853 100644 --- a/collector/netdev_darwin.go +++ b/collector/netdev_darwin.go | |||
@@ -23,11 +23,12 @@ import ( | |||
23 | "regexp" | 23 | "regexp" |
24 | "strconv" | 24 | "strconv" |
25 | 25 | ||
26 | "github.com/prometheus/common/log" | 26 | "github.com/go-kit/kit/log" |
27 | "github.com/go-kit/kit/log/level" | ||
27 | "golang.org/x/sys/unix" | 28 | "golang.org/x/sys/unix" |
28 | ) | 29 | ) |
29 | 30 | ||
30 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]map[string]string, error) { | 31 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp, logger log.Logger) (map[string]map[string]string, error) { |
31 | netDev := map[string]map[string]string{} | 32 | netDev := map[string]map[string]string{} |
32 | 33 | ||
33 | ifs, err := net.Interfaces() | 34 | ifs, err := net.Interfaces() |
@@ -38,16 +39,16 @@ func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]ma | |||
38 | for _, iface := range ifs { | 39 | for _, iface := range ifs { |
39 | ifaceData, err := getIfaceData(iface.Index) | 40 | ifaceData, err := getIfaceData(iface.Index) |
40 | if err != nil { | 41 | if err != nil { |
41 | log.Debugf("failed to load data for interface %q: %v", iface.Name, err) | 42 | level.Debug(logger).Log("msg", "failed to load data for interface", "device", iface.Name, "err", err) |
42 | continue | 43 | continue |
43 | } | 44 | } |
44 | 45 | ||
45 | if ignore != nil && ignore.MatchString(iface.Name) { | 46 | if ignore != nil && ignore.MatchString(iface.Name) { |
46 | log.Debugf("Ignoring device: %s", iface.Name) | 47 | level.Debug(logger).Log("msg", "Ignoring device", "device", iface.Name) |
47 | continue | 48 | continue |
48 | } | 49 | } |
49 | if accept != nil && !accept.MatchString(iface.Name) { | 50 | if accept != nil && !accept.MatchString(iface.Name) { |
50 | log.Debugf("Ignoring device: %s", iface.Name) | 51 | level.Debug(logger).Log("msg", "Ignoring device", "device", iface.Name) |
51 | continue | 52 | continue |
52 | } | 53 | } |
53 | 54 | ||
diff --git a/collector/netdev_linux.go b/collector/netdev_linux.go index a5c6163..1a4b5df 100644 --- a/collector/netdev_linux.go +++ b/collector/netdev_linux.go | |||
@@ -23,7 +23,8 @@ import ( | |||
23 | "regexp" | 23 | "regexp" |
24 | "strings" | 24 | "strings" |
25 | 25 | ||
26 | "github.com/prometheus/common/log" | 26 | "github.com/go-kit/kit/log" |
27 | "github.com/go-kit/kit/log/level" | ||
27 | ) | 28 | ) |
28 | 29 | ||
29 | var ( | 30 | var ( |
@@ -31,17 +32,17 @@ var ( | |||
31 | procNetDevFieldSep = regexp.MustCompile(` +`) | 32 | procNetDevFieldSep = regexp.MustCompile(` +`) |
32 | ) | 33 | ) |
33 | 34 | ||
34 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]map[string]string, error) { | 35 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp, logger log.Logger) (map[string]map[string]string, error) { |
35 | file, err := os.Open(procFilePath("net/dev")) | 36 | file, err := os.Open(procFilePath("net/dev")) |
36 | if err != nil { | 37 | if err != nil { |
37 | return nil, err | 38 | return nil, err |
38 | } | 39 | } |
39 | defer file.Close() | 40 | defer file.Close() |
40 | 41 | ||
41 | return parseNetDevStats(file, ignore, accept) | 42 | return parseNetDevStats(file, ignore, accept, logger) |
42 | } | 43 | } |
43 | 44 | ||
44 | func parseNetDevStats(r io.Reader, ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]map[string]string, error) { | 45 | func parseNetDevStats(r io.Reader, ignore *regexp.Regexp, accept *regexp.Regexp, logger log.Logger) (map[string]map[string]string, error) { |
45 | scanner := bufio.NewScanner(r) | 46 | scanner := bufio.NewScanner(r) |
46 | scanner.Scan() // skip first header | 47 | scanner.Scan() // skip first header |
47 | scanner.Scan() | 48 | scanner.Scan() |
@@ -65,11 +66,11 @@ func parseNetDevStats(r io.Reader, ignore *regexp.Regexp, accept *regexp.Regexp) | |||
65 | 66 | ||
66 | dev := parts[1] | 67 | dev := parts[1] |
67 | if ignore != nil && ignore.MatchString(dev) { | 68 | if ignore != nil && ignore.MatchString(dev) { |
68 | log.Debugf("Ignoring device: %s", dev) | 69 | level.Debug(logger).Log("msg", "Ignoring device", "device", dev) |
69 | continue | 70 | continue |
70 | } | 71 | } |
71 | if accept != nil && !accept.MatchString(dev) { | 72 | if accept != nil && !accept.MatchString(dev) { |
72 | log.Debugf("Ignoring device: %s", dev) | 73 | level.Debug(logger).Log("msg", "Ignoring device", "device", dev) |
73 | continue | 74 | continue |
74 | } | 75 | } |
75 | 76 | ||
diff --git a/collector/netdev_linux_test.go b/collector/netdev_linux_test.go index 163c87f..1c88d83 100644 --- a/collector/netdev_linux_test.go +++ b/collector/netdev_linux_test.go | |||
@@ -14,6 +14,7 @@ | |||
14 | package collector | 14 | package collector |
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "github.com/go-kit/kit/log" | ||
17 | "os" | 18 | "os" |
18 | "regexp" | 19 | "regexp" |
19 | "testing" | 20 | "testing" |
@@ -26,7 +27,7 @@ func TestNetDevStatsIgnore(t *testing.T) { | |||
26 | } | 27 | } |
27 | defer file.Close() | 28 | defer file.Close() |
28 | 29 | ||
29 | netStats, err := parseNetDevStats(file, regexp.MustCompile("^veth"), nil) | 30 | netStats, err := parseNetDevStats(file, regexp.MustCompile("^veth"), nil, log.NewNopLogger()) |
30 | if err != nil { | 31 | if err != nil { |
31 | t.Fatal(err) | 32 | t.Fatal(err) |
32 | } | 33 | } |
@@ -67,7 +68,7 @@ func TestNetDevStatsAccept(t *testing.T) { | |||
67 | } | 68 | } |
68 | defer file.Close() | 69 | defer file.Close() |
69 | 70 | ||
70 | netStats, err := parseNetDevStats(file, nil, regexp.MustCompile("^💩0$")) | 71 | netStats, err := parseNetDevStats(file, nil, regexp.MustCompile("^💩0$"), log.NewNopLogger()) |
71 | if err != nil { | 72 | if err != nil { |
72 | t.Fatal(err) | 73 | t.Fatal(err) |
73 | } | 74 | } |
diff --git a/collector/netdev_openbsd.go b/collector/netdev_openbsd.go index b080cbc..f7c9030 100644 --- a/collector/netdev_openbsd.go +++ b/collector/netdev_openbsd.go | |||
@@ -20,7 +20,8 @@ import ( | |||
20 | "regexp" | 20 | "regexp" |
21 | "strconv" | 21 | "strconv" |
22 | 22 | ||
23 | "github.com/prometheus/common/log" | 23 | "github.com/go-kit/kit/log" |
24 | "github.com/go-kit/kit/log/level" | ||
24 | ) | 25 | ) |
25 | 26 | ||
26 | /* | 27 | /* |
@@ -31,7 +32,7 @@ import ( | |||
31 | */ | 32 | */ |
32 | import "C" | 33 | import "C" |
33 | 34 | ||
34 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]map[string]string, error) { | 35 | func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp, logger log.Logger) (map[string]map[string]string, error) { |
35 | netDev := map[string]map[string]string{} | 36 | netDev := map[string]map[string]string{} |
36 | 37 | ||
37 | var ifap, ifa *C.struct_ifaddrs | 38 | var ifap, ifa *C.struct_ifaddrs |
@@ -44,11 +45,11 @@ func getNetDevStats(ignore *regexp.Regexp, accept *regexp.Regexp) (map[string]ma | |||
44 | if ifa.ifa_addr.sa_family == C.AF_LINK { | 45 | if ifa.ifa_addr.sa_family == C.AF_LINK { |
45 | dev := C.GoString(ifa.ifa_name) | 46 | dev := C.GoString(ifa.ifa_name) |
46 | if ignore != nil && ignore.MatchString(dev) { | 47 | if ignore != nil && ignore.MatchString(dev) { |
47 | log.Debugf("Ignoring device: %s", dev) | 48 | level.Debug(logger).Log("msg", "Ignoring device", "device", dev) |
48 | continue | 49 | continue |
49 | } | 50 | } |
50 | if accept != nil && !accept.MatchString(dev) { | 51 | if accept != nil && !accept.MatchString(dev) { |
51 | log.Debugf("Ignoring device: %s", dev) | 52 | level.Debug(logger).Log("msg", "Ignoring device", "device", dev) |
52 | continue | 53 | continue |
53 | } | 54 | } |
54 | 55 | ||
diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index d5eed69..f0aca26 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go | |||
@@ -24,6 +24,7 @@ import ( | |||
24 | "strconv" | 24 | "strconv" |
25 | "strings" | 25 | "strings" |
26 | 26 | ||
27 | "github.com/go-kit/kit/log" | ||
27 | "github.com/prometheus/client_golang/prometheus" | 28 | "github.com/prometheus/client_golang/prometheus" |
28 | "gopkg.in/alecthomas/kingpin.v2" | 29 | "gopkg.in/alecthomas/kingpin.v2" |
29 | ) | 30 | ) |
@@ -38,6 +39,7 @@ var ( | |||
38 | 39 | ||
39 | type netStatCollector struct { | 40 | type netStatCollector struct { |
40 | fieldPattern *regexp.Regexp | 41 | fieldPattern *regexp.Regexp |
42 | logger log.Logger | ||
41 | } | 43 | } |
42 | 44 | ||
43 | func init() { | 45 | func init() { |
@@ -46,10 +48,11 @@ func init() { | |||
46 | 48 | ||
47 | // NewNetStatCollector takes and returns | 49 | // NewNetStatCollector takes and returns |
48 | // a new Collector exposing network stats. | 50 | // a new Collector exposing network stats. |
49 | func NewNetStatCollector() (Collector, error) { | 51 | func NewNetStatCollector(logger log.Logger) (Collector, error) { |
50 | pattern := regexp.MustCompile(*netStatFields) | 52 | pattern := regexp.MustCompile(*netStatFields) |
51 | return &netStatCollector{ | 53 | return &netStatCollector{ |
52 | fieldPattern: pattern, | 54 | fieldPattern: pattern, |
55 | logger: logger, | ||
53 | }, nil | 56 | }, nil |
54 | } | 57 | } |
55 | 58 | ||
diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go index 05b241e..7ed4930 100644 --- a/collector/nfs_linux.go +++ b/collector/nfs_linux.go | |||
@@ -18,8 +18,9 @@ import ( | |||
18 | "os" | 18 | "os" |
19 | "reflect" | 19 | "reflect" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
22 | "github.com/go-kit/kit/log/level" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/prometheus/common/log" | ||
23 | "github.com/prometheus/procfs/nfs" | 24 | "github.com/prometheus/procfs/nfs" |
24 | ) | 25 | ) |
25 | 26 | ||
@@ -35,6 +36,7 @@ type nfsCollector struct { | |||
35 | nfsRPCRetransmissionsDesc *prometheus.Desc | 36 | nfsRPCRetransmissionsDesc *prometheus.Desc |
36 | nfsRPCAuthenticationRefreshesDesc *prometheus.Desc | 37 | nfsRPCAuthenticationRefreshesDesc *prometheus.Desc |
37 | nfsProceduresDesc *prometheus.Desc | 38 | nfsProceduresDesc *prometheus.Desc |
39 | logger log.Logger | ||
38 | } | 40 | } |
39 | 41 | ||
40 | func init() { | 42 | func init() { |
@@ -42,7 +44,7 @@ func init() { | |||
42 | } | 44 | } |
43 | 45 | ||
44 | // NewNfsCollector returns a new Collector exposing NFS statistics. | 46 | // NewNfsCollector returns a new Collector exposing NFS statistics. |
45 | func NewNfsCollector() (Collector, error) { | 47 | func NewNfsCollector(logger log.Logger) (Collector, error) { |
46 | fs, err := nfs.NewFS(*procPath) | 48 | fs, err := nfs.NewFS(*procPath) |
47 | if err != nil { | 49 | if err != nil { |
48 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 50 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -86,6 +88,7 @@ func NewNfsCollector() (Collector, error) { | |||
86 | []string{"proto", "method"}, | 88 | []string{"proto", "method"}, |
87 | nil, | 89 | nil, |
88 | ), | 90 | ), |
91 | logger: logger, | ||
89 | }, nil | 92 | }, nil |
90 | } | 93 | } |
91 | 94 | ||
@@ -93,7 +96,7 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error { | |||
93 | stats, err := c.fs.ClientRPCStats() | 96 | stats, err := c.fs.ClientRPCStats() |
94 | if err != nil { | 97 | if err != nil { |
95 | if os.IsNotExist(err) { | 98 | if os.IsNotExist(err) { |
96 | log.Debugf("Not collecting NFS metrics: %s", err) | 99 | level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err) |
97 | return nil | 100 | return nil |
98 | } | 101 | } |
99 | return fmt.Errorf("failed to retrieve nfs stats: %w", err) | 102 | return fmt.Errorf("failed to retrieve nfs stats: %w", err) |
diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go index b5e7cf9..234e1da 100644 --- a/collector/nfsd_linux.go +++ b/collector/nfsd_linux.go | |||
@@ -17,8 +17,9 @@ import ( | |||
17 | "fmt" | 17 | "fmt" |
18 | "os" | 18 | "os" |
19 | 19 | ||
20 | "github.com/go-kit/kit/log" | ||
21 | "github.com/go-kit/kit/log/level" | ||
20 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
21 | "github.com/prometheus/common/log" | ||
22 | "github.com/prometheus/procfs/nfs" | 23 | "github.com/prometheus/procfs/nfs" |
23 | ) | 24 | ) |
24 | 25 | ||
@@ -27,6 +28,7 @@ import ( | |||
27 | type nfsdCollector struct { | 28 | type nfsdCollector struct { |
28 | fs nfs.FS | 29 | fs nfs.FS |
29 | requestsDesc *prometheus.Desc | 30 | requestsDesc *prometheus.Desc |
31 | logger log.Logger | ||
30 | } | 32 | } |
31 | 33 | ||
32 | func init() { | 34 | func init() { |
@@ -38,7 +40,7 @@ const ( | |||
38 | ) | 40 | ) |
39 | 41 | ||
40 | // NewNFSdCollector returns a new Collector exposing /proc/net/rpc/nfsd statistics. | 42 | // NewNFSdCollector returns a new Collector exposing /proc/net/rpc/nfsd statistics. |
41 | func NewNFSdCollector() (Collector, error) { | 43 | func NewNFSdCollector(logger log.Logger) (Collector, error) { |
42 | fs, err := nfs.NewFS(*procPath) | 44 | fs, err := nfs.NewFS(*procPath) |
43 | if err != nil { | 45 | if err != nil { |
44 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 46 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -51,6 +53,7 @@ func NewNFSdCollector() (Collector, error) { | |||
51 | "Total number NFSd Requests by method and protocol.", | 53 | "Total number NFSd Requests by method and protocol.", |
52 | []string{"proto", "method"}, nil, | 54 | []string{"proto", "method"}, nil, |
53 | ), | 55 | ), |
56 | logger: logger, | ||
54 | }, nil | 57 | }, nil |
55 | } | 58 | } |
56 | 59 | ||
@@ -59,7 +62,7 @@ func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error { | |||
59 | stats, err := c.fs.ServerRPCStats() | 62 | stats, err := c.fs.ServerRPCStats() |
60 | if err != nil { | 63 | if err != nil { |
61 | if os.IsNotExist(err) { | 64 | if os.IsNotExist(err) { |
62 | log.Debugf("Not collecting NFSd metrics: %s", err) | 65 | level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err) |
63 | return nil | 66 | return nil |
64 | } | 67 | } |
65 | return fmt.Errorf("failed to retrieve nfsd stats: %w", err) | 68 | return fmt.Errorf("failed to retrieve nfsd stats: %w", err) |
diff --git a/collector/ntp.go b/collector/ntp.go index 9b3c5a2..ea3a69e 100644 --- a/collector/ntp.go +++ b/collector/ntp.go | |||
@@ -22,6 +22,7 @@ import ( | |||
22 | "time" | 22 | "time" |
23 | 23 | ||
24 | "github.com/beevik/ntp" | 24 | "github.com/beevik/ntp" |
25 | "github.com/go-kit/kit/log" | ||
25 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
26 | "gopkg.in/alecthomas/kingpin.v2" | 27 | "gopkg.in/alecthomas/kingpin.v2" |
27 | ) | 28 | ) |
@@ -47,6 +48,7 @@ var ( | |||
47 | 48 | ||
48 | type ntpCollector struct { | 49 | type ntpCollector struct { |
49 | stratum, leap, rtt, offset, reftime, rootDelay, rootDispersion, sanity typedDesc | 50 | stratum, leap, rtt, offset, reftime, rootDelay, rootDispersion, sanity typedDesc |
51 | logger log.Logger | ||
50 | } | 52 | } |
51 | 53 | ||
52 | func init() { | 54 | func init() { |
@@ -57,7 +59,7 @@ func init() { | |||
57 | // Default definition of "local" is: | 59 | // Default definition of "local" is: |
58 | // - collector.ntp.server address is a loopback address (or collector.ntp.server-is-mine flag is turned on) | 60 | // - collector.ntp.server address is a loopback address (or collector.ntp.server-is-mine flag is turned on) |
59 | // - the server is reachable with outgoin IP_TTL = 1 | 61 | // - the server is reachable with outgoin IP_TTL = 1 |
60 | func NewNtpCollector() (Collector, error) { | 62 | func NewNtpCollector(logger log.Logger) (Collector, error) { |
61 | ipaddr := net.ParseIP(*ntpServer) | 63 | ipaddr := net.ParseIP(*ntpServer) |
62 | if !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) { | 64 | if !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) { |
63 | return nil, fmt.Errorf("only IP address of local NTP server is valid for --collector.ntp.server") | 65 | return nil, fmt.Errorf("only IP address of local NTP server is valid for --collector.ntp.server") |
@@ -112,6 +114,7 @@ func NewNtpCollector() (Collector, error) { | |||
112 | "NTPD sanity according to RFC5905 heuristics and configured limits.", | 114 | "NTPD sanity according to RFC5905 heuristics and configured limits.", |
113 | nil, nil, | 115 | nil, nil, |
114 | ), prometheus.GaugeValue}, | 116 | ), prometheus.GaugeValue}, |
117 | logger: logger, | ||
115 | }, nil | 118 | }, nil |
116 | } | 119 | } |
117 | 120 | ||
diff --git a/collector/perf_linux.go b/collector/perf_linux.go index 0ab7b84..0e8a3cc 100644 --- a/collector/perf_linux.go +++ b/collector/perf_linux.go | |||
@@ -17,7 +17,8 @@ import ( | |||
17 | "fmt" | 17 | "fmt" |
18 | "runtime" | 18 | "runtime" |
19 | 19 | ||
20 | perf "github.com/hodgesds/perf-utils" | 20 | "github.com/go-kit/kit/log" |
21 | "github.com/hodgesds/perf-utils" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | ) | 23 | ) |
23 | 24 | ||
@@ -29,7 +30,7 @@ func init() { | |||
29 | registerCollector(perfSubsystem, defaultDisabled, NewPerfCollector) | 30 | registerCollector(perfSubsystem, defaultDisabled, NewPerfCollector) |
30 | } | 31 | } |
31 | 32 | ||
32 | // perfCollector is a Collecter that uses the perf subsystem to collect | 33 | // perfCollector is a Collector that uses the perf subsystem to collect |
33 | // metrics. It uses perf_event_open an ioctls for profiling. Due to the fact | 34 | // metrics. It uses perf_event_open an ioctls for profiling. Due to the fact |
34 | // that the perf subsystem is highly dependent on kernel configuration and | 35 | // that the perf subsystem is highly dependent on kernel configuration and |
35 | // settings not all profiler values may be exposed on the target system at any | 36 | // settings not all profiler values may be exposed on the target system at any |
@@ -39,34 +40,36 @@ type perfCollector struct { | |||
39 | perfSwProfilers map[int]perf.SoftwareProfiler | 40 | perfSwProfilers map[int]perf.SoftwareProfiler |
40 | perfCacheProfilers map[int]perf.CacheProfiler | 41 | perfCacheProfilers map[int]perf.CacheProfiler |
41 | desc map[string]*prometheus.Desc | 42 | desc map[string]*prometheus.Desc |
43 | logger log.Logger | ||
42 | } | 44 | } |
43 | 45 | ||
44 | // NewPerfCollector returns a new perf based collector, it creates a profiler | 46 | // NewPerfCollector returns a new perf based collector, it creates a profiler |
45 | // per CPU. | 47 | // per CPU. |
46 | func NewPerfCollector() (Collector, error) { | 48 | func NewPerfCollector(logger log.Logger) (Collector, error) { |
47 | collector := &perfCollector{ | 49 | c := &perfCollector{ |
48 | perfHwProfilers: map[int]perf.HardwareProfiler{}, | 50 | perfHwProfilers: map[int]perf.HardwareProfiler{}, |
49 | perfSwProfilers: map[int]perf.SoftwareProfiler{}, | 51 | perfSwProfilers: map[int]perf.SoftwareProfiler{}, |
50 | perfCacheProfilers: map[int]perf.CacheProfiler{}, | 52 | perfCacheProfilers: map[int]perf.CacheProfiler{}, |
53 | logger: logger, | ||
51 | } | 54 | } |
52 | ncpus := runtime.NumCPU() | 55 | ncpus := runtime.NumCPU() |
53 | for i := 0; i < ncpus; i++ { | 56 | for i := 0; i < ncpus; i++ { |
54 | // Use -1 to profile all processes on the CPU, see: | 57 | // Use -1 to profile all processes on the CPU, see: |
55 | // man perf_event_open | 58 | // man perf_event_open |
56 | collector.perfHwProfilers[i] = perf.NewHardwareProfiler(-1, i) | 59 | c.perfHwProfilers[i] = perf.NewHardwareProfiler(-1, i) |
57 | if err := collector.perfHwProfilers[i].Start(); err != nil { | 60 | if err := c.perfHwProfilers[i].Start(); err != nil { |
58 | return collector, err | 61 | return c, err |
59 | } | 62 | } |
60 | collector.perfSwProfilers[i] = perf.NewSoftwareProfiler(-1, i) | 63 | c.perfSwProfilers[i] = perf.NewSoftwareProfiler(-1, i) |
61 | if err := collector.perfSwProfilers[i].Start(); err != nil { | 64 | if err := c.perfSwProfilers[i].Start(); err != nil { |
62 | return collector, err | 65 | return c, err |
63 | } | 66 | } |
64 | collector.perfCacheProfilers[i] = perf.NewCacheProfiler(-1, i) | 67 | c.perfCacheProfilers[i] = perf.NewCacheProfiler(-1, i) |
65 | if err := collector.perfCacheProfilers[i].Start(); err != nil { | 68 | if err := c.perfCacheProfilers[i].Start(); err != nil { |
66 | return collector, err | 69 | return c, err |
67 | } | 70 | } |
68 | } | 71 | } |
69 | collector.desc = map[string]*prometheus.Desc{ | 72 | c.desc = map[string]*prometheus.Desc{ |
70 | "cpucycles_total": prometheus.NewDesc( | 73 | "cpucycles_total": prometheus.NewDesc( |
71 | prometheus.BuildFQName( | 74 | prometheus.BuildFQName( |
72 | namespace, | 75 | namespace, |
@@ -309,7 +312,7 @@ func NewPerfCollector() (Collector, error) { | |||
309 | ), | 312 | ), |
310 | } | 313 | } |
311 | 314 | ||
312 | return collector, nil | 315 | return c, nil |
313 | } | 316 | } |
314 | 317 | ||
315 | // Update implements the Collector interface and will collect metrics per CPU. | 318 | // Update implements the Collector interface and will collect metrics per CPU. |
diff --git a/collector/perf_linux_test.go b/collector/perf_linux_test.go index 0b57d10..68c580b 100644 --- a/collector/perf_linux_test.go +++ b/collector/perf_linux_test.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "github.com/go-kit/kit/log" | ||
19 | "io/ioutil" | 20 | "io/ioutil" |
20 | "strconv" | 21 | "strconv" |
21 | "strings" | 22 | "strings" |
@@ -37,7 +38,7 @@ func TestPerfCollector(t *testing.T) { | |||
37 | if paranoid >= 1 { | 38 | if paranoid >= 1 { |
38 | t.Skip("Skipping perf tests, set perf_event_paranoid to 0") | 39 | t.Skip("Skipping perf tests, set perf_event_paranoid to 0") |
39 | } | 40 | } |
40 | collector, err := NewPerfCollector() | 41 | collector, err := NewPerfCollector(log.NewNopLogger()) |
41 | if err != nil { | 42 | if err != nil { |
42 | t.Fatal(err) | 43 | t.Fatal(err) |
43 | } | 44 | } |
diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 3b5c8d7..988b0ee 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go | |||
@@ -20,6 +20,7 @@ import ( | |||
20 | "fmt" | 20 | "fmt" |
21 | "regexp" | 21 | "regexp" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/procfs/sysfs" | 25 | "github.com/prometheus/procfs/sysfs" |
25 | "gopkg.in/alecthomas/kingpin.v2" | 26 | "gopkg.in/alecthomas/kingpin.v2" |
@@ -33,18 +34,20 @@ type powerSupplyClassCollector struct { | |||
33 | subsystem string | 34 | subsystem string |
34 | ignoredPattern *regexp.Regexp | 35 | ignoredPattern *regexp.Regexp |
35 | metricDescs map[string]*prometheus.Desc | 36 | metricDescs map[string]*prometheus.Desc |
37 | logger log.Logger | ||
36 | } | 38 | } |
37 | 39 | ||
38 | func init() { | 40 | func init() { |
39 | registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector) | 41 | registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector) |
40 | } | 42 | } |
41 | 43 | ||
42 | func NewPowerSupplyClassCollector() (Collector, error) { | 44 | func NewPowerSupplyClassCollector(logger log.Logger) (Collector, error) { |
43 | pattern := regexp.MustCompile(*powerSupplyClassIgnoredPowerSupplies) | 45 | pattern := regexp.MustCompile(*powerSupplyClassIgnoredPowerSupplies) |
44 | return &powerSupplyClassCollector{ | 46 | return &powerSupplyClassCollector{ |
45 | subsystem: "power_supply", | 47 | subsystem: "power_supply", |
46 | ignoredPattern: pattern, | 48 | ignoredPattern: pattern, |
47 | metricDescs: map[string]*prometheus.Desc{}, | 49 | metricDescs: map[string]*prometheus.Desc{}, |
50 | logger: logger, | ||
48 | }, nil | 51 | }, nil |
49 | } | 52 | } |
50 | 53 | ||
diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index 2ed7ffb..8f0b8db 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go | |||
@@ -18,8 +18,9 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
22 | "github.com/go-kit/kit/log/level" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/prometheus/common/log" | ||
23 | "github.com/prometheus/procfs" | 24 | "github.com/prometheus/procfs" |
24 | ) | 25 | ) |
25 | 26 | ||
@@ -35,6 +36,8 @@ type pressureStatsCollector struct { | |||
35 | memFull *prometheus.Desc | 36 | memFull *prometheus.Desc |
36 | 37 | ||
37 | fs procfs.FS | 38 | fs procfs.FS |
39 | |||
40 | logger log.Logger | ||
38 | } | 41 | } |
39 | 42 | ||
40 | func init() { | 43 | func init() { |
@@ -42,7 +45,7 @@ func init() { | |||
42 | } | 45 | } |
43 | 46 | ||
44 | // NewPressureStatsCollector returns a Collector exposing pressure stall information | 47 | // NewPressureStatsCollector returns a Collector exposing pressure stall information |
45 | func NewPressureStatsCollector() (Collector, error) { | 48 | func NewPressureStatsCollector(logger log.Logger) (Collector, error) { |
46 | fs, err := procfs.NewFS(*procPath) | 49 | fs, err := procfs.NewFS(*procPath) |
47 | if err != nil { | 50 | if err != nil { |
48 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 51 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -74,17 +77,18 @@ func NewPressureStatsCollector() (Collector, error) { | |||
74 | "Total time in seconds no process could make progress due to memory congestion", | 77 | "Total time in seconds no process could make progress due to memory congestion", |
75 | nil, nil, | 78 | nil, nil, |
76 | ), | 79 | ), |
77 | fs: fs, | 80 | fs: fs, |
81 | logger: logger, | ||
78 | }, nil | 82 | }, nil |
79 | } | 83 | } |
80 | 84 | ||
81 | // Update calls procfs.NewPSIStatsForResource for the different resources and updates the values | 85 | // Update calls procfs.NewPSIStatsForResource for the different resources and updates the values |
82 | func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { | 86 | func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { |
83 | for _, res := range psiResources { | 87 | for _, res := range psiResources { |
84 | log.Debugf("collecting statistics for resource: %s", res) | 88 | level.Debug(c.logger).Log("msg", "collecting statistics for resource", "resource", res) |
85 | vals, err := c.fs.PSIStatsForResource(res) | 89 | vals, err := c.fs.PSIStatsForResource(res) |
86 | if err != nil { | 90 | if err != nil { |
87 | log.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") | 91 | level.Debug(c.logger).Log("msg", "pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") |
88 | return nil | 92 | return nil |
89 | } | 93 | } |
90 | switch res { | 94 | switch res { |
@@ -97,7 +101,7 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { | |||
97 | ch <- prometheus.MustNewConstMetric(c.mem, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0) | 101 | ch <- prometheus.MustNewConstMetric(c.mem, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0) |
98 | ch <- prometheus.MustNewConstMetric(c.memFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0) | 102 | ch <- prometheus.MustNewConstMetric(c.memFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0) |
99 | default: | 103 | default: |
100 | log.Debugf("did not account for resource: %s", res) | 104 | level.Debug(c.logger).Log("msg", "did not account for resource", "resource", res) |
101 | } | 105 | } |
102 | } | 106 | } |
103 | 107 | ||
diff --git a/collector/processes_linux.go b/collector/processes_linux.go index bb18a69..3d64cbd 100644 --- a/collector/processes_linux.go +++ b/collector/processes_linux.go | |||
@@ -19,8 +19,9 @@ import ( | |||
19 | "fmt" | 19 | "fmt" |
20 | "os" | 20 | "os" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
23 | "github.com/go-kit/kit/log/level" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | ||
24 | "github.com/prometheus/procfs" | 25 | "github.com/prometheus/procfs" |
25 | ) | 26 | ) |
26 | 27 | ||
@@ -31,6 +32,7 @@ type processCollector struct { | |||
31 | procsState *prometheus.Desc | 32 | procsState *prometheus.Desc |
32 | pidUsed *prometheus.Desc | 33 | pidUsed *prometheus.Desc |
33 | pidMax *prometheus.Desc | 34 | pidMax *prometheus.Desc |
35 | logger log.Logger | ||
34 | } | 36 | } |
35 | 37 | ||
36 | func init() { | 38 | func init() { |
@@ -38,7 +40,7 @@ func init() { | |||
38 | } | 40 | } |
39 | 41 | ||
40 | // NewProcessStatCollector returns a new Collector exposing process data read from the proc filesystem. | 42 | // NewProcessStatCollector returns a new Collector exposing process data read from the proc filesystem. |
41 | func NewProcessStatCollector() (Collector, error) { | 43 | func NewProcessStatCollector(logger log.Logger) (Collector, error) { |
42 | fs, err := procfs.NewFS(*procPath) | 44 | fs, err := procfs.NewFS(*procPath) |
43 | if err != nil { | 45 | if err != nil { |
44 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 46 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -67,6 +69,7 @@ func NewProcessStatCollector() (Collector, error) { | |||
67 | pidMax: prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, "max_processes"), | 69 | pidMax: prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, "max_processes"), |
68 | "Number of max PIDs limit", nil, nil, | 70 | "Number of max PIDs limit", nil, nil, |
69 | ), | 71 | ), |
72 | logger: logger, | ||
70 | }, nil | 73 | }, nil |
71 | } | 74 | } |
72 | func (c *processCollector) Update(ch chan<- prometheus.Metric) error { | 75 | func (c *processCollector) Update(ch chan<- prometheus.Metric) error { |
@@ -108,11 +111,11 @@ func (c *processCollector) getAllocatedThreads() (int, map[string]int32, int, er | |||
108 | stat, err := pid.Stat() | 111 | stat, err := pid.Stat() |
109 | // PIDs can vanish between getting the list and getting stats. | 112 | // PIDs can vanish between getting the list and getting stats. |
110 | if os.IsNotExist(err) { | 113 | if os.IsNotExist(err) { |
111 | log.Debugf("file not found when retrieving stats for pid %v: %q", pid, err) | 114 | level.Debug(c.logger).Log("msg", "file not found when retrieving stats for pid", "pid", pid, "err", err) |
112 | continue | 115 | continue |
113 | } | 116 | } |
114 | if err != nil { | 117 | if err != nil { |
115 | log.Debugf("error reading stat for pid %v: %q", pid, err) | 118 | level.Debug(c.logger).Log("msg", "error reading stat for pid", "pid", pid, "err", err) |
116 | return 0, nil, 0, err | 119 | return 0, nil, 0, err |
117 | } | 120 | } |
118 | pids++ | 121 | pids++ |
diff --git a/collector/processes_linux_test.go b/collector/processes_linux_test.go index dc71ced..cb01fbb 100644 --- a/collector/processes_linux_test.go +++ b/collector/processes_linux_test.go | |||
@@ -16,6 +16,7 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "github.com/go-kit/kit/log" | ||
19 | "testing" | 20 | "testing" |
20 | 21 | ||
21 | "github.com/prometheus/procfs" | 22 | "github.com/prometheus/procfs" |
@@ -31,7 +32,7 @@ func TestReadProcessStatus(t *testing.T) { | |||
31 | if err != nil { | 32 | if err != nil { |
32 | t.Errorf("failed to open procfs: %v", err) | 33 | t.Errorf("failed to open procfs: %v", err) |
33 | } | 34 | } |
34 | c := processCollector{fs: fs} | 35 | c := processCollector{fs: fs, logger: log.NewNopLogger()} |
35 | pids, states, threads, err := c.getAllocatedThreads() | 36 | pids, states, threads, err := c.getAllocatedThreads() |
36 | if err != nil { | 37 | if err != nil { |
37 | t.Fatalf("Cannot retrieve data from procfs getAllocatedThreads function: %v ", err) | 38 | t.Fatalf("Cannot retrieve data from procfs getAllocatedThreads function: %v ", err) |
diff --git a/collector/qdisc_linux.go b/collector/qdisc_linux.go index 74757b3..daba199 100644 --- a/collector/qdisc_linux.go +++ b/collector/qdisc_linux.go | |||
@@ -21,6 +21,7 @@ import ( | |||
21 | "path/filepath" | 21 | "path/filepath" |
22 | 22 | ||
23 | "github.com/ema/qdisc" | 23 | "github.com/ema/qdisc" |
24 | "github.com/go-kit/kit/log" | ||
24 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
25 | "gopkg.in/alecthomas/kingpin.v2" | 26 | "gopkg.in/alecthomas/kingpin.v2" |
26 | ) | 27 | ) |
@@ -31,6 +32,7 @@ type qdiscStatCollector struct { | |||
31 | drops typedDesc | 32 | drops typedDesc |
32 | requeues typedDesc | 33 | requeues typedDesc |
33 | overlimits typedDesc | 34 | overlimits typedDesc |
35 | logger log.Logger | ||
34 | } | 36 | } |
35 | 37 | ||
36 | var ( | 38 | var ( |
@@ -42,7 +44,7 @@ func init() { | |||
42 | } | 44 | } |
43 | 45 | ||
44 | // NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics. | 46 | // NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics. |
45 | func NewQdiscStatCollector() (Collector, error) { | 47 | func NewQdiscStatCollector(logger log.Logger) (Collector, error) { |
46 | return &qdiscStatCollector{ | 48 | return &qdiscStatCollector{ |
47 | bytes: typedDesc{prometheus.NewDesc( | 49 | bytes: typedDesc{prometheus.NewDesc( |
48 | prometheus.BuildFQName(namespace, "qdisc", "bytes_total"), | 50 | prometheus.BuildFQName(namespace, "qdisc", "bytes_total"), |
@@ -69,6 +71,7 @@ func NewQdiscStatCollector() (Collector, error) { | |||
69 | "Number of overlimit packets.", | 71 | "Number of overlimit packets.", |
70 | []string{"device", "kind"}, nil, | 72 | []string{"device", "kind"}, nil, |
71 | ), prometheus.CounterValue}, | 73 | ), prometheus.CounterValue}, |
74 | logger: logger, | ||
72 | }, nil | 75 | }, nil |
73 | } | 76 | } |
74 | 77 | ||
diff --git a/collector/runit.go b/collector/runit.go index 2608e1b..9d88904 100644 --- a/collector/runit.go +++ b/collector/runit.go | |||
@@ -16,8 +16,9 @@ | |||
16 | package collector | 16 | package collector |
17 | 17 | ||
18 | import ( | 18 | import ( |
19 | "github.com/go-kit/kit/log" | ||
20 | "github.com/go-kit/kit/log/level" | ||
19 | "github.com/prometheus/client_golang/prometheus" | 21 | "github.com/prometheus/client_golang/prometheus" |
20 | "github.com/prometheus/common/log" | ||
21 | "github.com/soundcloud/go-runit/runit" | 22 | "github.com/soundcloud/go-runit/runit" |
22 | "gopkg.in/alecthomas/kingpin.v2" | 23 | "gopkg.in/alecthomas/kingpin.v2" |
23 | ) | 24 | ) |
@@ -25,7 +26,11 @@ import ( | |||
25 | var runitServiceDir = kingpin.Flag("collector.runit.servicedir", "Path to runit service directory.").Default("/etc/service").String() | 26 | var runitServiceDir = kingpin.Flag("collector.runit.servicedir", "Path to runit service directory.").Default("/etc/service").String() |
26 | 27 | ||
27 | type runitCollector struct { | 28 | type runitCollector struct { |
28 | state, stateDesired, stateNormal, stateTimestamp typedDesc | 29 | state typedDesc |
30 | stateDesired typedDesc | ||
31 | stateNormal typedDesc | ||
32 | stateTimestamp typedDesc | ||
33 | logger log.Logger | ||
29 | } | 34 | } |
30 | 35 | ||
31 | func init() { | 36 | func init() { |
@@ -33,7 +38,7 @@ func init() { | |||
33 | } | 38 | } |
34 | 39 | ||
35 | // NewRunitCollector returns a new Collector exposing runit statistics. | 40 | // NewRunitCollector returns a new Collector exposing runit statistics. |
36 | func NewRunitCollector() (Collector, error) { | 41 | func NewRunitCollector(logger log.Logger) (Collector, error) { |
37 | var ( | 42 | var ( |
38 | subsystem = "service" | 43 | subsystem = "service" |
39 | constLabels = prometheus.Labels{"supervisor": "runit"} | 44 | constLabels = prometheus.Labels{"supervisor": "runit"} |
@@ -61,6 +66,7 @@ func NewRunitCollector() (Collector, error) { | |||
61 | "Unix timestamp of the last runit service state change.", | 66 | "Unix timestamp of the last runit service state change.", |
62 | labelNames, constLabels, | 67 | labelNames, constLabels, |
63 | ), prometheus.GaugeValue}, | 68 | ), prometheus.GaugeValue}, |
69 | logger: logger, | ||
64 | }, nil | 70 | }, nil |
65 | } | 71 | } |
66 | 72 | ||
@@ -73,11 +79,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error { | |||
73 | for _, service := range services { | 79 | for _, service := range services { |
74 | status, err := service.Status() | 80 | status, err := service.Status() |
75 | if err != nil { | 81 | if err != nil { |
76 | log.Debugf("Couldn't get status for %s: %s, skipping...", service.Name, err) | 82 | level.Debug(c.logger).Log("msg", "Couldn't get status", "service", service.Name, "err", err) |
77 | continue | 83 | continue |
78 | } | 84 | } |
79 | 85 | ||
80 | log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration) | 86 | level.Debug(c.logger).Log("msg", "duration", "service", service.Name, "status", status.State, "pid", status.Pid, "duration_seconds", status.Duration) |
81 | ch <- c.state.mustNewConstMetric(float64(status.State), service.Name) | 87 | ch <- c.state.mustNewConstMetric(float64(status.State), service.Name) |
82 | ch <- c.stateDesired.mustNewConstMetric(float64(status.Want), service.Name) | 88 | ch <- c.stateDesired.mustNewConstMetric(float64(status.Want), service.Name) |
83 | ch <- c.stateTimestamp.mustNewConstMetric(float64(status.Timestamp.Unix()), service.Name) | 89 | ch <- c.stateTimestamp.mustNewConstMetric(float64(status.Timestamp.Unix()), service.Name) |
diff --git a/collector/schedstat_linux.go b/collector/schedstat_linux.go index 1c91a47..6810b93 100644 --- a/collector/schedstat_linux.go +++ b/collector/schedstat_linux.go | |||
@@ -16,6 +16,7 @@ package collector | |||
16 | import ( | 16 | import ( |
17 | "fmt" | 17 | "fmt" |
18 | 18 | ||
19 | "github.com/go-kit/kit/log" | ||
19 | "github.com/prometheus/client_golang/prometheus" | 20 | "github.com/prometheus/client_golang/prometheus" |
20 | "github.com/prometheus/procfs" | 21 | "github.com/prometheus/procfs" |
21 | ) | 22 | ) |
@@ -46,17 +47,18 @@ var ( | |||
46 | ) | 47 | ) |
47 | 48 | ||
48 | // NewSchedstatCollector returns a new Collector exposing task scheduler statistics | 49 | // NewSchedstatCollector returns a new Collector exposing task scheduler statistics |
49 | func NewSchedstatCollector() (Collector, error) { | 50 | func NewSchedstatCollector(logger log.Logger) (Collector, error) { |
50 | fs, err := procfs.NewFS(*procPath) | 51 | fs, err := procfs.NewFS(*procPath) |
51 | if err != nil { | 52 | if err != nil { |
52 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 53 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
53 | } | 54 | } |
54 | 55 | ||
55 | return &schedstatCollector{fs: fs}, nil | 56 | return &schedstatCollector{fs, logger}, nil |
56 | } | 57 | } |
57 | 58 | ||
58 | type schedstatCollector struct { | 59 | type schedstatCollector struct { |
59 | fs procfs.FS | 60 | fs procfs.FS |
61 | logger log.Logger | ||
60 | } | 62 | } |
61 | 63 | ||
62 | func init() { | 64 | func init() { |
diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index fceb0ed..c7596c9 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go | |||
@@ -19,8 +19,9 @@ import ( | |||
19 | "fmt" | 19 | "fmt" |
20 | "os" | 20 | "os" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
23 | "github.com/go-kit/kit/log/level" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | ||
24 | "github.com/prometheus/procfs" | 25 | "github.com/prometheus/procfs" |
25 | ) | 26 | ) |
26 | 27 | ||
@@ -31,15 +32,17 @@ const ( | |||
31 | // Used for calculating the total memory bytes on TCP and UDP. | 32 | // Used for calculating the total memory bytes on TCP and UDP. |
32 | var pageSize = os.Getpagesize() | 33 | var pageSize = os.Getpagesize() |
33 | 34 | ||
34 | type sockStatCollector struct{} | 35 | type sockStatCollector struct { |
36 | logger log.Logger | ||
37 | } | ||
35 | 38 | ||
36 | func init() { | 39 | func init() { |
37 | registerCollector(sockStatSubsystem, defaultEnabled, NewSockStatCollector) | 40 | registerCollector(sockStatSubsystem, defaultEnabled, NewSockStatCollector) |
38 | } | 41 | } |
39 | 42 | ||
40 | // NewSockStatCollector returns a new Collector exposing socket stats. | 43 | // NewSockStatCollector returns a new Collector exposing socket stats. |
41 | func NewSockStatCollector() (Collector, error) { | 44 | func NewSockStatCollector(logger log.Logger) (Collector, error) { |
42 | return &sockStatCollector{}, nil | 45 | return &sockStatCollector{logger}, nil |
43 | } | 46 | } |
44 | 47 | ||
45 | func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { | 48 | func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { |
@@ -53,7 +56,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { | |||
53 | switch { | 56 | switch { |
54 | case err == nil: | 57 | case err == nil: |
55 | case os.IsNotExist(err): | 58 | case os.IsNotExist(err): |
56 | log.Debug("IPv4 sockstat statistics not found, skipping") | 59 | level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") |
57 | default: | 60 | default: |
58 | return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) | 61 | return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) |
59 | } | 62 | } |
@@ -62,7 +65,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { | |||
62 | switch { | 65 | switch { |
63 | case err == nil: | 66 | case err == nil: |
64 | case os.IsNotExist(err): | 67 | case os.IsNotExist(err): |
65 | log.Debug("IPv6 sockstat statistics not found, skipping") | 68 | level.Debug(c.logger).Log("msg", "IPv6 sockstat statistics not found, skipping") |
66 | default: | 69 | default: |
67 | return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) | 70 | return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) |
68 | } | 71 | } |
diff --git a/collector/stat_linux.go b/collector/stat_linux.go index 5e51d96..667d962 100644 --- a/collector/stat_linux.go +++ b/collector/stat_linux.go | |||
@@ -18,9 +18,9 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/prometheus/procfs" | 21 | "github.com/go-kit/kit/log" |
22 | |||
23 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/procfs" | ||
24 | ) | 24 | ) |
25 | 25 | ||
26 | type statCollector struct { | 26 | type statCollector struct { |
@@ -31,6 +31,7 @@ type statCollector struct { | |||
31 | btime *prometheus.Desc | 31 | btime *prometheus.Desc |
32 | procsRunning *prometheus.Desc | 32 | procsRunning *prometheus.Desc |
33 | procsBlocked *prometheus.Desc | 33 | procsBlocked *prometheus.Desc |
34 | logger log.Logger | ||
34 | } | 35 | } |
35 | 36 | ||
36 | func init() { | 37 | func init() { |
@@ -38,7 +39,7 @@ func init() { | |||
38 | } | 39 | } |
39 | 40 | ||
40 | // NewStatCollector returns a new Collector exposing kernel/system statistics. | 41 | // NewStatCollector returns a new Collector exposing kernel/system statistics. |
41 | func NewStatCollector() (Collector, error) { | 42 | func NewStatCollector(logger log.Logger) (Collector, error) { |
42 | fs, err := procfs.NewFS(*procPath) | 43 | fs, err := procfs.NewFS(*procPath) |
43 | if err != nil { | 44 | if err != nil { |
44 | return nil, fmt.Errorf("failed to open procfs: %w", err) | 45 | return nil, fmt.Errorf("failed to open procfs: %w", err) |
@@ -75,6 +76,7 @@ func NewStatCollector() (Collector, error) { | |||
75 | "Number of processes blocked waiting for I/O to complete.", | 76 | "Number of processes blocked waiting for I/O to complete.", |
76 | nil, nil, | 77 | nil, nil, |
77 | ), | 78 | ), |
79 | logger: logger, | ||
78 | }, nil | 80 | }, nil |
79 | } | 81 | } |
80 | 82 | ||
diff --git a/collector/supervisord.go b/collector/supervisord.go index 0e32540..a182062 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go | |||
@@ -18,9 +18,10 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
22 | "github.com/go-kit/kit/log/level" | ||
21 | "github.com/mattn/go-xmlrpc" | 23 | "github.com/mattn/go-xmlrpc" |
22 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/common/log" | ||
24 | "gopkg.in/alecthomas/kingpin.v2" | 25 | "gopkg.in/alecthomas/kingpin.v2" |
25 | ) | 26 | ) |
26 | 27 | ||
@@ -33,6 +34,7 @@ type supervisordCollector struct { | |||
33 | stateDesc *prometheus.Desc | 34 | stateDesc *prometheus.Desc |
34 | exitStatusDesc *prometheus.Desc | 35 | exitStatusDesc *prometheus.Desc |
35 | startTimeDesc *prometheus.Desc | 36 | startTimeDesc *prometheus.Desc |
37 | logger log.Logger | ||
36 | } | 38 | } |
37 | 39 | ||
38 | func init() { | 40 | func init() { |
@@ -40,7 +42,7 @@ func init() { | |||
40 | } | 42 | } |
41 | 43 | ||
42 | // NewSupervisordCollector returns a new Collector exposing supervisord statistics. | 44 | // NewSupervisordCollector returns a new Collector exposing supervisord statistics. |
43 | func NewSupervisordCollector() (Collector, error) { | 45 | func NewSupervisordCollector(logger log.Logger) (Collector, error) { |
44 | var ( | 46 | var ( |
45 | subsystem = "supervisord" | 47 | subsystem = "supervisord" |
46 | labelNames = []string{"name", "group"} | 48 | labelNames = []string{"name", "group"} |
@@ -70,6 +72,7 @@ func NewSupervisordCollector() (Collector, error) { | |||
70 | labelNames, | 72 | labelNames, |
71 | nil, | 73 | nil, |
72 | ), | 74 | ), |
75 | logger: logger, | ||
73 | }, nil | 76 | }, nil |
74 | } | 77 | } |
75 | 78 | ||
@@ -147,7 +150,7 @@ func (c *supervisordCollector) Update(ch chan<- prometheus.Metric) error { | |||
147 | } else { | 150 | } else { |
148 | ch <- prometheus.MustNewConstMetric(c.upDesc, prometheus.GaugeValue, 0, labels...) | 151 | ch <- prometheus.MustNewConstMetric(c.upDesc, prometheus.GaugeValue, 0, labels...) |
149 | } | 152 | } |
150 | log.Debugf("%s:%s is %s on pid %d", info.Group, info.Name, info.StateName, info.PID) | 153 | level.Debug(c.logger).Log("msg", "process info", "group", info.Group, "name", info.Name, "state", info.StateName, "pid", info.PID) |
151 | } | 154 | } |
152 | 155 | ||
153 | return nil | 156 | return nil |
diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index eb1fa78..3c55f4d 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go | |||
@@ -25,8 +25,9 @@ import ( | |||
25 | "time" | 25 | "time" |
26 | 26 | ||
27 | "github.com/coreos/go-systemd/dbus" | 27 | "github.com/coreos/go-systemd/dbus" |
28 | "github.com/go-kit/kit/log" | ||
29 | "github.com/go-kit/kit/log/level" | ||
28 | "github.com/prometheus/client_golang/prometheus" | 30 | "github.com/prometheus/client_golang/prometheus" |
29 | "github.com/prometheus/common/log" | ||
30 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 31 | kingpin "gopkg.in/alecthomas/kingpin.v2" |
31 | ) | 32 | ) |
32 | 33 | ||
@@ -62,6 +63,7 @@ type systemdCollector struct { | |||
62 | systemdVersion int | 63 | systemdVersion int |
63 | unitWhitelistPattern *regexp.Regexp | 64 | unitWhitelistPattern *regexp.Regexp |
64 | unitBlacklistPattern *regexp.Regexp | 65 | unitBlacklistPattern *regexp.Regexp |
66 | logger log.Logger | ||
65 | } | 67 | } |
66 | 68 | ||
67 | var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"} | 69 | var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"} |
@@ -71,7 +73,7 @@ func init() { | |||
71 | } | 73 | } |
72 | 74 | ||
73 | // NewSystemdCollector returns a new Collector exposing systemd statistics. | 75 | // NewSystemdCollector returns a new Collector exposing systemd statistics. |
74 | func NewSystemdCollector() (Collector, error) { | 76 | func NewSystemdCollector(logger log.Logger) (Collector, error) { |
75 | const subsystem = "systemd" | 77 | const subsystem = "systemd" |
76 | 78 | ||
77 | unitDesc := prometheus.NewDesc( | 79 | unitDesc := prometheus.NewDesc( |
@@ -119,10 +121,10 @@ func NewSystemdCollector() (Collector, error) { | |||
119 | unitWhitelistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitWhitelist)) | 121 | unitWhitelistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitWhitelist)) |
120 | unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist)) | 122 | unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist)) |
121 | 123 | ||
122 | systemdVersion := getSystemdVersion() | 124 | systemdVersion := getSystemdVersion(logger) |
123 | if systemdVersion < minSystemdVersionSystemState { | 125 | if systemdVersion < minSystemdVersionSystemState { |
124 | log.Warnf("Detected systemd version %v is lower than minimum %v", systemdVersion, minSystemdVersionSystemState) | 126 | level.Warn(logger).Log("msg", "Detected systemd version is lower than minimum", "current", systemdVersion, "minimum", minSystemdVersionSystemState) |
125 | log.Warn("Some systemd state and timer metrics will not be available") | 127 | level.Warn(logger).Log("msg", "Some systemd state and timer metrics will not be available") |
126 | } | 128 | } |
127 | 129 | ||
128 | return &systemdCollector{ | 130 | return &systemdCollector{ |
@@ -141,6 +143,7 @@ func NewSystemdCollector() (Collector, error) { | |||
141 | systemdVersion: systemdVersion, | 143 | systemdVersion: systemdVersion, |
142 | unitWhitelistPattern: unitWhitelistPattern, | 144 | unitWhitelistPattern: unitWhitelistPattern, |
143 | unitBlacklistPattern: unitBlacklistPattern, | 145 | unitBlacklistPattern: unitBlacklistPattern, |
146 | logger: logger, | ||
144 | }, nil | 147 | }, nil |
145 | } | 148 | } |
146 | 149 | ||
@@ -158,16 +161,16 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
158 | if err != nil { | 161 | if err != nil { |
159 | return fmt.Errorf("couldn't get units: %s", err) | 162 | return fmt.Errorf("couldn't get units: %s", err) |
160 | } | 163 | } |
161 | log.Debugf("systemd getAllUnits took %f", time.Since(begin).Seconds()) | 164 | level.Debug(c.logger).Log("msg", "getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) |
162 | 165 | ||
163 | begin = time.Now() | 166 | begin = time.Now() |
164 | summary := summarizeUnits(allUnits) | 167 | summary := summarizeUnits(allUnits) |
165 | c.collectSummaryMetrics(ch, summary) | 168 | c.collectSummaryMetrics(ch, summary) |
166 | log.Debugf("systemd collectSummaryMetrics took %f", time.Since(begin).Seconds()) | 169 | level.Debug(c.logger).Log("msg", "collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds()) |
167 | 170 | ||
168 | begin = time.Now() | 171 | begin = time.Now() |
169 | units := filterUnits(allUnits, c.unitWhitelistPattern, c.unitBlacklistPattern) | 172 | units := filterUnits(allUnits, c.unitWhitelistPattern, c.unitBlacklistPattern, c.logger) |
170 | log.Debugf("systemd filterUnits took %f", time.Since(begin).Seconds()) | 173 | level.Debug(c.logger).Log("msg", "filterUnits took", "duration_seconds", time.Since(begin).Seconds()) |
171 | 174 | ||
172 | var wg sync.WaitGroup | 175 | var wg sync.WaitGroup |
173 | defer wg.Wait() | 176 | defer wg.Wait() |
@@ -177,7 +180,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
177 | defer wg.Done() | 180 | defer wg.Done() |
178 | begin = time.Now() | 181 | begin = time.Now() |
179 | c.collectUnitStatusMetrics(conn, ch, units) | 182 | c.collectUnitStatusMetrics(conn, ch, units) |
180 | log.Debugf("systemd collectUnitStatusMetrics took %f", time.Since(begin).Seconds()) | 183 | level.Debug(c.logger).Log("msg", "collectUnitStatusMetrics took", "duration_seconds", time.Since(begin).Seconds()) |
181 | }() | 184 | }() |
182 | 185 | ||
183 | if *enableStartTimeMetrics { | 186 | if *enableStartTimeMetrics { |
@@ -186,7 +189,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
186 | defer wg.Done() | 189 | defer wg.Done() |
187 | begin = time.Now() | 190 | begin = time.Now() |
188 | c.collectUnitStartTimeMetrics(conn, ch, units) | 191 | c.collectUnitStartTimeMetrics(conn, ch, units) |
189 | log.Debugf("systemd collectUnitStartTimeMetrics took %f", time.Since(begin).Seconds()) | 192 | level.Debug(c.logger).Log("msg", "collectUnitStartTimeMetrics took", "duration_seconds", time.Since(begin).Seconds()) |
190 | }() | 193 | }() |
191 | } | 194 | } |
192 | 195 | ||
@@ -196,7 +199,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
196 | defer wg.Done() | 199 | defer wg.Done() |
197 | begin = time.Now() | 200 | begin = time.Now() |
198 | c.collectUnitTasksMetrics(conn, ch, units) | 201 | c.collectUnitTasksMetrics(conn, ch, units) |
199 | log.Debugf("systemd collectUnitTasksMetrics took %f", time.Since(begin).Seconds()) | 202 | level.Debug(c.logger).Log("msg", "collectUnitTasksMetrics took", "duration_seconds", time.Since(begin).Seconds()) |
200 | }() | 203 | }() |
201 | } | 204 | } |
202 | 205 | ||
@@ -206,7 +209,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
206 | defer wg.Done() | 209 | defer wg.Done() |
207 | begin = time.Now() | 210 | begin = time.Now() |
208 | c.collectTimers(conn, ch, units) | 211 | c.collectTimers(conn, ch, units) |
209 | log.Debugf("systemd collectTimers took %f", time.Since(begin).Seconds()) | 212 | level.Debug(c.logger).Log("msg", "collectTimers took", "duration_seconds", time.Since(begin).Seconds()) |
210 | }() | 213 | }() |
211 | } | 214 | } |
212 | 215 | ||
@@ -215,13 +218,13 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { | |||
215 | defer wg.Done() | 218 | defer wg.Done() |
216 | begin = time.Now() | 219 | begin = time.Now() |
217 | c.collectSockets(conn, ch, units) | 220 | c.collectSockets(conn, ch, units) |
218 | log.Debugf("systemd collectSockets took %f", time.Since(begin).Seconds()) | 221 | level.Debug(c.logger).Log("msg", "collectSockets took", "duration_seconds", time.Since(begin).Seconds()) |
219 | }() | 222 | }() |
220 | 223 | ||
221 | if c.systemdVersion >= minSystemdVersionSystemState { | 224 | if c.systemdVersion >= minSystemdVersionSystemState { |
222 | begin = time.Now() | 225 | begin = time.Now() |
223 | err = c.collectSystemState(conn, ch) | 226 | err = c.collectSystemState(conn, ch) |
224 | log.Debugf("systemd collectSystemState took %f", time.Since(begin).Seconds()) | 227 | level.Debug(c.logger).Log("msg", "collectSystemState took", "duration_seconds", time.Since(begin).Seconds()) |
225 | } | 228 | } |
226 | 229 | ||
227 | ch <- prometheus.MustNewConstMetric( | 230 | ch <- prometheus.MustNewConstMetric( |
@@ -236,14 +239,14 @@ func (c *systemdCollector) collectUnitStatusMetrics(conn *dbus.Conn, ch chan<- p | |||
236 | if strings.HasSuffix(unit.Name, ".service") { | 239 | if strings.HasSuffix(unit.Name, ".service") { |
237 | serviceTypeProperty, err := conn.GetUnitTypeProperty(unit.Name, "Service", "Type") | 240 | serviceTypeProperty, err := conn.GetUnitTypeProperty(unit.Name, "Service", "Type") |
238 | if err != nil { | 241 | if err != nil { |
239 | log.Debugf("couldn't get unit '%s' Type: %s", unit.Name, err) | 242 | level.Debug(c.logger).Log("msg", "couldn't get unit type", "unit", unit.Name, "err", err) |
240 | } else { | 243 | } else { |
241 | serviceType = serviceTypeProperty.Value.Value().(string) | 244 | serviceType = serviceTypeProperty.Value.Value().(string) |
242 | } | 245 | } |
243 | } else if strings.HasSuffix(unit.Name, ".mount") { | 246 | } else if strings.HasSuffix(unit.Name, ".mount") { |
244 | serviceTypeProperty, err := conn.GetUnitTypeProperty(unit.Name, "Mount", "Type") | 247 | serviceTypeProperty, err := conn.GetUnitTypeProperty(unit.Name, "Mount", "Type") |
245 | if err != nil { | 248 | if err != nil { |
246 | log.Debugf("couldn't get unit '%s' Type: %s", unit.Name, err) | 249 | level.Debug(c.logger).Log("msg", "couldn't get unit type", "unit", unit.Name, "err", err) |
247 | } else { | 250 | } else { |
248 | serviceType = serviceTypeProperty.Value.Value().(string) | 251 | serviceType = serviceTypeProperty.Value.Value().(string) |
249 | } | 252 | } |
@@ -261,7 +264,7 @@ func (c *systemdCollector) collectUnitStatusMetrics(conn *dbus.Conn, ch chan<- p | |||
261 | // NRestarts wasn't added until systemd 235. | 264 | // NRestarts wasn't added until systemd 235. |
262 | restartsCount, err := conn.GetUnitTypeProperty(unit.Name, "Service", "NRestarts") | 265 | restartsCount, err := conn.GetUnitTypeProperty(unit.Name, "Service", "NRestarts") |
263 | if err != nil { | 266 | if err != nil { |
264 | log.Debugf("couldn't get unit '%s' NRestarts: %s", unit.Name, err) | 267 | level.Debug(c.logger).Log("msg", "couldn't get unit NRestarts", "unit", unit.Name, "err", err) |
265 | } else { | 268 | } else { |
266 | ch <- prometheus.MustNewConstMetric( | 269 | ch <- prometheus.MustNewConstMetric( |
267 | c.nRestartsDesc, prometheus.CounterValue, | 270 | c.nRestartsDesc, prometheus.CounterValue, |
@@ -279,7 +282,7 @@ func (c *systemdCollector) collectSockets(conn *dbus.Conn, ch chan<- prometheus. | |||
279 | 282 | ||
280 | acceptedConnectionCount, err := conn.GetUnitTypeProperty(unit.Name, "Socket", "NAccepted") | 283 | acceptedConnectionCount, err := conn.GetUnitTypeProperty(unit.Name, "Socket", "NAccepted") |
281 | if err != nil { | 284 | if err != nil { |
282 | log.Debugf("couldn't get unit '%s' NAccepted: %s", unit.Name, err) | 285 | level.Debug(c.logger).Log("msg", "couldn't get unit NAccepted", "unit", unit.Name, "err", err) |
283 | continue | 286 | continue |
284 | } | 287 | } |
285 | ch <- prometheus.MustNewConstMetric( | 288 | ch <- prometheus.MustNewConstMetric( |
@@ -288,7 +291,7 @@ func (c *systemdCollector) collectSockets(conn *dbus.Conn, ch chan<- prometheus. | |||
288 | 291 | ||
289 | currentConnectionCount, err := conn.GetUnitTypeProperty(unit.Name, "Socket", "NConnections") | 292 | currentConnectionCount, err := conn.GetUnitTypeProperty(unit.Name, "Socket", "NConnections") |
290 | if err != nil { | 293 | if err != nil { |
291 | log.Debugf("couldn't get unit '%s' NConnections: %s", unit.Name, err) | 294 | level.Debug(c.logger).Log("msg", "couldn't get unit NConnections", "unit", unit.Name, "err", err) |
292 | continue | 295 | continue |
293 | } | 296 | } |
294 | ch <- prometheus.MustNewConstMetric( | 297 | ch <- prometheus.MustNewConstMetric( |
@@ -316,7 +319,7 @@ func (c *systemdCollector) collectUnitStartTimeMetrics(conn *dbus.Conn, ch chan< | |||
316 | } else { | 319 | } else { |
317 | timestampValue, err := conn.GetUnitProperty(unit.Name, "ActiveEnterTimestamp") | 320 | timestampValue, err := conn.GetUnitProperty(unit.Name, "ActiveEnterTimestamp") |
318 | if err != nil { | 321 | if err != nil { |
319 | log.Debugf("couldn't get unit '%s' StartTimeUsec: %s", unit.Name, err) | 322 | level.Debug(c.logger).Log("msg", "couldn't get unit StartTimeUsec", "unit", unit.Name, "err", err) |
320 | continue | 323 | continue |
321 | } | 324 | } |
322 | startTimeUsec = timestampValue.Value.Value().(uint64) | 325 | startTimeUsec = timestampValue.Value.Value().(uint64) |
@@ -334,7 +337,7 @@ func (c *systemdCollector) collectUnitTasksMetrics(conn *dbus.Conn, ch chan<- pr | |||
334 | if strings.HasSuffix(unit.Name, ".service") { | 337 | if strings.HasSuffix(unit.Name, ".service") { |
335 | tasksCurrentCount, err := conn.GetUnitTypeProperty(unit.Name, "Service", "TasksCurrent") | 338 | tasksCurrentCount, err := conn.GetUnitTypeProperty(unit.Name, "Service", "TasksCurrent") |
336 | if err != nil { | 339 | if err != nil { |
337 | log.Debugf("couldn't get unit '%s' TasksCurrent: %s", unit.Name, err) | 340 | level.Debug(c.logger).Log("msg", "couldn't get unit TasksCurrent", "unit", unit.Name, "err", err) |
338 | } else { | 341 | } else { |
339 | val = tasksCurrentCount.Value.Value().(uint64) | 342 | val = tasksCurrentCount.Value.Value().(uint64) |
340 | // Don't set if tasksCurrent if dbus reports MaxUint64. | 343 | // Don't set if tasksCurrent if dbus reports MaxUint64. |
@@ -346,7 +349,7 @@ func (c *systemdCollector) collectUnitTasksMetrics(conn *dbus.Conn, ch chan<- pr | |||
346 | } | 349 | } |
347 | tasksMaxCount, err := conn.GetUnitTypeProperty(unit.Name, "Service", "TasksMax") | 350 | tasksMaxCount, err := conn.GetUnitTypeProperty(unit.Name, "Service", "TasksMax") |
348 | if err != nil { | 351 | if err != nil { |
349 | log.Debugf("couldn't get unit '%s' TasksMax: %s", unit.Name, err) | 352 | level.Debug(c.logger).Log("msg", "couldn't get unit TasksMax", "unit", unit.Name, "err", err) |
350 | } else { | 353 | } else { |
351 | val = tasksMaxCount.Value.Value().(uint64) | 354 | val = tasksMaxCount.Value.Value().(uint64) |
352 | // Don't set if tasksMax if dbus reports MaxUint64. | 355 | // Don't set if tasksMax if dbus reports MaxUint64. |
@@ -368,7 +371,7 @@ func (c *systemdCollector) collectTimers(conn *dbus.Conn, ch chan<- prometheus.M | |||
368 | 371 | ||
369 | lastTriggerValue, err := conn.GetUnitTypeProperty(unit.Name, "Timer", "LastTriggerUSec") | 372 | lastTriggerValue, err := conn.GetUnitTypeProperty(unit.Name, "Timer", "LastTriggerUSec") |
370 | if err != nil { | 373 | if err != nil { |
371 | log.Debugf("couldn't get unit '%s' LastTriggerUSec: %s", unit.Name, err) | 374 | level.Debug(c.logger).Log("msg", "couldn't get unit LastTriggerUSec", "unit", unit.Name, "err", err) |
372 | continue | 375 | continue |
373 | } | 376 | } |
374 | 377 | ||
@@ -440,36 +443,36 @@ func summarizeUnits(units []unit) map[string]float64 { | |||
440 | return summarized | 443 | return summarized |
441 | } | 444 | } |
442 | 445 | ||
443 | func filterUnits(units []unit, whitelistPattern, blacklistPattern *regexp.Regexp) []unit { | 446 | func filterUnits(units []unit, whitelistPattern, blacklistPattern *regexp.Regexp, logger log.Logger) []unit { |
444 | filtered := make([]unit, 0, len(units)) | 447 | filtered := make([]unit, 0, len(units)) |
445 | for _, unit := range units { | 448 | for _, unit := range units { |
446 | if whitelistPattern.MatchString(unit.Name) && !blacklistPattern.MatchString(unit.Name) && unit.LoadState == "loaded" { | 449 | if whitelistPattern.MatchString(unit.Name) && !blacklistPattern.MatchString(unit.Name) && unit.LoadState == "loaded" { |
447 | log.Debugf("Adding unit: %s", unit.Name) | 450 | level.Debug(logger).Log("msg", "Adding unit", "unit", unit.Name) |
448 | filtered = append(filtered, unit) | 451 | filtered = append(filtered, unit) |
449 | } else { | 452 | } else { |
450 | log.Debugf("Ignoring unit: %s", unit.Name) | 453 | level.Debug(logger).Log("msg", "Ignoring unit", "unit", unit.Name) |
451 | } | 454 | } |
452 | } | 455 | } |
453 | 456 | ||
454 | return filtered | 457 | return filtered |
455 | } | 458 | } |
456 | 459 | ||
457 | func getSystemdVersion() int { | 460 | func getSystemdVersion(logger log.Logger) int { |
458 | conn, err := newSystemdDbusConn() | 461 | conn, err := newSystemdDbusConn() |
459 | if err != nil { | 462 | if err != nil { |
460 | log.Warnf("Unable to get systemd dbus connection, defaulting systemd version to 0: %s", err) | 463 | level.Warn(logger).Log("msg", "Unable to get systemd dbus connection, defaulting systemd version to 0", "err", err) |
461 | return 0 | 464 | return 0 |
462 | } | 465 | } |
463 | defer conn.Close() | 466 | defer conn.Close() |
464 | version, err := conn.GetManagerProperty("Version") | 467 | version, err := conn.GetManagerProperty("Version") |
465 | if err != nil { | 468 | if err != nil { |
466 | log.Warn("Unable to get systemd version property, defaulting to 0") | 469 | level.Warn(logger).Log("msg", "Unable to get systemd version property, defaulting to 0") |
467 | return 0 | 470 | return 0 |
468 | } | 471 | } |
469 | version = strings.Replace(version, "\"", "", 2) | 472 | version = strings.Replace(version, "\"", "", 2) |
470 | v, err := strconv.Atoi(version) | 473 | v, err := strconv.Atoi(version) |
471 | if err != nil { | 474 | if err != nil { |
472 | log.Warnf("Got invalid systemd version: %v", version) | 475 | level.Warn(logger).Log("msg", "Got invalid systemd version", "version", version) |
473 | return 0 | 476 | return 0 |
474 | } | 477 | } |
475 | return v | 478 | return v |
diff --git a/collector/systemd_linux_test.go b/collector/systemd_linux_test.go index b2298d6..613a1ab 100644 --- a/collector/systemd_linux_test.go +++ b/collector/systemd_linux_test.go | |||
@@ -14,6 +14,7 @@ | |||
14 | package collector | 14 | package collector |
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "github.com/go-kit/kit/log" | ||
17 | "regexp" | 18 | "regexp" |
18 | "testing" | 19 | "testing" |
19 | 20 | ||
@@ -90,7 +91,7 @@ func TestSystemdIgnoreFilter(t *testing.T) { | |||
90 | fixtures := getUnitListFixtures() | 91 | fixtures := getUnitListFixtures() |
91 | whitelistPattern := regexp.MustCompile("^foo$") | 92 | whitelistPattern := regexp.MustCompile("^foo$") |
92 | blacklistPattern := regexp.MustCompile("^bar$") | 93 | blacklistPattern := regexp.MustCompile("^bar$") |
93 | filtered := filterUnits(fixtures[0], whitelistPattern, blacklistPattern) | 94 | filtered := filterUnits(fixtures[0], whitelistPattern, blacklistPattern, log.NewNopLogger()) |
94 | for _, unit := range filtered { | 95 | for _, unit := range filtered { |
95 | if blacklistPattern.MatchString(unit.Name) || !whitelistPattern.MatchString(unit.Name) { | 96 | if blacklistPattern.MatchString(unit.Name) || !whitelistPattern.MatchString(unit.Name) { |
96 | t.Error(unit.Name, "should not be in the filtered list") | 97 | t.Error(unit.Name, "should not be in the filtered list") |
@@ -98,13 +99,14 @@ func TestSystemdIgnoreFilter(t *testing.T) { | |||
98 | } | 99 | } |
99 | } | 100 | } |
100 | func TestSystemdIgnoreFilterDefaultKeepsAll(t *testing.T) { | 101 | func TestSystemdIgnoreFilterDefaultKeepsAll(t *testing.T) { |
101 | c, err := NewSystemdCollector() | 102 | logger := log.NewNopLogger() |
103 | c, err := NewSystemdCollector(logger) | ||
102 | if err != nil { | 104 | if err != nil { |
103 | t.Fatal(err) | 105 | t.Fatal(err) |
104 | } | 106 | } |
105 | fixtures := getUnitListFixtures() | 107 | fixtures := getUnitListFixtures() |
106 | collector := c.(*systemdCollector) | 108 | collector := c.(*systemdCollector) |
107 | filtered := filterUnits(fixtures[0], collector.unitWhitelistPattern, collector.unitBlacklistPattern) | 109 | filtered := filterUnits(fixtures[0], collector.unitWhitelistPattern, collector.unitBlacklistPattern, logger) |
108 | // Adjust fixtures by 3 "not-found" units. | 110 | // Adjust fixtures by 3 "not-found" units. |
109 | if len(filtered) != len(fixtures[0])-3 { | 111 | if len(filtered) != len(fixtures[0])-3 { |
110 | t.Error("Default filters removed units") | 112 | t.Error("Default filters removed units") |
diff --git a/collector/tcpstat_linux.go b/collector/tcpstat_linux.go index cc4e960..9b09e9a 100644 --- a/collector/tcpstat_linux.go +++ b/collector/tcpstat_linux.go | |||
@@ -23,6 +23,7 @@ import ( | |||
23 | "strconv" | 23 | "strconv" |
24 | "strings" | 24 | "strings" |
25 | 25 | ||
26 | "github.com/go-kit/kit/log" | ||
26 | "github.com/prometheus/client_golang/prometheus" | 27 | "github.com/prometheus/client_golang/prometheus" |
27 | ) | 28 | ) |
28 | 29 | ||
@@ -54,7 +55,8 @@ const ( | |||
54 | ) | 55 | ) |
55 | 56 | ||
56 | type tcpStatCollector struct { | 57 | type tcpStatCollector struct { |
57 | desc typedDesc | 58 | desc typedDesc |
59 | logger log.Logger | ||
58 | } | 60 | } |
59 | 61 | ||
60 | func init() { | 62 | func init() { |
@@ -62,13 +64,14 @@ func init() { | |||
62 | } | 64 | } |
63 | 65 | ||
64 | // NewTCPStatCollector returns a new Collector exposing network stats. | 66 | // NewTCPStatCollector returns a new Collector exposing network stats. |
65 | func NewTCPStatCollector() (Collector, error) { | 67 | func NewTCPStatCollector(logger log.Logger) (Collector, error) { |
66 | return &tcpStatCollector{ | 68 | return &tcpStatCollector{ |
67 | desc: typedDesc{prometheus.NewDesc( | 69 | desc: typedDesc{prometheus.NewDesc( |
68 | prometheus.BuildFQName(namespace, "tcp", "connection_states"), | 70 | prometheus.BuildFQName(namespace, "tcp", "connection_states"), |
69 | "Number of connection states.", | 71 | "Number of connection states.", |
70 | []string{"state"}, nil, | 72 | []string{"state"}, nil, |
71 | ), prometheus.GaugeValue}, | 73 | ), prometheus.GaugeValue}, |
74 | logger: logger, | ||
72 | }, nil | 75 | }, nil |
73 | } | 76 | } |
74 | 77 | ||
diff --git a/collector/textfile.go b/collector/textfile.go index aee11db..64165e6 100644 --- a/collector/textfile.go +++ b/collector/textfile.go | |||
@@ -24,10 +24,11 @@ import ( | |||
24 | "strings" | 24 | "strings" |
25 | "time" | 25 | "time" |
26 | 26 | ||
27 | "github.com/go-kit/kit/log" | ||
28 | "github.com/go-kit/kit/log/level" | ||
27 | "github.com/prometheus/client_golang/prometheus" | 29 | "github.com/prometheus/client_golang/prometheus" |
28 | dto "github.com/prometheus/client_model/go" | 30 | dto "github.com/prometheus/client_model/go" |
29 | "github.com/prometheus/common/expfmt" | 31 | "github.com/prometheus/common/expfmt" |
30 | "github.com/prometheus/common/log" | ||
31 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 32 | kingpin "gopkg.in/alecthomas/kingpin.v2" |
32 | ) | 33 | ) |
33 | 34 | ||
@@ -44,7 +45,8 @@ var ( | |||
44 | type textFileCollector struct { | 45 | type textFileCollector struct { |
45 | path string | 46 | path string |
46 | // Only set for testing to get predictable output. | 47 | // Only set for testing to get predictable output. |
47 | mtime *float64 | 48 | mtime *float64 |
49 | logger log.Logger | ||
48 | } | 50 | } |
49 | 51 | ||
50 | func init() { | 52 | func init() { |
@@ -53,14 +55,15 @@ func init() { | |||
53 | 55 | ||
54 | // NewTextFileCollector returns a new Collector exposing metrics read from files | 56 | // NewTextFileCollector returns a new Collector exposing metrics read from files |
55 | // in the given textfile directory. | 57 | // in the given textfile directory. |
56 | func NewTextFileCollector() (Collector, error) { | 58 | func NewTextFileCollector(logger log.Logger) (Collector, error) { |
57 | c := &textFileCollector{ | 59 | c := &textFileCollector{ |
58 | path: *textFileDirectory, | 60 | path: *textFileDirectory, |
61 | logger: logger, | ||
59 | } | 62 | } |
60 | return c, nil | 63 | return c, nil |
61 | } | 64 | } |
62 | 65 | ||
63 | func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric) { | 66 | func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric, logger log.Logger) { |
64 | var valType prometheus.ValueType | 67 | var valType prometheus.ValueType |
65 | var val float64 | 68 | var val float64 |
66 | 69 | ||
@@ -76,7 +79,7 @@ func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Me | |||
76 | 79 | ||
77 | for _, metric := range metricFamily.Metric { | 80 | for _, metric := range metricFamily.Metric { |
78 | if metric.TimestampMs != nil { | 81 | if metric.TimestampMs != nil { |
79 | log.Warnf("Ignoring unsupported custom timestamp on textfile collector metric %v", metric) | 82 | level.Warn(logger).Log("msg", "Ignoring unsupported custom timestamp on textfile collector metric", "metric", metric) |
80 | } | 83 | } |
81 | 84 | ||
82 | labels := metric.GetLabel() | 85 | labels := metric.GetLabel() |
@@ -191,7 +194,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { | |||
191 | files, err := ioutil.ReadDir(c.path) | 194 | files, err := ioutil.ReadDir(c.path) |
192 | if err != nil && c.path != "" { | 195 | if err != nil && c.path != "" { |
193 | errored = true | 196 | errored = true |
194 | log.Errorf("failed to read textfile collector directory %q: %v", c.path, err) | 197 | level.Error(c.logger).Log("msg", "failed to read textfile collector directory", "path", c.path, "err", err) |
195 | } | 198 | } |
196 | 199 | ||
197 | mtimes := make(map[string]time.Time, len(files)) | 200 | mtimes := make(map[string]time.Time, len(files)) |
@@ -203,7 +206,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { | |||
203 | mtime, err := c.processFile(f.Name(), ch) | 206 | mtime, err := c.processFile(f.Name(), ch) |
204 | if err != nil { | 207 | if err != nil { |
205 | errored = true | 208 | errored = true |
206 | log.Errorf("failed to collect textfile data from %q: %v", f.Name(), err) | 209 | level.Error(c.logger).Log("msg", "failed to collect textfile data", "file", f.Name(), "err", err) |
207 | continue | 210 | continue |
208 | } | 211 | } |
209 | 212 | ||
@@ -257,7 +260,7 @@ func (c *textFileCollector) processFile(name string, ch chan<- prometheus.Metric | |||
257 | } | 260 | } |
258 | 261 | ||
259 | for _, mf := range families { | 262 | for _, mf := range families { |
260 | convertMetricFamily(mf, ch) | 263 | convertMetricFamily(mf, ch, c.logger) |
261 | } | 264 | } |
262 | 265 | ||
263 | // Only stat the file once it has been parsed and validated, so that | 266 | // Only stat the file once it has been parsed and validated, so that |
diff --git a/collector/textfile_test.go b/collector/textfile_test.go index fb1a700..f0e93a8 100644 --- a/collector/textfile_test.go +++ b/collector/textfile_test.go | |||
@@ -20,10 +20,12 @@ import ( | |||
20 | "net/http/httptest" | 20 | "net/http/httptest" |
21 | "testing" | 21 | "testing" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 24 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/client_golang/prometheus/promhttp" | 25 | "github.com/prometheus/client_golang/prometheus/promhttp" |
25 | "github.com/prometheus/common/log" | 26 | "github.com/prometheus/common/promlog" |
26 | kingpin "gopkg.in/alecthomas/kingpin.v2" | 27 | "github.com/prometheus/common/promlog/flag" |
28 | "gopkg.in/alecthomas/kingpin.v2" | ||
27 | ) | 29 | ) |
28 | 30 | ||
29 | type collectorAdapter struct { | 31 | type collectorAdapter struct { |
@@ -39,8 +41,7 @@ func (a collectorAdapter) Describe(ch chan<- *prometheus.Desc) { | |||
39 | 41 | ||
40 | // Collect implements the prometheus.Collector interface. | 42 | // Collect implements the prometheus.Collector interface. |
41 | func (a collectorAdapter) Collect(ch chan<- prometheus.Metric) { | 43 | func (a collectorAdapter) Collect(ch chan<- prometheus.Metric) { |
42 | err := a.Update(ch) | 44 | if err := a.Update(ch); err != nil { |
43 | if err != nil { | ||
44 | panic(fmt.Sprintf("failed to update collector: %v", err)) | 45 | panic(fmt.Sprintf("failed to update collector: %v", err)) |
45 | } | 46 | } |
46 | } | 47 | } |
@@ -95,15 +96,16 @@ func TestTextfileCollector(t *testing.T) { | |||
95 | for i, test := range tests { | 96 | for i, test := range tests { |
96 | mtime := 1.0 | 97 | mtime := 1.0 |
97 | c := &textFileCollector{ | 98 | c := &textFileCollector{ |
98 | path: test.path, | 99 | path: test.path, |
99 | mtime: &mtime, | 100 | mtime: &mtime, |
101 | logger: log.NewNopLogger(), | ||
100 | } | 102 | } |
101 | 103 | ||
102 | // Suppress a log message about `nonexistent_path` not existing, this is | 104 | // Suppress a log message about `nonexistent_path` not existing, this is |
103 | // expected and clutters the test output. | 105 | // expected and clutters the test output. |
104 | log.AddFlags(kingpin.CommandLine) | 106 | promlogConfig := &promlog.Config{} |
105 | _, err := kingpin.CommandLine.Parse([]string{"--log.level", "fatal"}) | 107 | flag.AddFlags(kingpin.CommandLine, promlogConfig) |
106 | if err != nil { | 108 | if _, err := kingpin.CommandLine.Parse([]string{"--log.level", "debug"}); err != nil { |
107 | t.Fatal(err) | 109 | t.Fatal(err) |
108 | } | 110 | } |
109 | 111 | ||
diff --git a/collector/thermal_zone_linux.go b/collector/thermal_zone_linux.go index b8a65cf..5d223bc 100644 --- a/collector/thermal_zone_linux.go +++ b/collector/thermal_zone_linux.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "fmt" | 19 | "fmt" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/prometheus/procfs/sysfs" | 23 | "github.com/prometheus/procfs/sysfs" |
23 | ) | 24 | ) |
@@ -30,6 +31,7 @@ type thermalZoneCollector struct { | |||
30 | coolingDeviceCurState *prometheus.Desc | 31 | coolingDeviceCurState *prometheus.Desc |
31 | coolingDeviceMaxState *prometheus.Desc | 32 | coolingDeviceMaxState *prometheus.Desc |
32 | zoneTemp *prometheus.Desc | 33 | zoneTemp *prometheus.Desc |
34 | logger log.Logger | ||
33 | } | 35 | } |
34 | 36 | ||
35 | func init() { | 37 | func init() { |
@@ -37,7 +39,7 @@ func init() { | |||
37 | } | 39 | } |
38 | 40 | ||
39 | // NewThermalZoneCollector returns a new Collector exposing kernel/system statistics. | 41 | // NewThermalZoneCollector returns a new Collector exposing kernel/system statistics. |
40 | func NewThermalZoneCollector() (Collector, error) { | 42 | func NewThermalZoneCollector(logger log.Logger) (Collector, error) { |
41 | fs, err := sysfs.NewFS(*sysPath) | 43 | fs, err := sysfs.NewFS(*sysPath) |
42 | if err != nil { | 44 | if err != nil { |
43 | return nil, fmt.Errorf("failed to open sysfs: %w", err) | 45 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
@@ -60,6 +62,7 @@ func NewThermalZoneCollector() (Collector, error) { | |||
60 | "Maximum throttle state of the cooling device", | 62 | "Maximum throttle state of the cooling device", |
61 | []string{"name", "type"}, nil, | 63 | []string{"name", "type"}, nil, |
62 | ), | 64 | ), |
65 | logger: logger, | ||
63 | }, nil | 66 | }, nil |
64 | } | 67 | } |
65 | 68 | ||
diff --git a/collector/time.go b/collector/time.go index eb57bd8..76a2d1e 100644 --- a/collector/time.go +++ b/collector/time.go | |||
@@ -18,12 +18,14 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "time" | 19 | "time" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
22 | "github.com/go-kit/kit/log/level" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/prometheus/common/log" | ||
23 | ) | 24 | ) |
24 | 25 | ||
25 | type timeCollector struct { | 26 | type timeCollector struct { |
26 | desc *prometheus.Desc | 27 | desc *prometheus.Desc |
28 | logger log.Logger | ||
27 | } | 29 | } |
28 | 30 | ||
29 | func init() { | 31 | func init() { |
@@ -32,19 +34,20 @@ func init() { | |||
32 | 34 | ||
33 | // NewTimeCollector returns a new Collector exposing the current system time in | 35 | // NewTimeCollector returns a new Collector exposing the current system time in |
34 | // seconds since epoch. | 36 | // seconds since epoch. |
35 | func NewTimeCollector() (Collector, error) { | 37 | func NewTimeCollector(logger log.Logger) (Collector, error) { |
36 | return &timeCollector{ | 38 | return &timeCollector{ |
37 | desc: prometheus.NewDesc( | 39 | desc: prometheus.NewDesc( |
38 | namespace+"_time_seconds", | 40 | namespace+"_time_seconds", |
39 | "System time in seconds since epoch (1970).", | 41 | "System time in seconds since epoch (1970).", |
40 | nil, nil, | 42 | nil, nil, |
41 | ), | 43 | ), |
44 | logger: logger, | ||
42 | }, nil | 45 | }, nil |
43 | } | 46 | } |
44 | 47 | ||
45 | func (c *timeCollector) Update(ch chan<- prometheus.Metric) error { | 48 | func (c *timeCollector) Update(ch chan<- prometheus.Metric) error { |
46 | now := float64(time.Now().UnixNano()) / 1e9 | 49 | now := float64(time.Now().UnixNano()) / 1e9 |
47 | log.Debugf("Return time: %f", now) | 50 | level.Debug(c.logger).Log("msg", "Return time", "now", now) |
48 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, now) | 51 | ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, now) |
49 | return nil | 52 | return nil |
50 | } | 53 | } |
diff --git a/collector/timex.go b/collector/timex.go index 7ef6920..4dc4d6c 100644 --- a/collector/timex.go +++ b/collector/timex.go | |||
@@ -19,6 +19,7 @@ package collector | |||
19 | import ( | 19 | import ( |
20 | "fmt" | 20 | "fmt" |
21 | 21 | ||
22 | "github.com/go-kit/kit/log" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 23 | "github.com/prometheus/client_golang/prometheus" |
23 | "golang.org/x/sys/unix" | 24 | "golang.org/x/sys/unix" |
24 | ) | 25 | ) |
@@ -54,6 +55,7 @@ type timexCollector struct { | |||
54 | stbcnt, | 55 | stbcnt, |
55 | tai, | 56 | tai, |
56 | syncStatus typedDesc | 57 | syncStatus typedDesc |
58 | logger log.Logger | ||
57 | } | 59 | } |
58 | 60 | ||
59 | func init() { | 61 | func init() { |
@@ -61,7 +63,7 @@ func init() { | |||
61 | } | 63 | } |
62 | 64 | ||
63 | // NewTimexCollector returns a new Collector exposing adjtime(3) stats. | 65 | // NewTimexCollector returns a new Collector exposing adjtime(3) stats. |
64 | func NewTimexCollector() (Collector, error) { | 66 | func NewTimexCollector(logger log.Logger) (Collector, error) { |
65 | const subsystem = "timex" | 67 | const subsystem = "timex" |
66 | 68 | ||
67 | return &timexCollector{ | 69 | return &timexCollector{ |
@@ -150,6 +152,7 @@ func NewTimexCollector() (Collector, error) { | |||
150 | "Is clock synchronized to a reliable server (1 = yes, 0 = no).", | 152 | "Is clock synchronized to a reliable server (1 = yes, 0 = no).", |
151 | nil, nil, | 153 | nil, nil, |
152 | ), prometheus.GaugeValue}, | 154 | ), prometheus.GaugeValue}, |
155 | logger: logger, | ||
153 | }, nil | 156 | }, nil |
154 | } | 157 | } |
155 | 158 | ||
diff --git a/collector/uname.go b/collector/uname.go index 381c0ae..2c0c306 100644 --- a/collector/uname.go +++ b/collector/uname.go | |||
@@ -17,6 +17,7 @@ | |||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "github.com/go-kit/kit/log" | ||
20 | "github.com/prometheus/client_golang/prometheus" | 21 | "github.com/prometheus/client_golang/prometheus" |
21 | ) | 22 | ) |
22 | 23 | ||
@@ -34,7 +35,9 @@ var unameDesc = prometheus.NewDesc( | |||
34 | nil, | 35 | nil, |
35 | ) | 36 | ) |
36 | 37 | ||
37 | type unameCollector struct{} | 38 | type unameCollector struct { |
39 | logger log.Logger | ||
40 | } | ||
38 | type uname struct { | 41 | type uname struct { |
39 | SysName string | 42 | SysName string |
40 | Release string | 43 | Release string |
@@ -49,8 +52,8 @@ func init() { | |||
49 | } | 52 | } |
50 | 53 | ||
51 | // NewUnameCollector returns new unameCollector. | 54 | // NewUnameCollector returns new unameCollector. |
52 | func newUnameCollector() (Collector, error) { | 55 | func newUnameCollector(logger log.Logger) (Collector, error) { |
53 | return &unameCollector{}, nil | 56 | return &unameCollector{logger}, nil |
54 | } | 57 | } |
55 | 58 | ||
56 | func (c *unameCollector) Update(ch chan<- prometheus.Metric) error { | 59 | func (c *unameCollector) Update(ch chan<- prometheus.Metric) error { |
diff --git a/collector/vmstat_linux.go b/collector/vmstat_linux.go index 50268dd..605c38a 100644 --- a/collector/vmstat_linux.go +++ b/collector/vmstat_linux.go | |||
@@ -23,6 +23,7 @@ import ( | |||
23 | "strconv" | 23 | "strconv" |
24 | "strings" | 24 | "strings" |
25 | 25 | ||
26 | "github.com/go-kit/kit/log" | ||
26 | "github.com/prometheus/client_golang/prometheus" | 27 | "github.com/prometheus/client_golang/prometheus" |
27 | "gopkg.in/alecthomas/kingpin.v2" | 28 | "gopkg.in/alecthomas/kingpin.v2" |
28 | ) | 29 | ) |
@@ -37,6 +38,7 @@ var ( | |||
37 | 38 | ||
38 | type vmStatCollector struct { | 39 | type vmStatCollector struct { |
39 | fieldPattern *regexp.Regexp | 40 | fieldPattern *regexp.Regexp |
41 | logger log.Logger | ||
40 | } | 42 | } |
41 | 43 | ||
42 | func init() { | 44 | func init() { |
@@ -44,10 +46,11 @@ func init() { | |||
44 | } | 46 | } |
45 | 47 | ||
46 | // NewvmStatCollector returns a new Collector exposing vmstat stats. | 48 | // NewvmStatCollector returns a new Collector exposing vmstat stats. |
47 | func NewvmStatCollector() (Collector, error) { | 49 | func NewvmStatCollector(logger log.Logger) (Collector, error) { |
48 | pattern := regexp.MustCompile(*vmStatFields) | 50 | pattern := regexp.MustCompile(*vmStatFields) |
49 | return &vmStatCollector{ | 51 | return &vmStatCollector{ |
50 | fieldPattern: pattern, | 52 | fieldPattern: pattern, |
53 | logger: logger, | ||
51 | }, nil | 54 | }, nil |
52 | } | 55 | } |
53 | 56 | ||
diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index 8e0d4ee..5a5a86c 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go | |||
@@ -20,9 +20,10 @@ import ( | |||
20 | "os" | 20 | "os" |
21 | "path/filepath" | 21 | "path/filepath" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/mdlayher/wifi" | 25 | "github.com/mdlayher/wifi" |
24 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
25 | "github.com/prometheus/common/log" | ||
26 | "gopkg.in/alecthomas/kingpin.v2" | 27 | "gopkg.in/alecthomas/kingpin.v2" |
27 | ) | 28 | ) |
28 | 29 | ||
@@ -40,6 +41,8 @@ type wifiCollector struct { | |||
40 | stationTransmitRetriesTotal *prometheus.Desc | 41 | stationTransmitRetriesTotal *prometheus.Desc |
41 | stationTransmitFailedTotal *prometheus.Desc | 42 | stationTransmitFailedTotal *prometheus.Desc |
42 | stationBeaconLossTotal *prometheus.Desc | 43 | stationBeaconLossTotal *prometheus.Desc |
44 | |||
45 | logger log.Logger | ||
43 | } | 46 | } |
44 | 47 | ||
45 | var ( | 48 | var ( |
@@ -61,7 +64,7 @@ type wifiStater interface { | |||
61 | } | 64 | } |
62 | 65 | ||
63 | // NewWifiCollector returns a new Collector exposing Wifi statistics. | 66 | // NewWifiCollector returns a new Collector exposing Wifi statistics. |
64 | func NewWifiCollector() (Collector, error) { | 67 | func NewWifiCollector(logger log.Logger) (Collector, error) { |
65 | const ( | 68 | const ( |
66 | subsystem = "wifi" | 69 | subsystem = "wifi" |
67 | ) | 70 | ) |
@@ -154,6 +157,7 @@ func NewWifiCollector() (Collector, error) { | |||
154 | labels, | 157 | labels, |
155 | nil, | 158 | nil, |
156 | ), | 159 | ), |
160 | logger: logger, | ||
157 | }, nil | 161 | }, nil |
158 | } | 162 | } |
159 | 163 | ||
@@ -162,11 +166,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
162 | if err != nil { | 166 | if err != nil { |
163 | // Cannot access wifi metrics, report no error. | 167 | // Cannot access wifi metrics, report no error. |
164 | if os.IsNotExist(err) { | 168 | if os.IsNotExist(err) { |
165 | log.Debug("wifi collector metrics are not available for this system") | 169 | level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") |
166 | return nil | 170 | return nil |
167 | } | 171 | } |
168 | if os.IsPermission(err) { | 172 | if os.IsPermission(err) { |
169 | log.Debug("wifi collector got permission denied when accessing metrics") | 173 | level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") |
170 | return nil | 174 | return nil |
171 | } | 175 | } |
172 | 176 | ||
@@ -185,7 +189,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
185 | continue | 189 | continue |
186 | } | 190 | } |
187 | 191 | ||
188 | log.Debugf("probing wifi device %q with type %q", ifi.Name, ifi.Type) | 192 | level.Debug(c.logger).Log("msg", "probing wifi device with type", "wifi", ifi.Name, "type", ifi.Type) |
189 | 193 | ||
190 | ch <- prometheus.MustNewConstMetric( | 194 | ch <- prometheus.MustNewConstMetric( |
191 | c.interfaceFrequencyHertz, | 195 | c.interfaceFrequencyHertz, |
@@ -203,7 +207,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
203 | case err == nil: | 207 | case err == nil: |
204 | c.updateBSSStats(ch, ifi.Name, bss) | 208 | c.updateBSSStats(ch, ifi.Name, bss) |
205 | case os.IsNotExist(err): | 209 | case os.IsNotExist(err): |
206 | log.Debugf("BSS information not found for wifi device %q", ifi.Name) | 210 | level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) |
207 | default: | 211 | default: |
208 | return fmt.Errorf("failed to retrieve BSS for device %s: %v", | 212 | return fmt.Errorf("failed to retrieve BSS for device %s: %v", |
209 | ifi.Name, err) | 213 | ifi.Name, err) |
@@ -216,7 +220,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { | |||
216 | c.updateStationStats(ch, ifi.Name, station) | 220 | c.updateStationStats(ch, ifi.Name, station) |
217 | } | 221 | } |
218 | case os.IsNotExist(err): | 222 | case os.IsNotExist(err): |
219 | log.Debugf("station information not found for wifi device %q", ifi.Name) | 223 | level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) |
220 | default: | 224 | default: |
221 | return fmt.Errorf("failed to retrieve station info for device %q: %v", | 225 | return fmt.Errorf("failed to retrieve station info for device %q: %v", |
222 | ifi.Name, err) | 226 | ifi.Name, err) |
diff --git a/collector/xfs_linux.go b/collector/xfs_linux.go index c92a48c..77824c5 100644 --- a/collector/xfs_linux.go +++ b/collector/xfs_linux.go | |||
@@ -16,13 +16,15 @@ package collector | |||
16 | import ( | 16 | import ( |
17 | "fmt" | 17 | "fmt" |
18 | 18 | ||
19 | "github.com/go-kit/kit/log" | ||
19 | "github.com/prometheus/client_golang/prometheus" | 20 | "github.com/prometheus/client_golang/prometheus" |
20 | "github.com/prometheus/procfs/xfs" | 21 | "github.com/prometheus/procfs/xfs" |
21 | ) | 22 | ) |
22 | 23 | ||
23 | // An xfsCollector is a Collector which gathers metrics from XFS filesystems. | 24 | // An xfsCollector is a Collector which gathers metrics from XFS filesystems. |
24 | type xfsCollector struct { | 25 | type xfsCollector struct { |
25 | fs xfs.FS | 26 | fs xfs.FS |
27 | logger log.Logger | ||
26 | } | 28 | } |
27 | 29 | ||
28 | func init() { | 30 | func init() { |
@@ -30,14 +32,15 @@ func init() { | |||
30 | } | 32 | } |
31 | 33 | ||
32 | // NewXFSCollector returns a new Collector exposing XFS statistics. | 34 | // NewXFSCollector returns a new Collector exposing XFS statistics. |
33 | func NewXFSCollector() (Collector, error) { | 35 | func NewXFSCollector(logger log.Logger) (Collector, error) { |
34 | fs, err := xfs.NewFS(*procPath, *sysPath) | 36 | fs, err := xfs.NewFS(*procPath, *sysPath) |
35 | if err != nil { | 37 | if err != nil { |
36 | return nil, fmt.Errorf("failed to open sysfs: %w", err) | 38 | return nil, fmt.Errorf("failed to open sysfs: %w", err) |
37 | } | 39 | } |
38 | 40 | ||
39 | return &xfsCollector{ | 41 | return &xfsCollector{ |
40 | fs: fs, | 42 | fs: fs, |
43 | logger: logger, | ||
41 | }, nil | 44 | }, nil |
42 | } | 45 | } |
43 | 46 | ||
diff --git a/collector/zfs.go b/collector/zfs.go index aa33688..093ded5 100644 --- a/collector/zfs.go +++ b/collector/zfs.go | |||
@@ -20,8 +20,9 @@ import ( | |||
20 | "errors" | 20 | "errors" |
21 | "strings" | 21 | "strings" |
22 | 22 | ||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
23 | "github.com/prometheus/client_golang/prometheus" | 25 | "github.com/prometheus/client_golang/prometheus" |
24 | "github.com/prometheus/common/log" | ||
25 | ) | 26 | ) |
26 | 27 | ||
27 | var errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available") | 28 | var errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available") |
@@ -36,10 +37,11 @@ type zfsCollector struct { | |||
36 | linuxProcpathBase string | 37 | linuxProcpathBase string |
37 | linuxZpoolIoPath string | 38 | linuxZpoolIoPath string |
38 | linuxPathMap map[string]string | 39 | linuxPathMap map[string]string |
40 | logger log.Logger | ||
39 | } | 41 | } |
40 | 42 | ||
41 | // NewZFSCollector returns a new Collector exposing ZFS statistics. | 43 | // NewZFSCollector returns a new Collector exposing ZFS statistics. |
42 | func NewZFSCollector() (Collector, error) { | 44 | func NewZFSCollector(logger log.Logger) (Collector, error) { |
43 | return &zfsCollector{ | 45 | return &zfsCollector{ |
44 | linuxProcpathBase: "spl/kstat/zfs", | 46 | linuxProcpathBase: "spl/kstat/zfs", |
45 | linuxZpoolIoPath: "/*/io", | 47 | linuxZpoolIoPath: "/*/io", |
@@ -56,6 +58,7 @@ func NewZFSCollector() (Collector, error) { | |||
56 | "zfs_zfetch": "zfetchstats", | 58 | "zfs_zfetch": "zfetchstats", |
57 | "zfs_zil": "zil", | 59 | "zfs_zil": "zil", |
58 | }, | 60 | }, |
61 | logger: logger, | ||
59 | }, nil | 62 | }, nil |
60 | } | 63 | } |
61 | 64 | ||
@@ -63,7 +66,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { | |||
63 | for subsystem := range c.linuxPathMap { | 66 | for subsystem := range c.linuxPathMap { |
64 | if err := c.updateZfsStats(subsystem, ch); err != nil { | 67 | if err := c.updateZfsStats(subsystem, ch); err != nil { |
65 | if err == errZFSNotAvailable { | 68 | if err == errZFSNotAvailable { |
66 | log.Debug(err) | 69 | level.Debug(c.logger).Log("err", err) |
67 | // ZFS /proc files are added as new features to ZFS arrive, it is ok to continue | 70 | // ZFS /proc files are added as new features to ZFS arrive, it is ok to continue |
68 | continue | 71 | continue |
69 | } | 72 | } |
diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go index 18fcd24..a625bbc 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go | |||
@@ -16,11 +16,13 @@ package collector | |||
16 | import ( | 16 | import ( |
17 | "fmt" | 17 | "fmt" |
18 | 18 | ||
19 | "github.com/go-kit/kit/log" | ||
19 | "github.com/prometheus/client_golang/prometheus" | 20 | "github.com/prometheus/client_golang/prometheus" |
20 | ) | 21 | ) |
21 | 22 | ||
22 | type zfsCollector struct { | 23 | type zfsCollector struct { |
23 | sysctls []bsdSysctl | 24 | sysctls []bsdSysctl |
25 | logger log.Logger | ||
24 | } | 26 | } |
25 | 27 | ||
26 | const ( | 28 | const ( |
@@ -31,7 +33,7 @@ func init() { | |||
31 | registerCollector("zfs", defaultEnabled, NewZfsCollector) | 33 | registerCollector("zfs", defaultEnabled, NewZfsCollector) |
32 | } | 34 | } |
33 | 35 | ||
34 | func NewZfsCollector() (Collector, error) { | 36 | func NewZfsCollector(logger log.Logger) (Collector, error) { |
35 | return &zfsCollector{ | 37 | return &zfsCollector{ |
36 | sysctls: []bsdSysctl{ | 38 | sysctls: []bsdSysctl{ |
37 | { | 39 | { |
@@ -238,6 +240,7 @@ func NewZfsCollector() (Collector, error) { | |||
238 | valueType: prometheus.CounterValue, | 240 | valueType: prometheus.CounterValue, |
239 | }, | 241 | }, |
240 | }, | 242 | }, |
243 | logger: logger, | ||
241 | }, nil | 244 | }, nil |
242 | } | 245 | } |
243 | 246 | ||
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index a964d50..aa27db8 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go | |||
@@ -22,8 +22,8 @@ import ( | |||
22 | "strconv" | 22 | "strconv" |
23 | "strings" | 23 | "strings" |
24 | 24 | ||
25 | "github.com/go-kit/kit/log/level" | ||
25 | "github.com/prometheus/client_golang/prometheus" | 26 | "github.com/prometheus/client_golang/prometheus" |
26 | "github.com/prometheus/common/log" | ||
27 | ) | 27 | ) |
28 | 28 | ||
29 | // constants from https://github.com/zfsonlinux/zfs/blob/master/lib/libspl/include/sys/kstat.h | 29 | // constants from https://github.com/zfsonlinux/zfs/blob/master/lib/libspl/include/sys/kstat.h |
@@ -45,7 +45,7 @@ func (c *zfsCollector) openProcFile(path string) (*os.File, error) { | |||
45 | // file not found error can occur if: | 45 | // file not found error can occur if: |
46 | // 1. zfs module is not loaded | 46 | // 1. zfs module is not loaded |
47 | // 2. zfs version does not have the feature with metrics -- ok to ignore | 47 | // 2. zfs version does not have the feature with metrics -- ok to ignore |
48 | log.Debugf("Cannot open %q for reading", procFilePath(path)) | 48 | level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", procFilePath(path)) |
49 | return nil, errZFSNotAvailable | 49 | return nil, errZFSNotAvailable |
50 | } | 50 | } |
51 | return file, nil | 51 | return file, nil |
@@ -77,7 +77,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { | |||
77 | file, err := os.Open(zpoolPath) | 77 | file, err := os.Open(zpoolPath) |
78 | if err != nil { | 78 | if err != nil { |
79 | // this file should exist, but there is a race where an exporting pool can remove the files -- ok to ignore | 79 | // this file should exist, but there is a race where an exporting pool can remove the files -- ok to ignore |
80 | log.Debugf("Cannot open %q for reading", zpoolPath) | 80 | level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) |
81 | return errZFSNotAvailable | 81 | return errZFSNotAvailable |
82 | } | 82 | } |
83 | 83 | ||
diff --git a/collector/zfs_solaris.go b/collector/zfs_solaris.go index 5bf2235..bfda64f 100644 --- a/collector/zfs_solaris.go +++ b/collector/zfs_solaris.go | |||
@@ -18,6 +18,7 @@ package collector | |||
18 | import ( | 18 | import ( |
19 | "strings" | 19 | "strings" |
20 | 20 | ||
21 | "github.com/go-kit/kit/log" | ||
21 | "github.com/prometheus/client_golang/prometheus" | 22 | "github.com/prometheus/client_golang/prometheus" |
22 | "github.com/siebenmann/go-kstat" | 23 | "github.com/siebenmann/go-kstat" |
23 | ) | 24 | ) |
@@ -52,6 +53,7 @@ type zfsCollector struct { | |||
52 | arcstatsSize *prometheus.Desc | 53 | arcstatsSize *prometheus.Desc |
53 | zfetchstatsHits *prometheus.Desc | 54 | zfetchstatsHits *prometheus.Desc |
54 | zfetchstatsMisses *prometheus.Desc | 55 | zfetchstatsMisses *prometheus.Desc |
56 | logger log.Logger | ||
55 | } | 57 | } |
56 | 58 | ||
57 | const ( | 59 | const ( |
@@ -62,7 +64,7 @@ func init() { | |||
62 | registerCollector("zfs", defaultEnabled, NewZfsCollector) | 64 | registerCollector("zfs", defaultEnabled, NewZfsCollector) |
63 | } | 65 | } |
64 | 66 | ||
65 | func NewZfsCollector() (Collector, error) { | 67 | func NewZfsCollector(logger log.Logger) (Collector, error) { |
66 | return &zfsCollector{ | 68 | return &zfsCollector{ |
67 | abdstatsLinearCount: prometheus.NewDesc( | 69 | abdstatsLinearCount: prometheus.NewDesc( |
68 | prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_count_total"), | 70 | prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_count_total"), |
@@ -180,6 +182,7 @@ func NewZfsCollector() (Collector, error) { | |||
180 | prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "zfetchstats_misses_total"), | 182 | prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "zfetchstats_misses_total"), |
181 | "ZFS cache fetch misses", nil, nil, | 183 | "ZFS cache fetch misses", nil, nil, |
182 | ), | 184 | ), |
185 | logger: logger, | ||
183 | }, nil | 186 | }, nil |
184 | } | 187 | } |
185 | 188 | ||
@@ -4,9 +4,9 @@ require ( | |||
4 | github.com/beevik/ntp v0.2.0 | 4 | github.com/beevik/ntp v0.2.0 |
5 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e | 5 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e |
6 | github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 | 6 | github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 |
7 | github.com/go-kit/kit v0.9.0 | ||
7 | github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 | 8 | github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 |
8 | github.com/hodgesds/perf-utils v0.0.7 | 9 | github.com/hodgesds/perf-utils v0.0.7 |
9 | github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect | ||
10 | github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3 | 10 | github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3 |
11 | github.com/mattn/go-xmlrpc v0.0.3 | 11 | github.com/mattn/go-xmlrpc v0.0.3 |
12 | github.com/mdlayher/genetlink v0.0.0-20190828143517-e35f2bf499b9 // indirect | 12 | github.com/mdlayher/genetlink v0.0.0-20190828143517-e35f2bf499b9 // indirect |
@@ -20,9 +20,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs | |||
20 | github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 h1:I3hLsM87FSASssIrIOGwJCio31dvLkvpYDKn2+r31ec= | 20 | github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 h1:I3hLsM87FSASssIrIOGwJCio31dvLkvpYDKn2+r31ec= |
21 | github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043/go.mod h1:ix4kG2zvdUd8kEKSW0ZTr1XLks0epFpI4j745DXxlNE= | 21 | github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043/go.mod h1:ix4kG2zvdUd8kEKSW0ZTr1XLks0epFpI4j745DXxlNE= |
22 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= | 22 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= |
23 | github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk= | ||
23 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= | 24 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= |
24 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= | 25 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= |
26 | github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= | ||
25 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= | 27 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= |
28 | github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= | ||
26 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= | 29 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= |
27 | github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 h1:s+PDl6lozQ+dEUtUtQnO7+A2iPG3sK1pI4liU+jxn90= | 30 | github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 h1:s+PDl6lozQ+dEUtUtQnO7+A2iPG3sK1pI4liU+jxn90= |
28 | github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= | 31 | github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= |
@@ -46,8 +49,7 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV | |||
46 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= | 49 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= |
47 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= | 50 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= |
48 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | 51 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= |
49 | github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= | 52 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= |
50 | github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | ||
51 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= | 53 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= |
52 | github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3 h1:XGhvld9vIpj929Gri5ybjukYZeyZwKkFkqgATqBQiOs= | 54 | github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3 h1:XGhvld9vIpj929Gri5ybjukYZeyZwKkFkqgATqBQiOs= |
53 | github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3/go.mod h1:lRgtFVamD7L7GaXOSwBiuXMwU3Aicfn5h66LVs4u2SA= | 55 | github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3/go.mod h1:lRgtFVamD7L7GaXOSwBiuXMwU3Aicfn5h66LVs4u2SA= |
diff --git a/node_exporter.go b/node_exporter.go index b48170c..6e92cc3 100644 --- a/node_exporter.go +++ b/node_exporter.go | |||
@@ -15,13 +15,17 @@ package main | |||
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "fmt" | 17 | "fmt" |
18 | "github.com/prometheus/common/promlog" | ||
19 | "github.com/prometheus/common/promlog/flag" | ||
18 | "net/http" | 20 | "net/http" |
19 | _ "net/http/pprof" | 21 | _ "net/http/pprof" |
22 | "os" | ||
20 | "sort" | 23 | "sort" |
21 | 24 | ||
25 | "github.com/go-kit/kit/log" | ||
26 | "github.com/go-kit/kit/log/level" | ||
22 | "github.com/prometheus/client_golang/prometheus" | 27 | "github.com/prometheus/client_golang/prometheus" |
23 | "github.com/prometheus/client_golang/prometheus/promhttp" | 28 | "github.com/prometheus/client_golang/prometheus/promhttp" |
24 | "github.com/prometheus/common/log" | ||
25 | "github.com/prometheus/common/version" | 29 | "github.com/prometheus/common/version" |
26 | "github.com/prometheus/node_exporter/collector" | 30 | "github.com/prometheus/node_exporter/collector" |
27 | "github.com/prometheus/node_exporter/https" | 31 | "github.com/prometheus/node_exporter/https" |
@@ -38,13 +42,15 @@ type handler struct { | |||
38 | exporterMetricsRegistry *prometheus.Registry | 42 | exporterMetricsRegistry *prometheus.Registry |
39 | includeExporterMetrics bool | 43 | includeExporterMetrics bool |
40 | maxRequests int | 44 | maxRequests int |
45 | logger log.Logger | ||
41 | } | 46 | } |
42 | 47 | ||
43 | func newHandler(includeExporterMetrics bool, maxRequests int) *handler { | 48 | func newHandler(includeExporterMetrics bool, maxRequests int, logger log.Logger) *handler { |
44 | h := &handler{ | 49 | h := &handler{ |
45 | exporterMetricsRegistry: prometheus.NewRegistry(), | 50 | exporterMetricsRegistry: prometheus.NewRegistry(), |
46 | includeExporterMetrics: includeExporterMetrics, | 51 | includeExporterMetrics: includeExporterMetrics, |
47 | maxRequests: maxRequests, | 52 | maxRequests: maxRequests, |
53 | logger: logger, | ||
48 | } | 54 | } |
49 | if h.includeExporterMetrics { | 55 | if h.includeExporterMetrics { |
50 | h.exporterMetricsRegistry.MustRegister( | 56 | h.exporterMetricsRegistry.MustRegister( |
@@ -53,7 +59,7 @@ func newHandler(includeExporterMetrics bool, maxRequests int) *handler { | |||
53 | ) | 59 | ) |
54 | } | 60 | } |
55 | if innerHandler, err := h.innerHandler(); err != nil { | 61 | if innerHandler, err := h.innerHandler(); err != nil { |
56 | log.Fatalf("Couldn't create metrics handler: %s", err) | 62 | panic(fmt.Sprintf("Couldn't create metrics handler: %s", err)) |
57 | } else { | 63 | } else { |
58 | h.unfilteredHandler = innerHandler | 64 | h.unfilteredHandler = innerHandler |
59 | } | 65 | } |
@@ -63,7 +69,7 @@ func newHandler(includeExporterMetrics bool, maxRequests int) *handler { | |||
63 | // ServeHTTP implements http.Handler. | 69 | // ServeHTTP implements http.Handler. |
64 | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | 70 | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
65 | filters := r.URL.Query()["collect[]"] | 71 | filters := r.URL.Query()["collect[]"] |
66 | log.Debugln("collect query:", filters) | 72 | level.Debug(h.logger).Log("msg", "collect query:", "filters", filters) |
67 | 73 | ||
68 | if len(filters) == 0 { | 74 | if len(filters) == 0 { |
69 | // No filters, use the prepared unfiltered handler. | 75 | // No filters, use the prepared unfiltered handler. |
@@ -73,7 +79,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
73 | // To serve filtered metrics, we create a filtering handler on the fly. | 79 | // To serve filtered metrics, we create a filtering handler on the fly. |
74 | filteredHandler, err := h.innerHandler(filters...) | 80 | filteredHandler, err := h.innerHandler(filters...) |
75 | if err != nil { | 81 | if err != nil { |
76 | log.Warnln("Couldn't create filtered metrics handler:", err) | 82 | level.Warn(h.logger).Log("msg", "Couldn't create filtered metrics handler:", "err", err) |
77 | w.WriteHeader(http.StatusBadRequest) | 83 | w.WriteHeader(http.StatusBadRequest) |
78 | w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) | 84 | w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) |
79 | return | 85 | return |
@@ -81,13 +87,13 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
81 | filteredHandler.ServeHTTP(w, r) | 87 | filteredHandler.ServeHTTP(w, r) |
82 | } | 88 | } |
83 | 89 | ||
84 | // innerHandler is used to create buth the one unfiltered http.Handler to be | 90 | // innerHandler is used to create both the one unfiltered http.Handler to be |
85 | // wrapped by the outer handler and also the filtered handlers created on the | 91 | // wrapped by the outer handler and also the filtered handlers created on the |
86 | // fly. The former is accomplished by calling innerHandler without any arguments | 92 | // fly. The former is accomplished by calling innerHandler without any arguments |
87 | // (in which case it will log all the collectors enabled via command-line | 93 | // (in which case it will log all the collectors enabled via command-line |
88 | // flags). | 94 | // flags). |
89 | func (h *handler) innerHandler(filters ...string) (http.Handler, error) { | 95 | func (h *handler) innerHandler(filters ...string) (http.Handler, error) { |
90 | nc, err := collector.NewNodeCollector(filters...) | 96 | nc, err := collector.NewNodeCollector(h.logger, filters...) |
91 | if err != nil { | 97 | if err != nil { |
92 | return nil, fmt.Errorf("couldn't create collector: %s", err) | 98 | return nil, fmt.Errorf("couldn't create collector: %s", err) |
93 | } | 99 | } |
@@ -95,14 +101,14 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { | |||
95 | // Only log the creation of an unfiltered handler, which should happen | 101 | // Only log the creation of an unfiltered handler, which should happen |
96 | // only once upon startup. | 102 | // only once upon startup. |
97 | if len(filters) == 0 { | 103 | if len(filters) == 0 { |
98 | log.Infof("Enabled collectors:") | 104 | level.Info(h.logger).Log("msg", "Enabled collectors") |
99 | collectors := []string{} | 105 | collectors := []string{} |
100 | for n := range nc.Collectors { | 106 | for n := range nc.Collectors { |
101 | collectors = append(collectors, n) | 107 | collectors = append(collectors, n) |
102 | } | 108 | } |
103 | sort.Strings(collectors) | 109 | sort.Strings(collectors) |
104 | for _, n := range collectors { | 110 | for _, c := range collectors { |
105 | log.Infof(" - %s", n) | 111 | level.Info(h.logger).Log("collector", c) |
106 | } | 112 | } |
107 | } | 113 | } |
108 | 114 | ||
@@ -114,7 +120,6 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { | |||
114 | handler := promhttp.HandlerFor( | 120 | handler := promhttp.HandlerFor( |
115 | prometheus.Gatherers{h.exporterMetricsRegistry, r}, | 121 | prometheus.Gatherers{h.exporterMetricsRegistry, r}, |
116 | promhttp.HandlerOpts{ | 122 | promhttp.HandlerOpts{ |
117 | ErrorLog: log.NewErrorLogger(), | ||
118 | ErrorHandling: promhttp.ContinueOnError, | 123 | ErrorHandling: promhttp.ContinueOnError, |
119 | MaxRequestsInFlight: h.maxRequests, | 124 | MaxRequestsInFlight: h.maxRequests, |
120 | Registry: h.exporterMetricsRegistry, | 125 | Registry: h.exporterMetricsRegistry, |
@@ -154,15 +159,17 @@ func main() { | |||
154 | ).Default("").String() | 159 | ).Default("").String() |
155 | ) | 160 | ) |
156 | 161 | ||
157 | log.AddFlags(kingpin.CommandLine) | 162 | promlogConfig := &promlog.Config{} |
163 | flag.AddFlags(kingpin.CommandLine, promlogConfig) | ||
158 | kingpin.Version(version.Print("node_exporter")) | 164 | kingpin.Version(version.Print("node_exporter")) |
159 | kingpin.HelpFlag.Short('h') | 165 | kingpin.HelpFlag.Short('h') |
160 | kingpin.Parse() | 166 | kingpin.Parse() |
167 | logger := promlog.New(promlogConfig) | ||
161 | 168 | ||
162 | log.Infoln("Starting node_exporter", version.Info()) | 169 | level.Info(logger).Log("msg", "Starting node_exporter", "version", version.Info()) |
163 | log.Infoln("Build context", version.BuildContext()) | 170 | level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) |
164 | 171 | ||
165 | http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests)) | 172 | http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger)) |
166 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | 173 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
167 | w.Write([]byte(`<html> | 174 | w.Write([]byte(`<html> |
168 | <head><title>Node Exporter</title></head> | 175 | <head><title>Node Exporter</title></head> |
@@ -173,9 +180,10 @@ func main() { | |||
173 | </html>`)) | 180 | </html>`)) |
174 | }) | 181 | }) |
175 | 182 | ||
176 | log.Infoln("Listening on", *listenAddress) | 183 | level.Info(logger).Log("msg", "Listening on", "address", *listenAddress) |
177 | server := &http.Server{Addr: *listenAddress} | 184 | server := &http.Server{Addr: *listenAddress} |
178 | if err := https.Listen(server, *configFile); err != nil { | 185 | if err := https.Listen(server, *configFile); err != nil { |
179 | log.Fatal(err) | 186 | level.Error(logger).Log("err", err) |
187 | os.Exit(1) | ||
180 | } | 188 | } |
181 | } | 189 | } |
diff --git a/scripts/errcheck_excludes.txt b/scripts/errcheck_excludes.txt index 2cadaa5..ed0736f 100644 --- a/scripts/errcheck_excludes.txt +++ b/scripts/errcheck_excludes.txt | |||
@@ -1,2 +1,4 @@ | |||
1 | // Used in HTTP handlers, any error is handled by the server itself. | 1 | // Used in HTTP handlers, any error is handled by the server itself. |
2 | (net/http.ResponseWriter).Write | 2 | (net/http.ResponseWriter).Write |
3 | // Never check for logger errors. | ||
4 | (github.com/go-kit/kit/log.Logger).Log \ No newline at end of file | ||
diff --git a/vendor/github.com/sirupsen/logrus/LICENSE b/vendor/github.com/go-kit/kit/LICENSE index f090cb4..9d83342 100644 --- a/vendor/github.com/sirupsen/logrus/LICENSE +++ b/vendor/github.com/go-kit/kit/LICENSE | |||
@@ -1,6 +1,6 @@ | |||
1 | The MIT License (MIT) | 1 | The MIT License (MIT) |
2 | 2 | ||
3 | Copyright (c) 2014 Simon Eskildsen | 3 | Copyright (c) 2015 Peter Bourgon |
4 | 4 | ||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | of this software and associated documentation files (the "Software"), to deal | 6 | of this software and associated documentation files (the "Software"), to deal |
@@ -9,13 +9,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
9 | copies of the Software, and to permit persons to whom the Software is | 9 | copies of the Software, and to permit persons to whom the Software is |
10 | furnished to do so, subject to the following conditions: | 10 | furnished to do so, subject to the following conditions: |
11 | 11 | ||
12 | The above copyright notice and this permission notice shall be included in | 12 | The above copyright notice and this permission notice shall be included in all |
13 | all copies or substantial portions of the Software. | 13 | copies or substantial portions of the Software. |
14 | 14 | ||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | THE SOFTWARE. | 21 | SOFTWARE. |
22 | |||
diff --git a/vendor/github.com/go-kit/kit/log/README.md b/vendor/github.com/go-kit/kit/log/README.md new file mode 100644 index 0000000..a201a3d --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/README.md | |||
@@ -0,0 +1,151 @@ | |||
1 | # package log | ||
2 | |||
3 | `package log` provides a minimal interface for structured logging in services. | ||
4 | It may be wrapped to encode conventions, enforce type-safety, provide leveled | ||
5 | logging, and so on. It can be used for both typical application log events, | ||
6 | and log-structured data streams. | ||
7 | |||
8 | ## Structured logging | ||
9 | |||
10 | Structured logging is, basically, conceding to the reality that logs are | ||
11 | _data_, and warrant some level of schematic rigor. Using a stricter, | ||
12 | key/value-oriented message format for our logs, containing contextual and | ||
13 | semantic information, makes it much easier to get insight into the | ||
14 | operational activity of the systems we build. Consequently, `package log` is | ||
15 | of the strong belief that "[the benefits of structured logging outweigh the | ||
16 | minimal effort involved](https://www.thoughtworks.com/radar/techniques/structured-logging)". | ||
17 | |||
18 | Migrating from unstructured to structured logging is probably a lot easier | ||
19 | than you'd expect. | ||
20 | |||
21 | ```go | ||
22 | // Unstructured | ||
23 | log.Printf("HTTP server listening on %s", addr) | ||
24 | |||
25 | // Structured | ||
26 | logger.Log("transport", "HTTP", "addr", addr, "msg", "listening") | ||
27 | ``` | ||
28 | |||
29 | ## Usage | ||
30 | |||
31 | ### Typical application logging | ||
32 | |||
33 | ```go | ||
34 | w := log.NewSyncWriter(os.Stderr) | ||
35 | logger := log.NewLogfmtLogger(w) | ||
36 | logger.Log("question", "what is the meaning of life?", "answer", 42) | ||
37 | |||
38 | // Output: | ||
39 | // question="what is the meaning of life?" answer=42 | ||
40 | ``` | ||
41 | |||
42 | ### Contextual Loggers | ||
43 | |||
44 | ```go | ||
45 | func main() { | ||
46 | var logger log.Logger | ||
47 | logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) | ||
48 | logger = log.With(logger, "instance_id", 123) | ||
49 | |||
50 | logger.Log("msg", "starting") | ||
51 | NewWorker(log.With(logger, "component", "worker")).Run() | ||
52 | NewSlacker(log.With(logger, "component", "slacker")).Run() | ||
53 | } | ||
54 | |||
55 | // Output: | ||
56 | // instance_id=123 msg=starting | ||
57 | // instance_id=123 component=worker msg=running | ||
58 | // instance_id=123 component=slacker msg=running | ||
59 | ``` | ||
60 | |||
61 | ### Interact with stdlib logger | ||
62 | |||
63 | Redirect stdlib logger to Go kit logger. | ||
64 | |||
65 | ```go | ||
66 | import ( | ||
67 | "os" | ||
68 | stdlog "log" | ||
69 | kitlog "github.com/go-kit/kit/log" | ||
70 | ) | ||
71 | |||
72 | func main() { | ||
73 | logger := kitlog.NewJSONLogger(kitlog.NewSyncWriter(os.Stdout)) | ||
74 | stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) | ||
75 | stdlog.Print("I sure like pie") | ||
76 | } | ||
77 | |||
78 | // Output: | ||
79 | // {"msg":"I sure like pie","ts":"2016/01/01 12:34:56"} | ||
80 | ``` | ||
81 | |||
82 | Or, if, for legacy reasons, you need to pipe all of your logging through the | ||
83 | stdlib log package, you can redirect Go kit logger to the stdlib logger. | ||
84 | |||
85 | ```go | ||
86 | logger := kitlog.NewLogfmtLogger(kitlog.StdlibWriter{}) | ||
87 | logger.Log("legacy", true, "msg", "at least it's something") | ||
88 | |||
89 | // Output: | ||
90 | // 2016/01/01 12:34:56 legacy=true msg="at least it's something" | ||
91 | ``` | ||
92 | |||
93 | ### Timestamps and callers | ||
94 | |||
95 | ```go | ||
96 | var logger log.Logger | ||
97 | logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) | ||
98 | logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) | ||
99 | |||
100 | logger.Log("msg", "hello") | ||
101 | |||
102 | // Output: | ||
103 | // ts=2016-01-01T12:34:56Z caller=main.go:15 msg=hello | ||
104 | ``` | ||
105 | |||
106 | ## Levels | ||
107 | |||
108 | Log levels are supported via the [level package](https://godoc.org/github.com/go-kit/kit/log/level). | ||
109 | |||
110 | ## Supported output formats | ||
111 | |||
112 | - [Logfmt](https://brandur.org/logfmt) ([see also](https://blog.codeship.com/logfmt-a-log-format-thats-easy-to-read-and-write)) | ||
113 | - JSON | ||
114 | |||
115 | ## Enhancements | ||
116 | |||
117 | `package log` is centered on the one-method Logger interface. | ||
118 | |||
119 | ```go | ||
120 | type Logger interface { | ||
121 | Log(keyvals ...interface{}) error | ||
122 | } | ||
123 | ``` | ||
124 | |||
125 | This interface, and its supporting code like is the product of much iteration | ||
126 | and evaluation. For more details on the evolution of the Logger interface, | ||
127 | see [The Hunt for a Logger Interface](http://go-talks.appspot.com/github.com/ChrisHines/talks/structured-logging/structured-logging.slide#1), | ||
128 | a talk by [Chris Hines](https://github.com/ChrisHines). | ||
129 | Also, please see | ||
130 | [#63](https://github.com/go-kit/kit/issues/63), | ||
131 | [#76](https://github.com/go-kit/kit/pull/76), | ||
132 | [#131](https://github.com/go-kit/kit/issues/131), | ||
133 | [#157](https://github.com/go-kit/kit/pull/157), | ||
134 | [#164](https://github.com/go-kit/kit/issues/164), and | ||
135 | [#252](https://github.com/go-kit/kit/pull/252) | ||
136 | to review historical conversations about package log and the Logger interface. | ||
137 | |||
138 | Value-add packages and suggestions, | ||
139 | like improvements to [the leveled logger](https://godoc.org/github.com/go-kit/kit/log/level), | ||
140 | are of course welcome. Good proposals should | ||
141 | |||
142 | - Be composable with [contextual loggers](https://godoc.org/github.com/go-kit/kit/log#With), | ||
143 | - Not break the behavior of [log.Caller](https://godoc.org/github.com/go-kit/kit/log#Caller) in any wrapped contextual loggers, and | ||
144 | - Be friendly to packages that accept only an unadorned log.Logger. | ||
145 | |||
146 | ## Benchmarks & comparisons | ||
147 | |||
148 | There are a few Go logging benchmarks and comparisons that include Go kit's package log. | ||
149 | |||
150 | - [imkira/go-loggers-bench](https://github.com/imkira/go-loggers-bench) includes kit/log | ||
151 | - [uber-common/zap](https://github.com/uber-common/zap), a zero-alloc logging library, includes a comparison with kit/log | ||
diff --git a/vendor/github.com/go-kit/kit/log/doc.go b/vendor/github.com/go-kit/kit/log/doc.go new file mode 100644 index 0000000..918c0af --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/doc.go | |||
@@ -0,0 +1,116 @@ | |||
1 | // Package log provides a structured logger. | ||
2 | // | ||
3 | // Structured logging produces logs easily consumed later by humans or | ||
4 | // machines. Humans might be interested in debugging errors, or tracing | ||
5 | // specific requests. Machines might be interested in counting interesting | ||
6 | // events, or aggregating information for off-line processing. In both cases, | ||
7 | // it is important that the log messages are structured and actionable. | ||
8 | // Package log is designed to encourage both of these best practices. | ||
9 | // | ||
10 | // Basic Usage | ||
11 | // | ||
12 | // The fundamental interface is Logger. Loggers create log events from | ||
13 | // key/value data. The Logger interface has a single method, Log, which | ||
14 | // accepts a sequence of alternating key/value pairs, which this package names | ||
15 | // keyvals. | ||
16 | // | ||
17 | // type Logger interface { | ||
18 | // Log(keyvals ...interface{}) error | ||
19 | // } | ||
20 | // | ||
21 | // Here is an example of a function using a Logger to create log events. | ||
22 | // | ||
23 | // func RunTask(task Task, logger log.Logger) string { | ||
24 | // logger.Log("taskID", task.ID, "event", "starting task") | ||
25 | // ... | ||
26 | // logger.Log("taskID", task.ID, "event", "task complete") | ||
27 | // } | ||
28 | // | ||
29 | // The keys in the above example are "taskID" and "event". The values are | ||
30 | // task.ID, "starting task", and "task complete". Every key is followed | ||
31 | // immediately by its value. | ||
32 | // | ||
33 | // Keys are usually plain strings. Values may be any type that has a sensible | ||
34 | // encoding in the chosen log format. With structured logging it is a good | ||
35 | // idea to log simple values without formatting them. This practice allows | ||
36 | // the chosen logger to encode values in the most appropriate way. | ||
37 | // | ||
38 | // Contextual Loggers | ||
39 | // | ||
40 | // A contextual logger stores keyvals that it includes in all log events. | ||
41 | // Building appropriate contextual loggers reduces repetition and aids | ||
42 | // consistency in the resulting log output. With and WithPrefix add context to | ||
43 | // a logger. We can use With to improve the RunTask example. | ||
44 | // | ||
45 | // func RunTask(task Task, logger log.Logger) string { | ||
46 | // logger = log.With(logger, "taskID", task.ID) | ||
47 | // logger.Log("event", "starting task") | ||
48 | // ... | ||
49 | // taskHelper(task.Cmd, logger) | ||
50 | // ... | ||
51 | // logger.Log("event", "task complete") | ||
52 | // } | ||
53 | // | ||
54 | // The improved version emits the same log events as the original for the | ||
55 | // first and last calls to Log. Passing the contextual logger to taskHelper | ||
56 | // enables each log event created by taskHelper to include the task.ID even | ||
57 | // though taskHelper does not have access to that value. Using contextual | ||
58 | // loggers this way simplifies producing log output that enables tracing the | ||
59 | // life cycle of individual tasks. (See the Contextual example for the full | ||
60 | // code of the above snippet.) | ||
61 | // | ||
62 | // Dynamic Contextual Values | ||
63 | // | ||
64 | // A Valuer function stored in a contextual logger generates a new value each | ||
65 | // time an event is logged. The Valuer example demonstrates how this feature | ||
66 | // works. | ||
67 | // | ||
68 | // Valuers provide the basis for consistently logging timestamps and source | ||
69 | // code location. The log package defines several valuers for that purpose. | ||
70 | // See Timestamp, DefaultTimestamp, DefaultTimestampUTC, Caller, and | ||
71 | // DefaultCaller. A common logger initialization sequence that ensures all log | ||
72 | // entries contain a timestamp and source location looks like this: | ||
73 | // | ||
74 | // logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) | ||
75 | // logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) | ||
76 | // | ||
77 | // Concurrent Safety | ||
78 | // | ||
79 | // Applications with multiple goroutines want each log event written to the | ||
80 | // same logger to remain separate from other log events. Package log provides | ||
81 | // two simple solutions for concurrent safe logging. | ||
82 | // | ||
83 | // NewSyncWriter wraps an io.Writer and serializes each call to its Write | ||
84 | // method. Using a SyncWriter has the benefit that the smallest practical | ||
85 | // portion of the logging logic is performed within a mutex, but it requires | ||
86 | // the formatting Logger to make only one call to Write per log event. | ||
87 | // | ||
88 | // NewSyncLogger wraps any Logger and serializes each call to its Log method. | ||
89 | // Using a SyncLogger has the benefit that it guarantees each log event is | ||
90 | // handled atomically within the wrapped logger, but it typically serializes | ||
91 | // both the formatting and output logic. Use a SyncLogger if the formatting | ||
92 | // logger may perform multiple writes per log event. | ||
93 | // | ||
94 | // Error Handling | ||
95 | // | ||
96 | // This package relies on the practice of wrapping or decorating loggers with | ||
97 | // other loggers to provide composable pieces of functionality. It also means | ||
98 | // that Logger.Log must return an error because some | ||
99 | // implementations—especially those that output log data to an io.Writer—may | ||
100 | // encounter errors that cannot be handled locally. This in turn means that | ||
101 | // Loggers that wrap other loggers should return errors from the wrapped | ||
102 | // logger up the stack. | ||
103 | // | ||
104 | // Fortunately, the decorator pattern also provides a way to avoid the | ||
105 | // necessity to check for errors every time an application calls Logger.Log. | ||
106 | // An application required to panic whenever its Logger encounters | ||
107 | // an error could initialize its logger as follows. | ||
108 | // | ||
109 | // fmtlogger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) | ||
110 | // logger := log.LoggerFunc(func(keyvals ...interface{}) error { | ||
111 | // if err := fmtlogger.Log(keyvals...); err != nil { | ||
112 | // panic(err) | ||
113 | // } | ||
114 | // return nil | ||
115 | // }) | ||
116 | package log | ||
diff --git a/vendor/github.com/go-kit/kit/log/json_logger.go b/vendor/github.com/go-kit/kit/log/json_logger.go new file mode 100644 index 0000000..66094b4 --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/json_logger.go | |||
@@ -0,0 +1,89 @@ | |||
1 | package log | ||
2 | |||
3 | import ( | ||
4 | "encoding" | ||
5 | "encoding/json" | ||
6 | "fmt" | ||
7 | "io" | ||
8 | "reflect" | ||
9 | ) | ||
10 | |||
11 | type jsonLogger struct { | ||
12 | io.Writer | ||
13 | } | ||
14 | |||
15 | // NewJSONLogger returns a Logger that encodes keyvals to the Writer as a | ||
16 | // single JSON object. Each log event produces no more than one call to | ||
17 | // w.Write. The passed Writer must be safe for concurrent use by multiple | ||
18 | // goroutines if the returned Logger will be used concurrently. | ||
19 | func NewJSONLogger(w io.Writer) Logger { | ||
20 | return &jsonLogger{w} | ||
21 | } | ||
22 | |||
23 | func (l *jsonLogger) Log(keyvals ...interface{}) error { | ||
24 | n := (len(keyvals) + 1) / 2 // +1 to handle case when len is odd | ||
25 | m := make(map[string]interface{}, n) | ||
26 | for i := 0; i < len(keyvals); i += 2 { | ||
27 | k := keyvals[i] | ||
28 | var v interface{} = ErrMissingValue | ||
29 | if i+1 < len(keyvals) { | ||
30 | v = keyvals[i+1] | ||
31 | } | ||
32 | merge(m, k, v) | ||
33 | } | ||
34 | return json.NewEncoder(l.Writer).Encode(m) | ||
35 | } | ||
36 | |||
37 | func merge(dst map[string]interface{}, k, v interface{}) { | ||
38 | var key string | ||
39 | switch x := k.(type) { | ||
40 | case string: | ||
41 | key = x | ||
42 | case fmt.Stringer: | ||
43 | key = safeString(x) | ||
44 | default: | ||
45 | key = fmt.Sprint(x) | ||
46 | } | ||
47 | |||
48 | // We want json.Marshaler and encoding.TextMarshaller to take priority over | ||
49 | // err.Error() and v.String(). But json.Marshall (called later) does that by | ||
50 | // default so we force a no-op if it's one of those 2 case. | ||
51 | switch x := v.(type) { | ||
52 | case json.Marshaler: | ||
53 | case encoding.TextMarshaler: | ||
54 | case error: | ||
55 | v = safeError(x) | ||
56 | case fmt.Stringer: | ||
57 | v = safeString(x) | ||
58 | } | ||
59 | |||
60 | dst[key] = v | ||
61 | } | ||
62 | |||
63 | func safeString(str fmt.Stringer) (s string) { | ||
64 | defer func() { | ||
65 | if panicVal := recover(); panicVal != nil { | ||
66 | if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { | ||
67 | s = "NULL" | ||
68 | } else { | ||
69 | panic(panicVal) | ||
70 | } | ||
71 | } | ||
72 | }() | ||
73 | s = str.String() | ||
74 | return | ||
75 | } | ||
76 | |||
77 | func safeError(err error) (s interface{}) { | ||
78 | defer func() { | ||
79 | if panicVal := recover(); panicVal != nil { | ||
80 | if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { | ||
81 | s = nil | ||
82 | } else { | ||
83 | panic(panicVal) | ||
84 | } | ||
85 | } | ||
86 | }() | ||
87 | s = err.Error() | ||
88 | return | ||
89 | } | ||
diff --git a/vendor/github.com/go-kit/kit/log/level/doc.go b/vendor/github.com/go-kit/kit/log/level/doc.go new file mode 100644 index 0000000..505d307 --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/level/doc.go | |||
@@ -0,0 +1,22 @@ | |||
1 | // Package level implements leveled logging on top of Go kit's log package. To | ||
2 | // use the level package, create a logger as per normal in your func main, and | ||
3 | // wrap it with level.NewFilter. | ||
4 | // | ||
5 | // var logger log.Logger | ||
6 | // logger = log.NewLogfmtLogger(os.Stderr) | ||
7 | // logger = level.NewFilter(logger, level.AllowInfo()) // <-- | ||
8 | // logger = log.With(logger, "ts", log.DefaultTimestampUTC) | ||
9 | // | ||
10 | // Then, at the callsites, use one of the level.Debug, Info, Warn, or Error | ||
11 | // helper methods to emit leveled log events. | ||
12 | // | ||
13 | // logger.Log("foo", "bar") // as normal, no level | ||
14 | // level.Debug(logger).Log("request_id", reqID, "trace_data", trace.Get()) | ||
15 | // if value > 100 { | ||
16 | // level.Error(logger).Log("value", value) | ||
17 | // } | ||
18 | // | ||
19 | // NewFilter allows precise control over what happens when a log event is | ||
20 | // emitted without a level key, or if a squelched level is used. Check the | ||
21 | // Option functions for details. | ||
22 | package level | ||
diff --git a/vendor/github.com/go-kit/kit/log/level/level.go b/vendor/github.com/go-kit/kit/log/level/level.go new file mode 100644 index 0000000..fceafc4 --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/level/level.go | |||
@@ -0,0 +1,205 @@ | |||
1 | package level | ||
2 | |||
3 | import "github.com/go-kit/kit/log" | ||
4 | |||
5 | // Error returns a logger that includes a Key/ErrorValue pair. | ||
6 | func Error(logger log.Logger) log.Logger { | ||
7 | return log.WithPrefix(logger, Key(), ErrorValue()) | ||
8 | } | ||
9 | |||
10 | // Warn returns a logger that includes a Key/WarnValue pair. | ||
11 | func Warn(logger log.Logger) log.Logger { | ||
12 | return log.WithPrefix(logger, Key(), WarnValue()) | ||
13 | } | ||
14 | |||
15 | // Info returns a logger that includes a Key/InfoValue pair. | ||
16 | func Info(logger log.Logger) log.Logger { | ||
17 | return log.WithPrefix(logger, Key(), InfoValue()) | ||
18 | } | ||
19 | |||
20 | // Debug returns a logger that includes a Key/DebugValue pair. | ||
21 | func Debug(logger log.Logger) log.Logger { | ||
22 | return log.WithPrefix(logger, Key(), DebugValue()) | ||
23 | } | ||
24 | |||
25 | // NewFilter wraps next and implements level filtering. See the commentary on | ||
26 | // the Option functions for a detailed description of how to configure levels. | ||
27 | // If no options are provided, all leveled log events created with Debug, | ||
28 | // Info, Warn or Error helper methods are squelched and non-leveled log | ||
29 | // events are passed to next unmodified. | ||
30 | func NewFilter(next log.Logger, options ...Option) log.Logger { | ||
31 | l := &logger{ | ||
32 | next: next, | ||
33 | } | ||
34 | for _, option := range options { | ||
35 | option(l) | ||
36 | } | ||
37 | return l | ||
38 | } | ||
39 | |||
40 | type logger struct { | ||
41 | next log.Logger | ||
42 | allowed level | ||
43 | squelchNoLevel bool | ||
44 | errNotAllowed error | ||
45 | errNoLevel error | ||
46 | } | ||
47 | |||
48 | func (l *logger) Log(keyvals ...interface{}) error { | ||
49 | var hasLevel, levelAllowed bool | ||
50 | for i := 1; i < len(keyvals); i += 2 { | ||
51 | if v, ok := keyvals[i].(*levelValue); ok { | ||
52 | hasLevel = true | ||
53 | levelAllowed = l.allowed&v.level != 0 | ||
54 | break | ||
55 | } | ||
56 | } | ||
57 | if !hasLevel && l.squelchNoLevel { | ||
58 | return l.errNoLevel | ||
59 | } | ||
60 | if hasLevel && !levelAllowed { | ||
61 | return l.errNotAllowed | ||
62 | } | ||
63 | return l.next.Log(keyvals...) | ||
64 | } | ||
65 | |||
66 | // Option sets a parameter for the leveled logger. | ||
67 | type Option func(*logger) | ||
68 | |||
69 | // AllowAll is an alias for AllowDebug. | ||
70 | func AllowAll() Option { | ||
71 | return AllowDebug() | ||
72 | } | ||
73 | |||
74 | // AllowDebug allows error, warn, info and debug level log events to pass. | ||
75 | func AllowDebug() Option { | ||
76 | return allowed(levelError | levelWarn | levelInfo | levelDebug) | ||
77 | } | ||
78 | |||
79 | // AllowInfo allows error, warn and info level log events to pass. | ||
80 | func AllowInfo() Option { | ||
81 | return allowed(levelError | levelWarn | levelInfo) | ||
82 | } | ||
83 | |||
84 | // AllowWarn allows error and warn level log events to pass. | ||
85 | func AllowWarn() Option { | ||
86 | return allowed(levelError | levelWarn) | ||
87 | } | ||
88 | |||
89 | // AllowError allows only error level log events to pass. | ||
90 | func AllowError() Option { | ||
91 | return allowed(levelError) | ||
92 | } | ||
93 | |||
94 | // AllowNone allows no leveled log events to pass. | ||
95 | func AllowNone() Option { | ||
96 | return allowed(0) | ||
97 | } | ||
98 | |||
99 | func allowed(allowed level) Option { | ||
100 | return func(l *logger) { l.allowed = allowed } | ||
101 | } | ||
102 | |||
103 | // ErrNotAllowed sets the error to return from Log when it squelches a log | ||
104 | // event disallowed by the configured Allow[Level] option. By default, | ||
105 | // ErrNotAllowed is nil; in this case the log event is squelched with no | ||
106 | // error. | ||
107 | func ErrNotAllowed(err error) Option { | ||
108 | return func(l *logger) { l.errNotAllowed = err } | ||
109 | } | ||
110 | |||
111 | // SquelchNoLevel instructs Log to squelch log events with no level, so that | ||
112 | // they don't proceed through to the wrapped logger. If SquelchNoLevel is set | ||
113 | // to true and a log event is squelched in this way, the error value | ||
114 | // configured with ErrNoLevel is returned to the caller. | ||
115 | func SquelchNoLevel(squelch bool) Option { | ||
116 | return func(l *logger) { l.squelchNoLevel = squelch } | ||
117 | } | ||
118 | |||
119 | // ErrNoLevel sets the error to return from Log when it squelches a log event | ||
120 | // with no level. By default, ErrNoLevel is nil; in this case the log event is | ||
121 | // squelched with no error. | ||
122 | func ErrNoLevel(err error) Option { | ||
123 | return func(l *logger) { l.errNoLevel = err } | ||
124 | } | ||
125 | |||
126 | // NewInjector wraps next and returns a logger that adds a Key/level pair to | ||
127 | // the beginning of log events that don't already contain a level. In effect, | ||
128 | // this gives a default level to logs without a level. | ||
129 | func NewInjector(next log.Logger, level Value) log.Logger { | ||
130 | return &injector{ | ||
131 | next: next, | ||
132 | level: level, | ||
133 | } | ||
134 | } | ||
135 | |||
136 | type injector struct { | ||
137 | next log.Logger | ||
138 | level interface{} | ||
139 | } | ||
140 | |||
141 | func (l *injector) Log(keyvals ...interface{}) error { | ||
142 | for i := 1; i < len(keyvals); i += 2 { | ||
143 | if _, ok := keyvals[i].(*levelValue); ok { | ||
144 | return l.next.Log(keyvals...) | ||
145 | } | ||
146 | } | ||
147 | kvs := make([]interface{}, len(keyvals)+2) | ||
148 | kvs[0], kvs[1] = key, l.level | ||
149 | copy(kvs[2:], keyvals) | ||
150 | return l.next.Log(kvs...) | ||
151 | } | ||
152 | |||
153 | // Value is the interface that each of the canonical level values implement. | ||
154 | // It contains unexported methods that prevent types from other packages from | ||
155 | // implementing it and guaranteeing that NewFilter can distinguish the levels | ||
156 | // defined in this package from all other values. | ||
157 | type Value interface { | ||
158 | String() string | ||
159 | levelVal() | ||
160 | } | ||
161 | |||
162 | // Key returns the unique key added to log events by the loggers in this | ||
163 | // package. | ||
164 | func Key() interface{} { return key } | ||
165 | |||
166 | // ErrorValue returns the unique value added to log events by Error. | ||
167 | func ErrorValue() Value { return errorValue } | ||
168 | |||
169 | // WarnValue returns the unique value added to log events by Warn. | ||
170 | func WarnValue() Value { return warnValue } | ||
171 | |||
172 | // InfoValue returns the unique value added to log events by Info. | ||
173 | func InfoValue() Value { return infoValue } | ||
174 | |||
175 | // DebugValue returns the unique value added to log events by Warn. | ||
176 | func DebugValue() Value { return debugValue } | ||
177 | |||
178 | var ( | ||
179 | // key is of type interface{} so that it allocates once during package | ||
180 | // initialization and avoids allocating every time the value is added to a | ||
181 | // []interface{} later. | ||
182 | key interface{} = "level" | ||
183 | |||
184 | errorValue = &levelValue{level: levelError, name: "error"} | ||
185 | warnValue = &levelValue{level: levelWarn, name: "warn"} | ||
186 | infoValue = &levelValue{level: levelInfo, name: "info"} | ||
187 | debugValue = &levelValue{level: levelDebug, name: "debug"} | ||
188 | ) | ||
189 | |||
190 | type level byte | ||
191 | |||
192 | const ( | ||
193 | levelDebug level = 1 << iota | ||
194 | levelInfo | ||
195 | levelWarn | ||
196 | levelError | ||
197 | ) | ||
198 | |||
199 | type levelValue struct { | ||
200 | name string | ||
201 | level | ||
202 | } | ||
203 | |||
204 | func (v *levelValue) String() string { return v.name } | ||
205 | func (v *levelValue) levelVal() {} | ||
diff --git a/vendor/github.com/go-kit/kit/log/log.go b/vendor/github.com/go-kit/kit/log/log.go new file mode 100644 index 0000000..66a9e2f --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/log.go | |||
@@ -0,0 +1,135 @@ | |||
1 | package log | ||
2 | |||
3 | import "errors" | ||
4 | |||
5 | // Logger is the fundamental interface for all log operations. Log creates a | ||
6 | // log event from keyvals, a variadic sequence of alternating keys and values. | ||
7 | // Implementations must be safe for concurrent use by multiple goroutines. In | ||
8 | // particular, any implementation of Logger that appends to keyvals or | ||
9 | // modifies or retains any of its elements must make a copy first. | ||
10 | type Logger interface { | ||
11 | Log(keyvals ...interface{}) error | ||
12 | } | ||
13 | |||
14 | // ErrMissingValue is appended to keyvals slices with odd length to substitute | ||
15 | // the missing value. | ||
16 | var ErrMissingValue = errors.New("(MISSING)") | ||
17 | |||
18 | // With returns a new contextual logger with keyvals prepended to those passed | ||
19 | // to calls to Log. If logger is also a contextual logger created by With or | ||
20 | // WithPrefix, keyvals is appended to the existing context. | ||
21 | // | ||
22 | // The returned Logger replaces all value elements (odd indexes) containing a | ||
23 | // Valuer with their generated value for each call to its Log method. | ||
24 | func With(logger Logger, keyvals ...interface{}) Logger { | ||
25 | if len(keyvals) == 0 { | ||
26 | return logger | ||
27 | } | ||
28 | l := newContext(logger) | ||
29 | kvs := append(l.keyvals, keyvals...) | ||
30 | if len(kvs)%2 != 0 { | ||
31 | kvs = append(kvs, ErrMissingValue) | ||
32 | } | ||
33 | return &context{ | ||
34 | logger: l.logger, | ||
35 | // Limiting the capacity of the stored keyvals ensures that a new | ||
36 | // backing array is created if the slice must grow in Log or With. | ||
37 | // Using the extra capacity without copying risks a data race that | ||
38 | // would violate the Logger interface contract. | ||
39 | keyvals: kvs[:len(kvs):len(kvs)], | ||
40 | hasValuer: l.hasValuer || containsValuer(keyvals), | ||
41 | } | ||
42 | } | ||
43 | |||
44 | // WithPrefix returns a new contextual logger with keyvals prepended to those | ||
45 | // passed to calls to Log. If logger is also a contextual logger created by | ||
46 | // With or WithPrefix, keyvals is prepended to the existing context. | ||
47 | // | ||
48 | // The returned Logger replaces all value elements (odd indexes) containing a | ||
49 | // Valuer with their generated value for each call to its Log method. | ||
50 | func WithPrefix(logger Logger, keyvals ...interface{}) Logger { | ||
51 | if len(keyvals) == 0 { | ||
52 | return logger | ||
53 | } | ||
54 | l := newContext(logger) | ||
55 | // Limiting the capacity of the stored keyvals ensures that a new | ||
56 | // backing array is created if the slice must grow in Log or With. | ||
57 | // Using the extra capacity without copying risks a data race that | ||
58 | // would violate the Logger interface contract. | ||
59 | n := len(l.keyvals) + len(keyvals) | ||
60 | if len(keyvals)%2 != 0 { | ||
61 | n++ | ||
62 | } | ||
63 | kvs := make([]interface{}, 0, n) | ||
64 | kvs = append(kvs, keyvals...) | ||
65 | if len(kvs)%2 != 0 { | ||
66 | kvs = append(kvs, ErrMissingValue) | ||
67 | } | ||
68 | kvs = append(kvs, l.keyvals...) | ||
69 | return &context{ | ||
70 | logger: l.logger, | ||
71 | keyvals: kvs, | ||
72 | hasValuer: l.hasValuer || containsValuer(keyvals), | ||
73 | } | ||
74 | } | ||
75 | |||
76 | // context is the Logger implementation returned by With and WithPrefix. It | ||
77 | // wraps a Logger and holds keyvals that it includes in all log events. Its | ||
78 | // Log method calls bindValues to generate values for each Valuer in the | ||
79 | // context keyvals. | ||
80 | // | ||
81 | // A context must always have the same number of stack frames between calls to | ||
82 | // its Log method and the eventual binding of Valuers to their value. This | ||
83 | // requirement comes from the functional requirement to allow a context to | ||
84 | // resolve application call site information for a Caller stored in the | ||
85 | // context. To do this we must be able to predict the number of logging | ||
86 | // functions on the stack when bindValues is called. | ||
87 | // | ||
88 | // Two implementation details provide the needed stack depth consistency. | ||
89 | // | ||
90 | // 1. newContext avoids introducing an additional layer when asked to | ||
91 | // wrap another context. | ||
92 | // 2. With and WithPrefix avoid introducing an additional layer by | ||
93 | // returning a newly constructed context with a merged keyvals rather | ||
94 | // than simply wrapping the existing context. | ||
95 | type context struct { | ||
96 | logger Logger | ||
97 | keyvals []interface{} | ||
98 | hasValuer bool | ||
99 | } | ||
100 | |||
101 | func newContext(logger Logger) *context { | ||
102 | if c, ok := logger.(*context); ok { | ||
103 | return c | ||
104 | } | ||
105 | return &context{logger: logger} | ||
106 | } | ||
107 | |||
108 | // Log replaces all value elements (odd indexes) containing a Valuer in the | ||
109 | // stored context with their generated value, appends keyvals, and passes the | ||
110 | // result to the wrapped Logger. | ||
111 | func (l *context) Log(keyvals ...interface{}) error { | ||
112 | kvs := append(l.keyvals, keyvals...) | ||
113 | if len(kvs)%2 != 0 { | ||
114 | kvs = append(kvs, ErrMissingValue) | ||
115 | } | ||
116 | if l.hasValuer { | ||
117 | // If no keyvals were appended above then we must copy l.keyvals so | ||
118 | // that future log events will reevaluate the stored Valuers. | ||
119 | if len(keyvals) == 0 { | ||
120 | kvs = append([]interface{}{}, l.keyvals...) | ||
121 | } | ||
122 | bindValues(kvs[:len(l.keyvals)]) | ||
123 | } | ||
124 | return l.logger.Log(kvs...) | ||
125 | } | ||
126 | |||
127 | // LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If | ||
128 | // f is a function with the appropriate signature, LoggerFunc(f) is a Logger | ||
129 | // object that calls f. | ||
130 | type LoggerFunc func(...interface{}) error | ||
131 | |||
132 | // Log implements Logger by calling f(keyvals...). | ||
133 | func (f LoggerFunc) Log(keyvals ...interface{}) error { | ||
134 | return f(keyvals...) | ||
135 | } | ||
diff --git a/vendor/github.com/go-kit/kit/log/logfmt_logger.go b/vendor/github.com/go-kit/kit/log/logfmt_logger.go new file mode 100644 index 0000000..a003052 --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/logfmt_logger.go | |||
@@ -0,0 +1,62 @@ | |||
1 | package log | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "io" | ||
6 | "sync" | ||
7 | |||
8 | "github.com/go-logfmt/logfmt" | ||
9 | ) | ||
10 | |||
11 | type logfmtEncoder struct { | ||
12 | *logfmt.Encoder | ||
13 | buf bytes.Buffer | ||
14 | } | ||
15 | |||
16 | func (l *logfmtEncoder) Reset() { | ||
17 | l.Encoder.Reset() | ||
18 | l.buf.Reset() | ||
19 | } | ||
20 | |||
21 | var logfmtEncoderPool = sync.Pool{ | ||
22 | New: func() interface{} { | ||
23 | var enc logfmtEncoder | ||
24 | enc.Encoder = logfmt.NewEncoder(&enc.buf) | ||
25 | return &enc | ||
26 | }, | ||
27 | } | ||
28 | |||
29 | type logfmtLogger struct { | ||
30 | w io.Writer | ||
31 | } | ||
32 | |||
33 | // NewLogfmtLogger returns a logger that encodes keyvals to the Writer in | ||
34 | // logfmt format. Each log event produces no more than one call to w.Write. | ||
35 | // The passed Writer must be safe for concurrent use by multiple goroutines if | ||
36 | // the returned Logger will be used concurrently. | ||
37 | func NewLogfmtLogger(w io.Writer) Logger { | ||
38 | return &logfmtLogger{w} | ||
39 | } | ||
40 | |||
41 | func (l logfmtLogger) Log(keyvals ...interface{}) error { | ||
42 | enc := logfmtEncoderPool.Get().(*logfmtEncoder) | ||
43 | enc.Reset() | ||
44 | defer logfmtEncoderPool.Put(enc) | ||
45 | |||
46 | if err := enc.EncodeKeyvals(keyvals...); err != nil { | ||
47 | return err | ||
48 | } | ||
49 | |||
50 | // Add newline to the end of the buffer | ||
51 | if err := enc.EndRecord(); err != nil { | ||
52 | return err | ||
53 | } | ||
54 | |||
55 | // The Logger interface requires implementations to be safe for concurrent | ||
56 | // use by multiple goroutines. For this implementation that means making | ||
57 | // only one call to l.w.Write() for each call to Log. | ||
58 | if _, err := l.w.Write(enc.buf.Bytes()); err != nil { | ||
59 | return err | ||
60 | } | ||
61 | return nil | ||
62 | } | ||
diff --git a/vendor/github.com/go-kit/kit/log/nop_logger.go b/vendor/github.com/go-kit/kit/log/nop_logger.go new file mode 100644 index 0000000..1047d62 --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/nop_logger.go | |||
@@ -0,0 +1,8 @@ | |||
1 | package log | ||
2 | |||
3 | type nopLogger struct{} | ||
4 | |||
5 | // NewNopLogger returns a logger that doesn't do anything. | ||
6 | func NewNopLogger() Logger { return nopLogger{} } | ||
7 | |||
8 | func (nopLogger) Log(...interface{}) error { return nil } | ||
diff --git a/vendor/github.com/go-kit/kit/log/stdlib.go b/vendor/github.com/go-kit/kit/log/stdlib.go new file mode 100644 index 0000000..ff96b5d --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/stdlib.go | |||
@@ -0,0 +1,116 @@ | |||
1 | package log | ||
2 | |||
3 | import ( | ||
4 | "io" | ||
5 | "log" | ||
6 | "regexp" | ||
7 | "strings" | ||
8 | ) | ||
9 | |||
10 | // StdlibWriter implements io.Writer by invoking the stdlib log.Print. It's | ||
11 | // designed to be passed to a Go kit logger as the writer, for cases where | ||
12 | // it's necessary to redirect all Go kit log output to the stdlib logger. | ||
13 | // | ||
14 | // If you have any choice in the matter, you shouldn't use this. Prefer to | ||
15 | // redirect the stdlib log to the Go kit logger via NewStdlibAdapter. | ||
16 | type StdlibWriter struct{} | ||
17 | |||
18 | // Write implements io.Writer. | ||
19 | func (w StdlibWriter) Write(p []byte) (int, error) { | ||
20 | log.Print(strings.TrimSpace(string(p))) | ||
21 | return len(p), nil | ||
22 | } | ||
23 | |||
24 | // StdlibAdapter wraps a Logger and allows it to be passed to the stdlib | ||
25 | // logger's SetOutput. It will extract date/timestamps, filenames, and | ||
26 | // messages, and place them under relevant keys. | ||
27 | type StdlibAdapter struct { | ||
28 | Logger | ||
29 | timestampKey string | ||
30 | fileKey string | ||
31 | messageKey string | ||
32 | } | ||
33 | |||
34 | // StdlibAdapterOption sets a parameter for the StdlibAdapter. | ||
35 | type StdlibAdapterOption func(*StdlibAdapter) | ||
36 | |||
37 | // TimestampKey sets the key for the timestamp field. By default, it's "ts". | ||
38 | func TimestampKey(key string) StdlibAdapterOption { | ||
39 | return func(a *StdlibAdapter) { a.timestampKey = key } | ||
40 | } | ||
41 | |||
42 | // FileKey sets the key for the file and line field. By default, it's "caller". | ||
43 | func FileKey(key string) StdlibAdapterOption { | ||
44 | return func(a *StdlibAdapter) { a.fileKey = key } | ||
45 | } | ||
46 | |||
47 | // MessageKey sets the key for the actual log message. By default, it's "msg". | ||
48 | func MessageKey(key string) StdlibAdapterOption { | ||
49 | return func(a *StdlibAdapter) { a.messageKey = key } | ||
50 | } | ||
51 | |||
52 | // NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed | ||
53 | // logger. It's designed to be passed to log.SetOutput. | ||
54 | func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { | ||
55 | a := StdlibAdapter{ | ||
56 | Logger: logger, | ||
57 | timestampKey: "ts", | ||
58 | fileKey: "caller", | ||
59 | messageKey: "msg", | ||
60 | } | ||
61 | for _, option := range options { | ||
62 | option(&a) | ||
63 | } | ||
64 | return a | ||
65 | } | ||
66 | |||
67 | func (a StdlibAdapter) Write(p []byte) (int, error) { | ||
68 | result := subexps(p) | ||
69 | keyvals := []interface{}{} | ||
70 | var timestamp string | ||
71 | if date, ok := result["date"]; ok && date != "" { | ||
72 | timestamp = date | ||
73 | } | ||
74 | if time, ok := result["time"]; ok && time != "" { | ||
75 | if timestamp != "" { | ||
76 | timestamp += " " | ||
77 | } | ||
78 | timestamp += time | ||
79 | } | ||
80 | if timestamp != "" { | ||
81 | keyvals = append(keyvals, a.timestampKey, timestamp) | ||
82 | } | ||
83 | if file, ok := result["file"]; ok && file != "" { | ||
84 | keyvals = append(keyvals, a.fileKey, file) | ||
85 | } | ||
86 | if msg, ok := result["msg"]; ok { | ||
87 | keyvals = append(keyvals, a.messageKey, msg) | ||
88 | } | ||
89 | if err := a.Logger.Log(keyvals...); err != nil { | ||
90 | return 0, err | ||
91 | } | ||
92 | return len(p), nil | ||
93 | } | ||
94 | |||
95 | const ( | ||
96 | logRegexpDate = `(?P<date>[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` | ||
97 | logRegexpTime = `(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?)?[ ]?` | ||
98 | logRegexpFile = `(?P<file>.+?:[0-9]+)?` | ||
99 | logRegexpMsg = `(: )?(?P<msg>.*)` | ||
100 | ) | ||
101 | |||
102 | var ( | ||
103 | logRegexp = regexp.MustCompile(logRegexpDate + logRegexpTime + logRegexpFile + logRegexpMsg) | ||
104 | ) | ||
105 | |||
106 | func subexps(line []byte) map[string]string { | ||
107 | m := logRegexp.FindSubmatch(line) | ||
108 | if len(m) < len(logRegexp.SubexpNames()) { | ||
109 | return map[string]string{} | ||
110 | } | ||
111 | result := map[string]string{} | ||
112 | for i, name := range logRegexp.SubexpNames() { | ||
113 | result[name] = string(m[i]) | ||
114 | } | ||
115 | return result | ||
116 | } | ||
diff --git a/vendor/github.com/go-kit/kit/log/sync.go b/vendor/github.com/go-kit/kit/log/sync.go new file mode 100644 index 0000000..c07cdfa --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/sync.go | |||
@@ -0,0 +1,116 @@ | |||
1 | package log | ||
2 | |||
3 | import ( | ||
4 | "io" | ||
5 | "sync" | ||
6 | "sync/atomic" | ||
7 | ) | ||
8 | |||
9 | // SwapLogger wraps another logger that may be safely replaced while other | ||
10 | // goroutines use the SwapLogger concurrently. The zero value for a SwapLogger | ||
11 | // will discard all log events without error. | ||
12 | // | ||
13 | // SwapLogger serves well as a package global logger that can be changed by | ||
14 | // importers. | ||
15 | type SwapLogger struct { | ||
16 | logger atomic.Value | ||
17 | } | ||
18 | |||
19 | type loggerStruct struct { | ||
20 | Logger | ||
21 | } | ||
22 | |||
23 | // Log implements the Logger interface by forwarding keyvals to the currently | ||
24 | // wrapped logger. It does not log anything if the wrapped logger is nil. | ||
25 | func (l *SwapLogger) Log(keyvals ...interface{}) error { | ||
26 | s, ok := l.logger.Load().(loggerStruct) | ||
27 | if !ok || s.Logger == nil { | ||
28 | return nil | ||
29 | } | ||
30 | return s.Log(keyvals...) | ||
31 | } | ||
32 | |||
33 | // Swap replaces the currently wrapped logger with logger. Swap may be called | ||
34 | // concurrently with calls to Log from other goroutines. | ||
35 | func (l *SwapLogger) Swap(logger Logger) { | ||
36 | l.logger.Store(loggerStruct{logger}) | ||
37 | } | ||
38 | |||
39 | // NewSyncWriter returns a new writer that is safe for concurrent use by | ||
40 | // multiple goroutines. Writes to the returned writer are passed on to w. If | ||
41 | // another write is already in progress, the calling goroutine blocks until | ||
42 | // the writer is available. | ||
43 | // | ||
44 | // If w implements the following interface, so does the returned writer. | ||
45 | // | ||
46 | // interface { | ||
47 | // Fd() uintptr | ||
48 | // } | ||
49 | func NewSyncWriter(w io.Writer) io.Writer { | ||
50 | switch w := w.(type) { | ||
51 | case fdWriter: | ||
52 | return &fdSyncWriter{fdWriter: w} | ||
53 | default: | ||
54 | return &syncWriter{Writer: w} | ||
55 | } | ||
56 | } | ||
57 | |||
58 | // syncWriter synchronizes concurrent writes to an io.Writer. | ||
59 | type syncWriter struct { | ||
60 | sync.Mutex | ||
61 | io.Writer | ||
62 | } | ||
63 | |||
64 | // Write writes p to the underlying io.Writer. If another write is already in | ||
65 | // progress, the calling goroutine blocks until the syncWriter is available. | ||
66 | func (w *syncWriter) Write(p []byte) (n int, err error) { | ||
67 | w.Lock() | ||
68 | n, err = w.Writer.Write(p) | ||
69 | w.Unlock() | ||
70 | return n, err | ||
71 | } | ||
72 | |||
73 | // fdWriter is an io.Writer that also has an Fd method. The most common | ||
74 | // example of an fdWriter is an *os.File. | ||
75 | type fdWriter interface { | ||
76 | io.Writer | ||
77 | Fd() uintptr | ||
78 | } | ||
79 | |||
80 | // fdSyncWriter synchronizes concurrent writes to an fdWriter. | ||
81 | type fdSyncWriter struct { | ||
82 | sync.Mutex | ||
83 | fdWriter | ||
84 | } | ||
85 | |||
86 | // Write writes p to the underlying io.Writer. If another write is already in | ||
87 | // progress, the calling goroutine blocks until the fdSyncWriter is available. | ||
88 | func (w *fdSyncWriter) Write(p []byte) (n int, err error) { | ||
89 | w.Lock() | ||
90 | n, err = w.fdWriter.Write(p) | ||
91 | w.Unlock() | ||
92 | return n, err | ||
93 | } | ||
94 | |||
95 | // syncLogger provides concurrent safe logging for another Logger. | ||
96 | type syncLogger struct { | ||
97 | mu sync.Mutex | ||
98 | logger Logger | ||
99 | } | ||
100 | |||
101 | // NewSyncLogger returns a logger that synchronizes concurrent use of the | ||
102 | // wrapped logger. When multiple goroutines use the SyncLogger concurrently | ||
103 | // only one goroutine will be allowed to log to the wrapped logger at a time. | ||
104 | // The other goroutines will block until the logger is available. | ||
105 | func NewSyncLogger(logger Logger) Logger { | ||
106 | return &syncLogger{logger: logger} | ||
107 | } | ||
108 | |||
109 | // Log logs keyvals to the underlying Logger. If another log is already in | ||
110 | // progress, the calling goroutine blocks until the syncLogger is available. | ||
111 | func (l *syncLogger) Log(keyvals ...interface{}) error { | ||
112 | l.mu.Lock() | ||
113 | err := l.logger.Log(keyvals...) | ||
114 | l.mu.Unlock() | ||
115 | return err | ||
116 | } | ||
diff --git a/vendor/github.com/go-kit/kit/log/value.go b/vendor/github.com/go-kit/kit/log/value.go new file mode 100644 index 0000000..1486f14 --- /dev/null +++ b/vendor/github.com/go-kit/kit/log/value.go | |||
@@ -0,0 +1,110 @@ | |||
1 | package log | ||
2 | |||
3 | import ( | ||
4 | "runtime" | ||
5 | "strconv" | ||
6 | "strings" | ||
7 | "time" | ||
8 | ) | ||
9 | |||
10 | // A Valuer generates a log value. When passed to With or WithPrefix in a | ||
11 | // value element (odd indexes), it represents a dynamic value which is re- | ||
12 | // evaluated with each log event. | ||
13 | type Valuer func() interface{} | ||
14 | |||
15 | // bindValues replaces all value elements (odd indexes) containing a Valuer | ||
16 | // with their generated value. | ||
17 | func bindValues(keyvals []interface{}) { | ||
18 | for i := 1; i < len(keyvals); i += 2 { | ||
19 | if v, ok := keyvals[i].(Valuer); ok { | ||
20 | keyvals[i] = v() | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | // containsValuer returns true if any of the value elements (odd indexes) | ||
26 | // contain a Valuer. | ||
27 | func containsValuer(keyvals []interface{}) bool { | ||
28 | for i := 1; i < len(keyvals); i += 2 { | ||
29 | if _, ok := keyvals[i].(Valuer); ok { | ||
30 | return true | ||
31 | } | ||
32 | } | ||
33 | return false | ||
34 | } | ||
35 | |||
36 | // Timestamp returns a timestamp Valuer. It invokes the t function to get the | ||
37 | // time; unless you are doing something tricky, pass time.Now. | ||
38 | // | ||
39 | // Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which | ||
40 | // are TimestampFormats that use the RFC3339Nano format. | ||
41 | func Timestamp(t func() time.Time) Valuer { | ||
42 | return func() interface{} { return t() } | ||
43 | } | ||
44 | |||
45 | // TimestampFormat returns a timestamp Valuer with a custom time format. It | ||
46 | // invokes the t function to get the time to format; unless you are doing | ||
47 | // something tricky, pass time.Now. The layout string is passed to | ||
48 | // Time.Format. | ||
49 | // | ||
50 | // Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which | ||
51 | // are TimestampFormats that use the RFC3339Nano format. | ||
52 | func TimestampFormat(t func() time.Time, layout string) Valuer { | ||
53 | return func() interface{} { | ||
54 | return timeFormat{ | ||
55 | time: t(), | ||
56 | layout: layout, | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | // A timeFormat represents an instant in time and a layout used when | ||
62 | // marshaling to a text format. | ||
63 | type timeFormat struct { | ||
64 | time time.Time | ||
65 | layout string | ||
66 | } | ||
67 | |||
68 | func (tf timeFormat) String() string { | ||
69 | return tf.time.Format(tf.layout) | ||
70 | } | ||
71 | |||
72 | // MarshalText implements encoding.TextMarshaller. | ||
73 | func (tf timeFormat) MarshalText() (text []byte, err error) { | ||
74 | // The following code adapted from the standard library time.Time.Format | ||
75 | // method. Using the same undocumented magic constant to extend the size | ||
76 | // of the buffer as seen there. | ||
77 | b := make([]byte, 0, len(tf.layout)+10) | ||
78 | b = tf.time.AppendFormat(b, tf.layout) | ||
79 | return b, nil | ||
80 | } | ||
81 | |||
82 | // Caller returns a Valuer that returns a file and line from a specified depth | ||
83 | // in the callstack. Users will probably want to use DefaultCaller. | ||
84 | func Caller(depth int) Valuer { | ||
85 | return func() interface{} { | ||
86 | _, file, line, _ := runtime.Caller(depth) | ||
87 | idx := strings.LastIndexByte(file, '/') | ||
88 | // using idx+1 below handles both of following cases: | ||
89 | // idx == -1 because no "/" was found, or | ||
90 | // idx >= 0 and we want to start at the character after the found "/". | ||
91 | return file[idx+1:] + ":" + strconv.Itoa(line) | ||
92 | } | ||
93 | } | ||
94 | |||
95 | var ( | ||
96 | // DefaultTimestamp is a Valuer that returns the current wallclock time, | ||
97 | // respecting time zones, when bound. | ||
98 | DefaultTimestamp = TimestampFormat(time.Now, time.RFC3339Nano) | ||
99 | |||
100 | // DefaultTimestampUTC is a Valuer that returns the current time in UTC | ||
101 | // when bound. | ||
102 | DefaultTimestampUTC = TimestampFormat( | ||
103 | func() time.Time { return time.Now().UTC() }, | ||
104 | time.RFC3339Nano, | ||
105 | ) | ||
106 | |||
107 | // DefaultCaller is a Valuer that returns the file and line where the Log | ||
108 | // method was invoked. It can only be used with log.With. | ||
109 | DefaultCaller = Caller(3) | ||
110 | ) | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/.gitignore b/vendor/github.com/go-logfmt/logfmt/.gitignore new file mode 100644 index 0000000..320e53e --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | _testdata/ | ||
2 | _testdata2/ | ||
3 | logfmt-fuzz.zip | ||
4 | logfmt.test.exe | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/.travis.yml b/vendor/github.com/go-logfmt/logfmt/.travis.yml new file mode 100644 index 0000000..25976da --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/.travis.yml | |||
@@ -0,0 +1,16 @@ | |||
1 | language: go | ||
2 | sudo: false | ||
3 | go: | ||
4 | - "1.7.x" | ||
5 | - "1.8.x" | ||
6 | - "1.9.x" | ||
7 | - "1.10.x" | ||
8 | - "1.11.x" | ||
9 | - "tip" | ||
10 | |||
11 | before_install: | ||
12 | - go get github.com/mattn/goveralls | ||
13 | - go get golang.org/x/tools/cmd/cover | ||
14 | |||
15 | script: | ||
16 | - goveralls -service=travis-ci | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/CHANGELOG.md b/vendor/github.com/go-logfmt/logfmt/CHANGELOG.md new file mode 100644 index 0000000..3455b8e --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/CHANGELOG.md | |||
@@ -0,0 +1,41 @@ | |||
1 | # Changelog | ||
2 | All notable changes to this project will be documented in this file. | ||
3 | |||
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
6 | |||
7 | ## [0.4.0] - 2018-11-21 | ||
8 | |||
9 | ### Added | ||
10 | - Go module support by [@ChrisHines] | ||
11 | - CHANGELOG by [@ChrisHines] | ||
12 | |||
13 | ### Changed | ||
14 | - Drop invalid runes from keys instead of returning ErrInvalidKey by [@ChrisHines] | ||
15 | - On panic while printing, attempt to print panic value by [@bboreham] | ||
16 | |||
17 | ## [0.3.0] - 2016-11-15 | ||
18 | ### Added | ||
19 | - Pool buffers for quoted strings and byte slices by [@nussjustin] | ||
20 | ### Fixed | ||
21 | - Fuzz fix, quote invalid UTF-8 values by [@judwhite] | ||
22 | |||
23 | ## [0.2.0] - 2016-05-08 | ||
24 | ### Added | ||
25 | - Encoder.EncodeKeyvals by [@ChrisHines] | ||
26 | |||
27 | ## [0.1.0] - 2016-03-28 | ||
28 | ### Added | ||
29 | - Encoder by [@ChrisHines] | ||
30 | - Decoder by [@ChrisHines] | ||
31 | - MarshalKeyvals by [@ChrisHines] | ||
32 | |||
33 | [0.4.0]: https://github.com/go-logfmt/logfmt/compare/v0.3.0...v0.4.0 | ||
34 | [0.3.0]: https://github.com/go-logfmt/logfmt/compare/v0.2.0...v0.3.0 | ||
35 | [0.2.0]: https://github.com/go-logfmt/logfmt/compare/v0.1.0...v0.2.0 | ||
36 | [0.1.0]: https://github.com/go-logfmt/logfmt/commits/v0.1.0 | ||
37 | |||
38 | [@ChrisHines]: https://github.com/ChrisHines | ||
39 | [@bboreham]: https://github.com/bboreham | ||
40 | [@judwhite]: https://github.com/judwhite | ||
41 | [@nussjustin]: https://github.com/nussjustin | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/LICENSE b/vendor/github.com/go-logfmt/logfmt/LICENSE new file mode 100644 index 0000000..c026508 --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/LICENSE | |||
@@ -0,0 +1,22 @@ | |||
1 | The MIT License (MIT) | ||
2 | |||
3 | Copyright (c) 2015 go-logfmt | ||
4 | |||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | of this software and associated documentation files (the "Software"), to deal | ||
7 | in the Software without restriction, including without limitation the rights | ||
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | copies of the Software, and to permit persons to whom the Software is | ||
10 | furnished to do so, subject to the following conditions: | ||
11 | |||
12 | The above copyright notice and this permission notice shall be included in all | ||
13 | copies or substantial portions of the Software. | ||
14 | |||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
21 | SOFTWARE. | ||
22 | |||
diff --git a/vendor/github.com/go-logfmt/logfmt/README.md b/vendor/github.com/go-logfmt/logfmt/README.md new file mode 100644 index 0000000..3a8f10b --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/README.md | |||
@@ -0,0 +1,33 @@ | |||
1 | [![GoDoc](https://godoc.org/github.com/go-logfmt/logfmt?status.svg)](https://godoc.org/github.com/go-logfmt/logfmt) | ||
2 | [![Go Report Card](https://goreportcard.com/badge/go-logfmt/logfmt)](https://goreportcard.com/report/go-logfmt/logfmt) | ||
3 | [![TravisCI](https://travis-ci.org/go-logfmt/logfmt.svg?branch=master)](https://travis-ci.org/go-logfmt/logfmt) | ||
4 | [![Coverage Status](https://coveralls.io/repos/github/go-logfmt/logfmt/badge.svg?branch=master)](https://coveralls.io/github/go-logfmt/logfmt?branch=master) | ||
5 | |||
6 | # logfmt | ||
7 | |||
8 | Package logfmt implements utilities to marshal and unmarshal data in the [logfmt | ||
9 | format](https://brandur.org/logfmt). It provides an API similar to | ||
10 | [encoding/json](http://golang.org/pkg/encoding/json/) and | ||
11 | [encoding/xml](http://golang.org/pkg/encoding/xml/). | ||
12 | |||
13 | The logfmt format was first documented by Brandur Leach in [this | ||
14 | article](https://brandur.org/logfmt). The format has not been formally | ||
15 | standardized. The most authoritative public specification to date has been the | ||
16 | documentation of a Go Language [package](http://godoc.org/github.com/kr/logfmt) | ||
17 | written by Blake Mizerany and Keith Rarick. | ||
18 | |||
19 | ## Goals | ||
20 | |||
21 | This project attempts to conform as closely as possible to the prior art, while | ||
22 | also removing ambiguity where necessary to provide well behaved encoder and | ||
23 | decoder implementations. | ||
24 | |||
25 | ## Non-goals | ||
26 | |||
27 | This project does not attempt to formally standardize the logfmt format. In the | ||
28 | event that logfmt is standardized this project would take conforming to the | ||
29 | standard as a goal. | ||
30 | |||
31 | ## Versioning | ||
32 | |||
33 | Package logfmt publishes releases via [semver](http://semver.org/) compatible Git tags prefixed with a single 'v'. | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/decode.go b/vendor/github.com/go-logfmt/logfmt/decode.go new file mode 100644 index 0000000..04e0eff --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/decode.go | |||
@@ -0,0 +1,237 @@ | |||
1 | package logfmt | ||
2 | |||
3 | import ( | ||
4 | "bufio" | ||
5 | "bytes" | ||
6 | "fmt" | ||
7 | "io" | ||
8 | "unicode/utf8" | ||
9 | ) | ||
10 | |||
11 | // A Decoder reads and decodes logfmt records from an input stream. | ||
12 | type Decoder struct { | ||
13 | pos int | ||
14 | key []byte | ||
15 | value []byte | ||
16 | lineNum int | ||
17 | s *bufio.Scanner | ||
18 | err error | ||
19 | } | ||
20 | |||
21 | // NewDecoder returns a new decoder that reads from r. | ||
22 | // | ||
23 | // The decoder introduces its own buffering and may read data from r beyond | ||
24 | // the logfmt records requested. | ||
25 | func NewDecoder(r io.Reader) *Decoder { | ||
26 | dec := &Decoder{ | ||
27 | s: bufio.NewScanner(r), | ||
28 | } | ||
29 | return dec | ||
30 | } | ||
31 | |||
32 | // ScanRecord advances the Decoder to the next record, which can then be | ||
33 | // parsed with the ScanKeyval method. It returns false when decoding stops, | ||
34 | // either by reaching the end of the input or an error. After ScanRecord | ||
35 | // returns false, the Err method will return any error that occurred during | ||
36 | // decoding, except that if it was io.EOF, Err will return nil. | ||
37 | func (dec *Decoder) ScanRecord() bool { | ||
38 | if dec.err != nil { | ||
39 | return false | ||
40 | } | ||
41 | if !dec.s.Scan() { | ||
42 | dec.err = dec.s.Err() | ||
43 | return false | ||
44 | } | ||
45 | dec.lineNum++ | ||
46 | dec.pos = 0 | ||
47 | return true | ||
48 | } | ||
49 | |||
50 | // ScanKeyval advances the Decoder to the next key/value pair of the current | ||
51 | // record, which can then be retrieved with the Key and Value methods. It | ||
52 | // returns false when decoding stops, either by reaching the end of the | ||
53 | // current record or an error. | ||
54 | func (dec *Decoder) ScanKeyval() bool { | ||
55 | dec.key, dec.value = nil, nil | ||
56 | if dec.err != nil { | ||
57 | return false | ||
58 | } | ||
59 | |||
60 | line := dec.s.Bytes() | ||
61 | |||
62 | // garbage | ||
63 | for p, c := range line[dec.pos:] { | ||
64 | if c > ' ' { | ||
65 | dec.pos += p | ||
66 | goto key | ||
67 | } | ||
68 | } | ||
69 | dec.pos = len(line) | ||
70 | return false | ||
71 | |||
72 | key: | ||
73 | const invalidKeyError = "invalid key" | ||
74 | |||
75 | start, multibyte := dec.pos, false | ||
76 | for p, c := range line[dec.pos:] { | ||
77 | switch { | ||
78 | case c == '=': | ||
79 | dec.pos += p | ||
80 | if dec.pos > start { | ||
81 | dec.key = line[start:dec.pos] | ||
82 | if multibyte && bytes.IndexRune(dec.key, utf8.RuneError) != -1 { | ||
83 | dec.syntaxError(invalidKeyError) | ||
84 | return false | ||
85 | } | ||
86 | } | ||
87 | if dec.key == nil { | ||
88 | dec.unexpectedByte(c) | ||
89 | return false | ||
90 | } | ||
91 | goto equal | ||
92 | case c == '"': | ||
93 | dec.pos += p | ||
94 | dec.unexpectedByte(c) | ||
95 | return false | ||
96 | case c <= ' ': | ||
97 | dec.pos += p | ||
98 | if dec.pos > start { | ||
99 | dec.key = line[start:dec.pos] | ||
100 | if multibyte && bytes.IndexRune(dec.key, utf8.RuneError) != -1 { | ||
101 | dec.syntaxError(invalidKeyError) | ||
102 | return false | ||
103 | } | ||
104 | } | ||
105 | return true | ||
106 | case c >= utf8.RuneSelf: | ||
107 | multibyte = true | ||
108 | } | ||
109 | } | ||
110 | dec.pos = len(line) | ||
111 | if dec.pos > start { | ||
112 | dec.key = line[start:dec.pos] | ||
113 | if multibyte && bytes.IndexRune(dec.key, utf8.RuneError) != -1 { | ||
114 | dec.syntaxError(invalidKeyError) | ||
115 | return false | ||
116 | } | ||
117 | } | ||
118 | return true | ||
119 | |||
120 | equal: | ||
121 | dec.pos++ | ||
122 | if dec.pos >= len(line) { | ||
123 | return true | ||
124 | } | ||
125 | switch c := line[dec.pos]; { | ||
126 | case c <= ' ': | ||
127 | return true | ||
128 | case c == '"': | ||
129 | goto qvalue | ||
130 | } | ||
131 | |||
132 | // value | ||
133 | start = dec.pos | ||
134 | for p, c := range line[dec.pos:] { | ||
135 | switch { | ||
136 | case c == '=' || c == '"': | ||
137 | dec.pos += p | ||
138 | dec.unexpectedByte(c) | ||
139 | return false | ||
140 | case c <= ' ': | ||
141 | dec.pos += p | ||
142 | if dec.pos > start { | ||
143 | dec.value = line[start:dec.pos] | ||
144 | } | ||
145 | return true | ||
146 | } | ||
147 | } | ||
148 | dec.pos = len(line) | ||
149 | if dec.pos > start { | ||
150 | dec.value = line[start:dec.pos] | ||
151 | } | ||
152 | return true | ||
153 | |||
154 | qvalue: | ||
155 | const ( | ||
156 | untermQuote = "unterminated quoted value" | ||
157 | invalidQuote = "invalid quoted value" | ||
158 | ) | ||
159 | |||
160 | hasEsc, esc := false, false | ||
161 | start = dec.pos | ||
162 | for p, c := range line[dec.pos+1:] { | ||
163 | switch { | ||
164 | case esc: | ||
165 | esc = false | ||
166 | case c == '\\': | ||
167 | hasEsc, esc = true, true | ||
168 | case c == '"': | ||
169 | dec.pos += p + 2 | ||
170 | if hasEsc { | ||
171 | v, ok := unquoteBytes(line[start:dec.pos]) | ||
172 | if !ok { | ||
173 | dec.syntaxError(invalidQuote) | ||
174 | return false | ||
175 | } | ||
176 | dec.value = v | ||
177 | } else { | ||
178 | start++ | ||
179 | end := dec.pos - 1 | ||
180 | if end > start { | ||
181 | dec.value = line[start:end] | ||
182 | } | ||
183 | } | ||
184 | return true | ||
185 | } | ||
186 | } | ||
187 | dec.pos = len(line) | ||
188 | dec.syntaxError(untermQuote) | ||
189 | return false | ||
190 | } | ||
191 | |||
192 | // Key returns the most recent key found by a call to ScanKeyval. The returned | ||
193 | // slice may point to internal buffers and is only valid until the next call | ||
194 | // to ScanRecord. It does no allocation. | ||
195 | func (dec *Decoder) Key() []byte { | ||
196 | return dec.key | ||
197 | } | ||
198 | |||
199 | // Value returns the most recent value found by a call to ScanKeyval. The | ||
200 | // returned slice may point to internal buffers and is only valid until the | ||
201 | // next call to ScanRecord. It does no allocation when the value has no | ||
202 | // escape sequences. | ||
203 | func (dec *Decoder) Value() []byte { | ||
204 | return dec.value | ||
205 | } | ||
206 | |||
207 | // Err returns the first non-EOF error that was encountered by the Scanner. | ||
208 | func (dec *Decoder) Err() error { | ||
209 | return dec.err | ||
210 | } | ||
211 | |||
212 | func (dec *Decoder) syntaxError(msg string) { | ||
213 | dec.err = &SyntaxError{ | ||
214 | Msg: msg, | ||
215 | Line: dec.lineNum, | ||
216 | Pos: dec.pos + 1, | ||
217 | } | ||
218 | } | ||
219 | |||
220 | func (dec *Decoder) unexpectedByte(c byte) { | ||
221 | dec.err = &SyntaxError{ | ||
222 | Msg: fmt.Sprintf("unexpected %q", c), | ||
223 | Line: dec.lineNum, | ||
224 | Pos: dec.pos + 1, | ||
225 | } | ||
226 | } | ||
227 | |||
228 | // A SyntaxError represents a syntax error in the logfmt input stream. | ||
229 | type SyntaxError struct { | ||
230 | Msg string | ||
231 | Line int | ||
232 | Pos int | ||
233 | } | ||
234 | |||
235 | func (e *SyntaxError) Error() string { | ||
236 | return fmt.Sprintf("logfmt syntax error at pos %d on line %d: %s", e.Pos, e.Line, e.Msg) | ||
237 | } | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/doc.go b/vendor/github.com/go-logfmt/logfmt/doc.go new file mode 100644 index 0000000..378e9ad --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/doc.go | |||
@@ -0,0 +1,6 @@ | |||
1 | // Package logfmt implements utilities to marshal and unmarshal data in the | ||
2 | // logfmt format. The logfmt format records key/value pairs in a way that | ||
3 | // balances readability for humans and simplicity of computer parsing. It is | ||
4 | // most commonly used as a more human friendly alternative to JSON for | ||
5 | // structured logging. | ||
6 | package logfmt | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/encode.go b/vendor/github.com/go-logfmt/logfmt/encode.go new file mode 100644 index 0000000..4ea9d23 --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/encode.go | |||
@@ -0,0 +1,322 @@ | |||
1 | package logfmt | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "encoding" | ||
6 | "errors" | ||
7 | "fmt" | ||
8 | "io" | ||
9 | "reflect" | ||
10 | "strings" | ||
11 | "unicode/utf8" | ||
12 | ) | ||
13 | |||
14 | // MarshalKeyvals returns the logfmt encoding of keyvals, a variadic sequence | ||
15 | // of alternating keys and values. | ||
16 | func MarshalKeyvals(keyvals ...interface{}) ([]byte, error) { | ||
17 | buf := &bytes.Buffer{} | ||
18 | if err := NewEncoder(buf).EncodeKeyvals(keyvals...); err != nil { | ||
19 | return nil, err | ||
20 | } | ||
21 | return buf.Bytes(), nil | ||
22 | } | ||
23 | |||
24 | // An Encoder writes logfmt data to an output stream. | ||
25 | type Encoder struct { | ||
26 | w io.Writer | ||
27 | scratch bytes.Buffer | ||
28 | needSep bool | ||
29 | } | ||
30 | |||
31 | // NewEncoder returns a new encoder that writes to w. | ||
32 | func NewEncoder(w io.Writer) *Encoder { | ||
33 | return &Encoder{ | ||
34 | w: w, | ||
35 | } | ||
36 | } | ||
37 | |||
38 | var ( | ||
39 | space = []byte(" ") | ||
40 | equals = []byte("=") | ||
41 | newline = []byte("\n") | ||
42 | null = []byte("null") | ||
43 | ) | ||
44 | |||
45 | // EncodeKeyval writes the logfmt encoding of key and value to the stream. A | ||
46 | // single space is written before the second and subsequent keys in a record. | ||
47 | // Nothing is written if a non-nil error is returned. | ||
48 | func (enc *Encoder) EncodeKeyval(key, value interface{}) error { | ||
49 | enc.scratch.Reset() | ||
50 | if enc.needSep { | ||
51 | if _, err := enc.scratch.Write(space); err != nil { | ||
52 | return err | ||
53 | } | ||
54 | } | ||
55 | if err := writeKey(&enc.scratch, key); err != nil { | ||
56 | return err | ||
57 | } | ||
58 | if _, err := enc.scratch.Write(equals); err != nil { | ||
59 | return err | ||
60 | } | ||
61 | if err := writeValue(&enc.scratch, value); err != nil { | ||
62 | return err | ||
63 | } | ||
64 | _, err := enc.w.Write(enc.scratch.Bytes()) | ||
65 | enc.needSep = true | ||
66 | return err | ||
67 | } | ||
68 | |||
69 | // EncodeKeyvals writes the logfmt encoding of keyvals to the stream. Keyvals | ||
70 | // is a variadic sequence of alternating keys and values. Keys of unsupported | ||
71 | // type are skipped along with their corresponding value. Values of | ||
72 | // unsupported type or that cause a MarshalerError are replaced by their error | ||
73 | // but do not cause EncodeKeyvals to return an error. If a non-nil error is | ||
74 | // returned some key/value pairs may not have be written. | ||
75 | func (enc *Encoder) EncodeKeyvals(keyvals ...interface{}) error { | ||
76 | if len(keyvals) == 0 { | ||
77 | return nil | ||
78 | } | ||
79 | if len(keyvals)%2 == 1 { | ||
80 | keyvals = append(keyvals, nil) | ||
81 | } | ||
82 | for i := 0; i < len(keyvals); i += 2 { | ||
83 | k, v := keyvals[i], keyvals[i+1] | ||
84 | err := enc.EncodeKeyval(k, v) | ||
85 | if err == ErrUnsupportedKeyType { | ||
86 | continue | ||
87 | } | ||
88 | if _, ok := err.(*MarshalerError); ok || err == ErrUnsupportedValueType { | ||
89 | v = err | ||
90 | err = enc.EncodeKeyval(k, v) | ||
91 | } | ||
92 | if err != nil { | ||
93 | return err | ||
94 | } | ||
95 | } | ||
96 | return nil | ||
97 | } | ||
98 | |||
99 | // MarshalerError represents an error encountered while marshaling a value. | ||
100 | type MarshalerError struct { | ||
101 | Type reflect.Type | ||
102 | Err error | ||
103 | } | ||
104 | |||
105 | func (e *MarshalerError) Error() string { | ||
106 | return "error marshaling value of type " + e.Type.String() + ": " + e.Err.Error() | ||
107 | } | ||
108 | |||
109 | // ErrNilKey is returned by Marshal functions and Encoder methods if a key is | ||
110 | // a nil interface or pointer value. | ||
111 | var ErrNilKey = errors.New("nil key") | ||
112 | |||
113 | // ErrInvalidKey is returned by Marshal functions and Encoder methods if, after | ||
114 | // dropping invalid runes, a key is empty. | ||
115 | var ErrInvalidKey = errors.New("invalid key") | ||
116 | |||
117 | // ErrUnsupportedKeyType is returned by Encoder methods if a key has an | ||
118 | // unsupported type. | ||
119 | var ErrUnsupportedKeyType = errors.New("unsupported key type") | ||
120 | |||
121 | // ErrUnsupportedValueType is returned by Encoder methods if a value has an | ||
122 | // unsupported type. | ||
123 | var ErrUnsupportedValueType = errors.New("unsupported value type") | ||
124 | |||
125 | func writeKey(w io.Writer, key interface{}) error { | ||
126 | if key == nil { | ||
127 | return ErrNilKey | ||
128 | } | ||
129 | |||
130 | switch k := key.(type) { | ||
131 | case string: | ||
132 | return writeStringKey(w, k) | ||
133 | case []byte: | ||
134 | if k == nil { | ||
135 | return ErrNilKey | ||
136 | } | ||
137 | return writeBytesKey(w, k) | ||
138 | case encoding.TextMarshaler: | ||
139 | kb, err := safeMarshal(k) | ||
140 | if err != nil { | ||
141 | return err | ||
142 | } | ||
143 | if kb == nil { | ||
144 | return ErrNilKey | ||
145 | } | ||
146 | return writeBytesKey(w, kb) | ||
147 | case fmt.Stringer: | ||
148 | ks, ok := safeString(k) | ||
149 | if !ok { | ||
150 | return ErrNilKey | ||
151 | } | ||
152 | return writeStringKey(w, ks) | ||
153 | default: | ||
154 | rkey := reflect.ValueOf(key) | ||
155 | switch rkey.Kind() { | ||
156 | case reflect.Array, reflect.Chan, reflect.Func, reflect.Map, reflect.Slice, reflect.Struct: | ||
157 | return ErrUnsupportedKeyType | ||
158 | case reflect.Ptr: | ||
159 | if rkey.IsNil() { | ||
160 | return ErrNilKey | ||
161 | } | ||
162 | return writeKey(w, rkey.Elem().Interface()) | ||
163 | } | ||
164 | return writeStringKey(w, fmt.Sprint(k)) | ||
165 | } | ||
166 | } | ||
167 | |||
168 | // keyRuneFilter returns r for all valid key runes, and -1 for all invalid key | ||
169 | // runes. When used as the mapping function for strings.Map and bytes.Map | ||
170 | // functions it causes them to remove invalid key runes from strings or byte | ||
171 | // slices respectively. | ||
172 | func keyRuneFilter(r rune) rune { | ||
173 | if r <= ' ' || r == '=' || r == '"' || r == utf8.RuneError { | ||
174 | return -1 | ||
175 | } | ||
176 | return r | ||
177 | } | ||
178 | |||
179 | func writeStringKey(w io.Writer, key string) error { | ||
180 | k := strings.Map(keyRuneFilter, key) | ||
181 | if k == "" { | ||
182 | return ErrInvalidKey | ||
183 | } | ||
184 | _, err := io.WriteString(w, k) | ||
185 | return err | ||
186 | } | ||
187 | |||
188 | func writeBytesKey(w io.Writer, key []byte) error { | ||
189 | k := bytes.Map(keyRuneFilter, key) | ||
190 | if len(k) == 0 { | ||
191 | return ErrInvalidKey | ||
192 | } | ||
193 | _, err := w.Write(k) | ||
194 | return err | ||
195 | } | ||
196 | |||
197 | func writeValue(w io.Writer, value interface{}) error { | ||
198 | switch v := value.(type) { | ||
199 | case nil: | ||
200 | return writeBytesValue(w, null) | ||
201 | case string: | ||
202 | return writeStringValue(w, v, true) | ||
203 | case []byte: | ||
204 | return writeBytesValue(w, v) | ||
205 | case encoding.TextMarshaler: | ||
206 | vb, err := safeMarshal(v) | ||
207 | if err != nil { | ||
208 | return err | ||
209 | } | ||
210 | if vb == nil { | ||
211 | vb = null | ||
212 | } | ||
213 | return writeBytesValue(w, vb) | ||
214 | case error: | ||
215 | se, ok := safeError(v) | ||
216 | return writeStringValue(w, se, ok) | ||
217 | case fmt.Stringer: | ||
218 | ss, ok := safeString(v) | ||
219 | return writeStringValue(w, ss, ok) | ||
220 | default: | ||
221 | rvalue := reflect.ValueOf(value) | ||
222 | switch rvalue.Kind() { | ||
223 | case reflect.Array, reflect.Chan, reflect.Func, reflect.Map, reflect.Slice, reflect.Struct: | ||
224 | return ErrUnsupportedValueType | ||
225 | case reflect.Ptr: | ||
226 | if rvalue.IsNil() { | ||
227 | return writeBytesValue(w, null) | ||
228 | } | ||
229 | return writeValue(w, rvalue.Elem().Interface()) | ||
230 | } | ||
231 | return writeStringValue(w, fmt.Sprint(v), true) | ||
232 | } | ||
233 | } | ||
234 | |||
235 | func needsQuotedValueRune(r rune) bool { | ||
236 | return r <= ' ' || r == '=' || r == '"' || r == utf8.RuneError | ||
237 | } | ||
238 | |||
239 | func writeStringValue(w io.Writer, value string, ok bool) error { | ||
240 | var err error | ||
241 | if ok && value == "null" { | ||
242 | _, err = io.WriteString(w, `"null"`) | ||
243 | } else if strings.IndexFunc(value, needsQuotedValueRune) != -1 { | ||
244 | _, err = writeQuotedString(w, value) | ||
245 | } else { | ||
246 | _, err = io.WriteString(w, value) | ||
247 | } | ||
248 | return err | ||
249 | } | ||
250 | |||
251 | func writeBytesValue(w io.Writer, value []byte) error { | ||
252 | var err error | ||
253 | if bytes.IndexFunc(value, needsQuotedValueRune) != -1 { | ||
254 | _, err = writeQuotedBytes(w, value) | ||
255 | } else { | ||
256 | _, err = w.Write(value) | ||
257 | } | ||
258 | return err | ||
259 | } | ||
260 | |||
261 | // EndRecord writes a newline character to the stream and resets the encoder | ||
262 | // to the beginning of a new record. | ||
263 | func (enc *Encoder) EndRecord() error { | ||
264 | _, err := enc.w.Write(newline) | ||
265 | if err == nil { | ||
266 | enc.needSep = false | ||
267 | } | ||
268 | return err | ||
269 | } | ||
270 | |||
271 | // Reset resets the encoder to the beginning of a new record. | ||
272 | func (enc *Encoder) Reset() { | ||
273 | enc.needSep = false | ||
274 | } | ||
275 | |||
276 | func safeError(err error) (s string, ok bool) { | ||
277 | defer func() { | ||
278 | if panicVal := recover(); panicVal != nil { | ||
279 | if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { | ||
280 | s, ok = "null", false | ||
281 | } else { | ||
282 | s, ok = fmt.Sprintf("PANIC:%v", panicVal), false | ||
283 | } | ||
284 | } | ||
285 | }() | ||
286 | s, ok = err.Error(), true | ||
287 | return | ||
288 | } | ||
289 | |||
290 | func safeString(str fmt.Stringer) (s string, ok bool) { | ||
291 | defer func() { | ||
292 | if panicVal := recover(); panicVal != nil { | ||
293 | if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { | ||
294 | s, ok = "null", false | ||
295 | } else { | ||
296 | s, ok = fmt.Sprintf("PANIC:%v", panicVal), true | ||
297 | } | ||
298 | } | ||
299 | }() | ||
300 | s, ok = str.String(), true | ||
301 | return | ||
302 | } | ||
303 | |||
304 | func safeMarshal(tm encoding.TextMarshaler) (b []byte, err error) { | ||
305 | defer func() { | ||
306 | if panicVal := recover(); panicVal != nil { | ||
307 | if v := reflect.ValueOf(tm); v.Kind() == reflect.Ptr && v.IsNil() { | ||
308 | b, err = nil, nil | ||
309 | } else { | ||
310 | b, err = nil, fmt.Errorf("panic when marshalling: %s", panicVal) | ||
311 | } | ||
312 | } | ||
313 | }() | ||
314 | b, err = tm.MarshalText() | ||
315 | if err != nil { | ||
316 | return nil, &MarshalerError{ | ||
317 | Type: reflect.TypeOf(tm), | ||
318 | Err: err, | ||
319 | } | ||
320 | } | ||
321 | return | ||
322 | } | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/fuzz.go b/vendor/github.com/go-logfmt/logfmt/fuzz.go new file mode 100644 index 0000000..6553b35 --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/fuzz.go | |||
@@ -0,0 +1,126 @@ | |||
1 | // +build gofuzz | ||
2 | |||
3 | package logfmt | ||
4 | |||
5 | import ( | ||
6 | "bufio" | ||
7 | "bytes" | ||
8 | "fmt" | ||
9 | "io" | ||
10 | "reflect" | ||
11 | |||
12 | kr "github.com/kr/logfmt" | ||
13 | ) | ||
14 | |||
15 | // Fuzz checks reserialized data matches | ||
16 | func Fuzz(data []byte) int { | ||
17 | parsed, err := parse(data) | ||
18 | if err != nil { | ||
19 | return 0 | ||
20 | } | ||
21 | var w1 bytes.Buffer | ||
22 | if err = write(parsed, &w1); err != nil { | ||
23 | panic(err) | ||
24 | } | ||
25 | parsed, err = parse(w1.Bytes()) | ||
26 | if err != nil { | ||
27 | panic(err) | ||
28 | } | ||
29 | var w2 bytes.Buffer | ||
30 | if err = write(parsed, &w2); err != nil { | ||
31 | panic(err) | ||
32 | } | ||
33 | if !bytes.Equal(w1.Bytes(), w2.Bytes()) { | ||
34 | panic(fmt.Sprintf("reserialized data does not match:\n%q\n%q\n", w1.Bytes(), w2.Bytes())) | ||
35 | } | ||
36 | return 1 | ||
37 | } | ||
38 | |||
39 | // FuzzVsKR checks go-logfmt/logfmt against kr/logfmt | ||
40 | func FuzzVsKR(data []byte) int { | ||
41 | parsed, err := parse(data) | ||
42 | parsedKR, errKR := parseKR(data) | ||
43 | |||
44 | // github.com/go-logfmt/logfmt is a stricter parser. It returns errors for | ||
45 | // more inputs than github.com/kr/logfmt. Ignore any inputs that have a | ||
46 | // stict error. | ||
47 | if err != nil { | ||
48 | return 0 | ||
49 | } | ||
50 | |||
51 | // Fail if the more forgiving parser finds an error not found by the | ||
52 | // stricter parser. | ||
53 | if errKR != nil { | ||
54 | panic(fmt.Sprintf("unmatched error: %v", errKR)) | ||
55 | } | ||
56 | |||
57 | if !reflect.DeepEqual(parsed, parsedKR) { | ||
58 | panic(fmt.Sprintf("parsers disagree:\n%+v\n%+v\n", parsed, parsedKR)) | ||
59 | } | ||
60 | return 1 | ||
61 | } | ||
62 | |||
63 | type kv struct { | ||
64 | k, v []byte | ||
65 | } | ||
66 | |||
67 | func parse(data []byte) ([][]kv, error) { | ||
68 | var got [][]kv | ||
69 | dec := NewDecoder(bytes.NewReader(data)) | ||
70 | for dec.ScanRecord() { | ||
71 | var kvs []kv | ||
72 | for dec.ScanKeyval() { | ||
73 | kvs = append(kvs, kv{dec.Key(), dec.Value()}) | ||
74 | } | ||
75 | got = append(got, kvs) | ||
76 | } | ||
77 | return got, dec.Err() | ||
78 | } | ||
79 | |||
80 | func parseKR(data []byte) ([][]kv, error) { | ||
81 | var ( | ||
82 | s = bufio.NewScanner(bytes.NewReader(data)) | ||
83 | err error | ||
84 | h saveHandler | ||
85 | got [][]kv | ||
86 | ) | ||
87 | for err == nil && s.Scan() { | ||
88 | h.kvs = nil | ||
89 | err = kr.Unmarshal(s.Bytes(), &h) | ||
90 | got = append(got, h.kvs) | ||
91 | } | ||
92 | if err == nil { | ||
93 | err = s.Err() | ||
94 | } | ||
95 | return got, err | ||
96 | } | ||
97 | |||
98 | type saveHandler struct { | ||
99 | kvs []kv | ||
100 | } | ||
101 | |||
102 | func (h *saveHandler) HandleLogfmt(key, val []byte) error { | ||
103 | if len(key) == 0 { | ||
104 | key = nil | ||
105 | } | ||
106 | if len(val) == 0 { | ||
107 | val = nil | ||
108 | } | ||
109 | h.kvs = append(h.kvs, kv{key, val}) | ||
110 | return nil | ||
111 | } | ||
112 | |||
113 | func write(recs [][]kv, w io.Writer) error { | ||
114 | enc := NewEncoder(w) | ||
115 | for _, rec := range recs { | ||
116 | for _, f := range rec { | ||
117 | if err := enc.EncodeKeyval(f.k, f.v); err != nil { | ||
118 | return err | ||
119 | } | ||
120 | } | ||
121 | if err := enc.EndRecord(); err != nil { | ||
122 | return err | ||
123 | } | ||
124 | } | ||
125 | return nil | ||
126 | } | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/go.mod b/vendor/github.com/go-logfmt/logfmt/go.mod new file mode 100644 index 0000000..63d50f0 --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/go.mod | |||
@@ -0,0 +1,3 @@ | |||
1 | module github.com/go-logfmt/logfmt | ||
2 | |||
3 | require github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/go.sum b/vendor/github.com/go-logfmt/logfmt/go.sum new file mode 100644 index 0000000..d0cdc16 --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/go.sum | |||
@@ -0,0 +1,2 @@ | |||
1 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= | ||
2 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= | ||
diff --git a/vendor/github.com/go-logfmt/logfmt/jsonstring.go b/vendor/github.com/go-logfmt/logfmt/jsonstring.go new file mode 100644 index 0000000..030ac85 --- /dev/null +++ b/vendor/github.com/go-logfmt/logfmt/jsonstring.go | |||
@@ -0,0 +1,277 @@ | |||
1 | package logfmt | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "io" | ||
6 | "strconv" | ||
7 | "sync" | ||
8 | "unicode" | ||
9 | "unicode/utf16" | ||
10 | "unicode/utf8" | ||
11 | ) | ||
12 | |||
13 | // Taken from Go's encoding/json and modified for use here. | ||
14 | |||
15 | // Copyright 2010 The Go Authors. All rights reserved. | ||
16 | // Use of this source code is governed by a BSD-style | ||
17 | // license that can be found in the LICENSE file. | ||
18 | |||
19 | var hex = "0123456789abcdef" | ||
20 | |||
21 | var bufferPool = sync.Pool{ | ||
22 | New: func() interface{} { | ||
23 | return &bytes.Buffer{} | ||
24 | }, | ||
25 | } | ||
26 | |||
27 | func getBuffer() *bytes.Buffer { | ||
28 | return bufferPool.Get().(*bytes.Buffer) | ||
29 | } | ||
30 | |||
31 | func poolBuffer(buf *bytes.Buffer) { | ||
32 | buf.Reset() | ||
33 | bufferPool.Put(buf) | ||
34 | } | ||
35 | |||
36 | // NOTE: keep in sync with writeQuotedBytes below. | ||
37 | func writeQuotedString(w io.Writer, s string) (int, error) { | ||
38 | buf := getBuffer() | ||
39 | buf.WriteByte('"') | ||
40 | start := 0 | ||
41 | for i := 0; i < len(s); { | ||
42 | if b := s[i]; b < utf8.RuneSelf { | ||
43 | if 0x20 <= b && b != '\\' && b != '"' { | ||
44 | i++ | ||
45 | continue | ||
46 | } | ||
47 | if start < i { | ||
48 | buf.WriteString(s[start:i]) | ||
49 | } | ||
50 | switch b { | ||
51 | case '\\', '"': | ||
52 | buf.WriteByte('\\') | ||
53 | buf.WriteByte(b) | ||
54 | case '\n': | ||
55 | buf.WriteByte('\\') | ||
56 | buf.WriteByte('n') | ||
57 | case '\r': | ||
58 | buf.WriteByte('\\') | ||
59 | buf.WriteByte('r') | ||
60 | case '\t': | ||
61 | buf.WriteByte('\\') | ||
62 | buf.WriteByte('t') | ||
63 | default: | ||
64 | // This encodes bytes < 0x20 except for \n, \r, and \t. | ||
65 | buf.WriteString(`\u00`) | ||
66 | buf.WriteByte(hex[b>>4]) | ||
67 | buf.WriteByte(hex[b&0xF]) | ||
68 | } | ||
69 | i++ | ||
70 | start = i | ||
71 | continue | ||
72 | } | ||
73 | c, size := utf8.DecodeRuneInString(s[i:]) | ||
74 | if c == utf8.RuneError { | ||
75 | if start < i { | ||
76 | buf.WriteString(s[start:i]) | ||
77 | } | ||
78 | buf.WriteString(`\ufffd`) | ||
79 | i += size | ||
80 | start = i | ||
81 | continue | ||
82 | } | ||
83 | i += size | ||
84 | } | ||
85 | if start < len(s) { | ||
86 | buf.WriteString(s[start:]) | ||
87 | } | ||
88 | buf.WriteByte('"') | ||
89 | n, err := w.Write(buf.Bytes()) | ||
90 | poolBuffer(buf) | ||
91 | return n, err | ||
92 | } | ||
93 | |||
94 | // NOTE: keep in sync with writeQuoteString above. | ||
95 | func writeQuotedBytes(w io.Writer, s []byte) (int, error) { | ||
96 | buf := getBuffer() | ||
97 | buf.WriteByte('"') | ||
98 | start := 0 | ||
99 | for i := 0; i < len(s); { | ||
100 | if b := s[i]; b < utf8.RuneSelf { | ||
101 | if 0x20 <= b && b != '\\' && b != '"' { | ||
102 | i++ | ||
103 | continue | ||
104 | } | ||
105 | if start < i { | ||
106 | buf.Write(s[start:i]) | ||
107 | } | ||
108 | switch b { | ||
109 | case '\\', '"': | ||
110 | buf.WriteByte('\\') | ||
111 | buf.WriteByte(b) | ||
112 | case '\n': | ||
113 | buf.WriteByte('\\') | ||
114 | buf.WriteByte('n') | ||
115 | case '\r': | ||
116 | buf.WriteByte('\\') | ||
117 | buf.WriteByte('r') | ||
118 | case '\t': | ||
119 | buf.WriteByte('\\') | ||
120 | buf.WriteByte('t') | ||
121 | default: | ||
122 | // This encodes bytes < 0x20 except for \n, \r, and \t. | ||
123 | buf.WriteString(`\u00`) | ||
124 | buf.WriteByte(hex[b>>4]) | ||
125 | buf.WriteByte(hex[b&0xF]) | ||
126 | } | ||
127 | i++ | ||
128 | start = i | ||
129 | continue | ||
130 | } | ||
131 | c, size := utf8.DecodeRune(s[i:]) | ||
132 | if c == utf8.RuneError { | ||
133 | if start < i { | ||
134 | buf.Write(s[start:i]) | ||
135 | } | ||
136 | buf.WriteString(`\ufffd`) | ||
137 | i += size | ||
138 | start = i | ||
139 | continue | ||
140 | } | ||
141 | i += size | ||
142 | } | ||
143 | if start < len(s) { | ||
144 | buf.Write(s[start:]) | ||
145 | } | ||
146 | buf.WriteByte('"') | ||
147 | n, err := w.Write(buf.Bytes()) | ||
148 | poolBuffer(buf) | ||
149 | return n, err | ||
150 | } | ||
151 | |||
152 | // getu4 decodes \uXXXX from the beginning of s, returning the hex value, | ||
153 | // or it returns -1. | ||
154 | func getu4(s []byte) rune { | ||
155 | if len(s) < 6 || s[0] != '\\' || s[1] != 'u' { | ||
156 | return -1 | ||
157 | } | ||
158 | r, err := strconv.ParseUint(string(s[2:6]), 16, 64) | ||
159 | if err != nil { | ||
160 | return -1 | ||
161 | } | ||
162 | return rune(r) | ||
163 | } | ||
164 | |||
165 | func unquoteBytes(s []byte) (t []byte, ok bool) { | ||
166 | if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' { | ||
167 | return | ||
168 | } | ||
169 | s = s[1 : len(s)-1] | ||
170 | |||
171 | // Check for unusual characters. If there are none, | ||
172 | // then no unquoting is needed, so return a slice of the | ||
173 | // original bytes. | ||
174 | r := 0 | ||
175 | for r < len(s) { | ||
176 | c := s[r] | ||
177 | if c == '\\' || c == '"' || c < ' ' { | ||
178 | break | ||
179 | } | ||
180 | if c < utf8.RuneSelf { | ||
181 | r++ | ||
182 | continue | ||
183 | } | ||
184 | rr, size := utf8.DecodeRune(s[r:]) | ||
185 | if rr == utf8.RuneError { | ||
186 | break | ||
187 | } | ||
188 | r += size | ||
189 | } | ||
190 | if r == len(s) { | ||
191 | return s, true | ||
192 | } | ||
193 | |||
194 | b := make([]byte, len(s)+2*utf8.UTFMax) | ||
195 | w := copy(b, s[0:r]) | ||
196 | for r < len(s) { | ||
197 | // Out of room? Can only happen if s is full of | ||
198 | // malformed UTF-8 and we're replacing each | ||
199 | // byte with RuneError. | ||
200 | if w >= len(b)-2*utf8.UTFMax { | ||
201 | nb := make([]byte, (len(b)+utf8.UTFMax)*2) | ||
202 | copy(nb, b[0:w]) | ||
203 | b = nb | ||
204 | } | ||
205 | switch c := s[r]; { | ||
206 | case c == '\\': | ||
207 | r++ | ||
208 | if r >= len(s) { | ||
209 | return | ||
210 | } | ||
211 | switch s[r] { | ||
212 | default: | ||
213 | return | ||
214 | case '"', '\\', '/', '\'': | ||
215 | b[w] = s[r] | ||
216 | r++ | ||
217 | w++ | ||
218 | case 'b': | ||
219 | b[w] = '\b' | ||
220 | r++ | ||
221 | w++ | ||
222 | case 'f': | ||
223 | b[w] = '\f' | ||
224 | r++ | ||
225 | w++ | ||
226 | case 'n': | ||
227 | b[w] = '\n' | ||
228 | r++ | ||
229 | w++ | ||
230 | case 'r': | ||
231 | b[w] = '\r' | ||
232 | r++ | ||
233 | w++ | ||
234 | case 't': | ||
235 | b[w] = '\t' | ||
236 | r++ | ||
237 | w++ | ||
238 | case 'u': | ||
239 | r-- | ||
240 | rr := getu4(s[r:]) | ||
241 | if rr < 0 { | ||
242 | return | ||
243 | } | ||
244 | r += 6 | ||
245 | if utf16.IsSurrogate(rr) { | ||
246 | rr1 := getu4(s[r:]) | ||
247 | if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { | ||
248 | // A valid pair; consume. | ||
249 | r += 6 | ||
250 | w += utf8.EncodeRune(b[w:], dec) | ||
251 | break | ||
252 | } | ||
253 | // Invalid surrogate; fall back to replacement rune. | ||
254 | rr = unicode.ReplacementChar | ||
255 | } | ||
256 | w += utf8.EncodeRune(b[w:], rr) | ||
257 | } | ||
258 | |||
259 | // Quote, control characters are invalid. | ||
260 | case c == '"', c < ' ': | ||
261 | return | ||
262 | |||
263 | // ASCII | ||
264 | case c < utf8.RuneSelf: | ||
265 | b[w] = c | ||
266 | r++ | ||
267 | w++ | ||
268 | |||
269 | // Coerce to well-formed UTF-8. | ||
270 | default: | ||
271 | rr, size := utf8.DecodeRune(s[r:]) | ||
272 | r += size | ||
273 | w += utf8.EncodeRune(b[w:], rr) | ||
274 | } | ||
275 | } | ||
276 | return b[0:w], true | ||
277 | } | ||
diff --git a/vendor/github.com/konsorten/go-windows-terminal-sequences/README.md b/vendor/github.com/konsorten/go-windows-terminal-sequences/README.md deleted file mode 100644 index 195333e..0000000 --- a/vendor/github.com/konsorten/go-windows-terminal-sequences/README.md +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | # Windows Terminal Sequences | ||
2 | |||
3 | This library allow for enabling Windows terminal color support for Go. | ||
4 | |||
5 | See [Console Virtual Terminal Sequences](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) for details. | ||
6 | |||
7 | ## Usage | ||
8 | |||
9 | ```go | ||
10 | import ( | ||
11 | "syscall" | ||
12 | |||
13 | sequences "github.com/konsorten/go-windows-terminal-sequences" | ||
14 | ) | ||
15 | |||
16 | func main() { | ||
17 | sequences.EnableVirtualTerminalProcessing(syscall.Stdout, true) | ||
18 | } | ||
19 | |||
20 | ``` | ||
21 | |||
22 | ## Authors | ||
23 | |||
24 | The tool is sponsored by the [marvin + konsorten GmbH](http://www.konsorten.de). | ||
25 | |||
26 | We thank all the authors who provided code to this library: | ||
27 | |||
28 | * Felix Kollmann | ||
29 | * Nicolas Perraut | ||
30 | |||
31 | ## License | ||
32 | |||
33 | (The MIT License) | ||
34 | |||
35 | Copyright (c) 2018 marvin + konsorten GmbH (open-source@konsorten.de) | ||
36 | |||
37 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
38 | |||
39 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
40 | |||
41 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
diff --git a/vendor/github.com/konsorten/go-windows-terminal-sequences/go.mod b/vendor/github.com/konsorten/go-windows-terminal-sequences/go.mod deleted file mode 100644 index 716c613..0000000 --- a/vendor/github.com/konsorten/go-windows-terminal-sequences/go.mod +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | module github.com/konsorten/go-windows-terminal-sequences | ||
diff --git a/vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go b/vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go deleted file mode 100644 index ef18d8f..0000000 --- a/vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | // +build windows | ||
2 | |||
3 | package sequences | ||
4 | |||
5 | import ( | ||
6 | "syscall" | ||
7 | "unsafe" | ||
8 | ) | ||
9 | |||
10 | var ( | ||
11 | kernel32Dll *syscall.LazyDLL = syscall.NewLazyDLL("Kernel32.dll") | ||
12 | setConsoleMode *syscall.LazyProc = kernel32Dll.NewProc("SetConsoleMode") | ||
13 | ) | ||
14 | |||
15 | func EnableVirtualTerminalProcessing(stream syscall.Handle, enable bool) error { | ||
16 | const ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x4 | ||
17 | |||
18 | var mode uint32 | ||
19 | err := syscall.GetConsoleMode(syscall.Stdout, &mode) | ||
20 | if err != nil { | ||
21 | return err | ||
22 | } | ||
23 | |||
24 | if enable { | ||
25 | mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
26 | } else { | ||
27 | mode &^= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
28 | } | ||
29 | |||
30 | ret, _, err := setConsoleMode.Call(uintptr(unsafe.Pointer(stream)), uintptr(mode)) | ||
31 | if ret == 0 { | ||
32 | return err | ||
33 | } | ||
34 | |||
35 | return nil | ||
36 | } | ||
diff --git a/vendor/github.com/konsorten/go-windows-terminal-sequences/sequences_dummy.go b/vendor/github.com/konsorten/go-windows-terminal-sequences/sequences_dummy.go deleted file mode 100644 index df61a6f..0000000 --- a/vendor/github.com/konsorten/go-windows-terminal-sequences/sequences_dummy.go +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | // +build linux darwin | ||
2 | |||
3 | package sequences | ||
4 | |||
5 | import ( | ||
6 | "fmt" | ||
7 | ) | ||
8 | |||
9 | func EnableVirtualTerminalProcessing(stream uintptr, enable bool) error { | ||
10 | return fmt.Errorf("windows only package") | ||
11 | } | ||
diff --git a/vendor/github.com/kr/logfmt/.gitignore b/vendor/github.com/kr/logfmt/.gitignore new file mode 100644 index 0000000..8e524f6 --- /dev/null +++ b/vendor/github.com/kr/logfmt/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | *.test | ||
2 | *.swp | ||
3 | *.prof | ||
diff --git a/vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE b/vendor/github.com/kr/logfmt/Readme index 14127cd..1865a11 100644 --- a/vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE +++ b/vendor/github.com/kr/logfmt/Readme | |||
@@ -1,9 +1,12 @@ | |||
1 | (The MIT License) | 1 | Go package for parsing (and, eventually, generating) |
2 | log lines in the logfmt style. | ||
2 | 3 | ||
3 | Copyright (c) 2017 marvin + konsorten GmbH (open-source@konsorten.de) | 4 | See http://godoc.org/github.com/kr/logfmt for format, and other documentation and examples. |
4 | 5 | ||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | 6 | Copyright (C) 2013 Keith Rarick, Blake Mizerany |
7 | |||
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
6 | 9 | ||
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
8 | 11 | ||
9 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
diff --git a/vendor/github.com/kr/logfmt/decode.go b/vendor/github.com/kr/logfmt/decode.go new file mode 100644 index 0000000..1397fb7 --- /dev/null +++ b/vendor/github.com/kr/logfmt/decode.go | |||
@@ -0,0 +1,184 @@ | |||
1 | // Package implements the decoding of logfmt key-value pairs. | ||
2 | // | ||
3 | // Example logfmt message: | ||
4 | // | ||
5 | // foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf | ||
6 | // | ||
7 | // Example result in JSON: | ||
8 | // | ||
9 | // { "foo": "bar", "a": 14, "baz": "hello kitty", "cool%story": "bro", "f": true, "%^asdf": true } | ||
10 | // | ||
11 | // EBNFish: | ||
12 | // | ||
13 | // ident_byte = any byte greater than ' ', excluding '=' and '"' | ||
14 | // string_byte = any byte excluding '"' and '\' | ||
15 | // garbage = !ident_byte | ||
16 | // ident = ident_byte, { ident byte } | ||
17 | // key = ident | ||
18 | // value = ident | '"', { string_byte | '\', '"' }, '"' | ||
19 | // pair = key, '=', value | key, '=' | key | ||
20 | // message = { garbage, pair }, garbage | ||
21 | package logfmt | ||
22 | |||
23 | import ( | ||
24 | "reflect" | ||
25 | "strconv" | ||
26 | "strings" | ||
27 | "time" | ||
28 | ) | ||
29 | |||
30 | // Handler is the interface implemented by objects that accept logfmt | ||
31 | // key-value pairs. HandleLogfmt must copy the logfmt data if it | ||
32 | // wishes to retain the data after returning. | ||
33 | type Handler interface { | ||
34 | HandleLogfmt(key, val []byte) error | ||
35 | } | ||
36 | |||
37 | // The HandlerFunc type is an adapter to allow the use of ordinary functions as | ||
38 | // logfmt handlers. If f is a function with the appropriate signature, | ||
39 | // HandlerFunc(f) is a Handler object that calls f. | ||
40 | type HandlerFunc func(key, val []byte) error | ||
41 | |||
42 | func (f HandlerFunc) HandleLogfmt(key, val []byte) error { | ||
43 | return f(key, val) | ||
44 | } | ||
45 | |||
46 | // Unmarshal parses the logfmt encoding data and stores the result in the value | ||
47 | // pointed to by v. If v is an Handler, HandleLogfmt will be called for each | ||
48 | // key-value pair. | ||
49 | // | ||
50 | // If v is not a Handler, it will pass v to NewStructHandler and use the | ||
51 | // returned StructHandler for decoding. | ||
52 | func Unmarshal(data []byte, v interface{}) (err error) { | ||
53 | h, ok := v.(Handler) | ||
54 | if !ok { | ||
55 | h, err = NewStructHandler(v) | ||
56 | if err != nil { | ||
57 | return err | ||
58 | } | ||
59 | } | ||
60 | return gotoScanner(data, h) | ||
61 | } | ||
62 | |||
63 | // StructHandler unmarshals logfmt into a struct. It matches incoming keys to | ||
64 | // the the struct's fields (either the struct field name or its tag, preferring | ||
65 | // an exact match but also accepting a case-insensitive match. | ||
66 | // | ||
67 | // Field types supported by StructHandler are: | ||
68 | // | ||
69 | // all numeric types (e.g. float32, int, etc.) | ||
70 | // []byte | ||
71 | // string | ||
72 | // bool - true if key is present, false otherwise (the value is ignored). | ||
73 | // time.Duration - uses time.ParseDuration | ||
74 | // | ||
75 | // If a field is a pointer to an above type, and a matching key is not present | ||
76 | // in the logfmt data, the pointer will be untouched. | ||
77 | // | ||
78 | // If v is not a pointer to an Handler or struct, Unmarshal will return an | ||
79 | // error. | ||
80 | type StructHandler struct { | ||
81 | rv reflect.Value | ||
82 | } | ||
83 | |||
84 | func NewStructHandler(v interface{}) (Handler, error) { | ||
85 | rv := reflect.ValueOf(v) | ||
86 | if rv.Kind() != reflect.Ptr || rv.IsNil() { | ||
87 | return nil, &InvalidUnmarshalError{reflect.TypeOf(v)} | ||
88 | } | ||
89 | return &StructHandler{rv: rv}, nil | ||
90 | } | ||
91 | |||
92 | func (h *StructHandler) HandleLogfmt(key, val []byte) error { | ||
93 | el := h.rv.Elem() | ||
94 | skey := string(key) | ||
95 | for i := 0; i < el.NumField(); i++ { | ||
96 | fv := el.Field(i) | ||
97 | ft := el.Type().Field(i) | ||
98 | switch { | ||
99 | case ft.Name == skey: | ||
100 | case ft.Tag.Get("logfmt") == skey: | ||
101 | case strings.EqualFold(ft.Name, skey): | ||
102 | default: | ||
103 | continue | ||
104 | } | ||
105 | if fv.Kind() == reflect.Ptr { | ||
106 | if fv.IsNil() { | ||
107 | t := fv.Type().Elem() | ||
108 | v := reflect.New(t) | ||
109 | fv.Set(v) | ||
110 | fv = v | ||
111 | } | ||
112 | fv = fv.Elem() | ||
113 | } | ||
114 | switch fv.Interface().(type) { | ||
115 | case time.Duration: | ||
116 | d, err := time.ParseDuration(string(val)) | ||
117 | if err != nil { | ||
118 | return &UnmarshalTypeError{string(val), fv.Type()} | ||
119 | } | ||
120 | fv.Set(reflect.ValueOf(d)) | ||
121 | case string: | ||
122 | fv.SetString(string(val)) | ||
123 | case []byte: | ||
124 | b := make([]byte, len(val)) | ||
125 | copy(b, val) | ||
126 | fv.SetBytes(b) | ||
127 | case bool: | ||
128 | fv.SetBool(true) | ||
129 | default: | ||
130 | switch { | ||
131 | case reflect.Int <= fv.Kind() && fv.Kind() <= reflect.Int64: | ||
132 | v, err := strconv.ParseInt(string(val), 10, 64) | ||
133 | if err != nil { | ||
134 | return err | ||
135 | } | ||
136 | fv.SetInt(v) | ||
137 | case reflect.Uint32 <= fv.Kind() && fv.Kind() <= reflect.Uint64: | ||
138 | v, err := strconv.ParseUint(string(val), 10, 64) | ||
139 | if err != nil { | ||
140 | return err | ||
141 | } | ||
142 | fv.SetUint(v) | ||
143 | case reflect.Float32 <= fv.Kind() && fv.Kind() <= reflect.Float64: | ||
144 | v, err := strconv.ParseFloat(string(val), 10) | ||
145 | if err != nil { | ||
146 | return err | ||
147 | } | ||
148 | fv.SetFloat(v) | ||
149 | default: | ||
150 | return &UnmarshalTypeError{string(val), fv.Type()} | ||
151 | } | ||
152 | } | ||
153 | |||
154 | } | ||
155 | return nil | ||
156 | } | ||
157 | |||
158 | // An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. | ||
159 | // (The argument to Unmarshal must be a non-nil pointer.) | ||
160 | type InvalidUnmarshalError struct { | ||
161 | Type reflect.Type | ||
162 | } | ||
163 | |||
164 | func (e *InvalidUnmarshalError) Error() string { | ||
165 | if e.Type == nil { | ||
166 | return "logfmt: Unmarshal(nil)" | ||
167 | } | ||
168 | |||
169 | if e.Type.Kind() != reflect.Ptr { | ||
170 | return "logfmt: Unmarshal(non-pointer " + e.Type.String() + ")" | ||
171 | } | ||
172 | return "logfmt: Unmarshal(nil " + e.Type.String() + ")" | ||
173 | } | ||
174 | |||
175 | // An UnmarshalTypeError describes a logfmt value that was | ||
176 | // not appropriate for a value of a specific Go type. | ||
177 | type UnmarshalTypeError struct { | ||
178 | Value string // the logfmt value | ||
179 | Type reflect.Type // type of Go value it could not be assigned to | ||
180 | } | ||
181 | |||
182 | func (e *UnmarshalTypeError) Error() string { | ||
183 | return "logfmt: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String() | ||
184 | } | ||
diff --git a/vendor/github.com/kr/logfmt/scanner.go b/vendor/github.com/kr/logfmt/scanner.go new file mode 100644 index 0000000..095221f --- /dev/null +++ b/vendor/github.com/kr/logfmt/scanner.go | |||
@@ -0,0 +1,149 @@ | |||
1 | package logfmt | ||
2 | |||
3 | import ( | ||
4 | "errors" | ||
5 | "fmt" | ||
6 | ) | ||
7 | |||
8 | var ErrUnterminatedString = errors.New("logfmt: unterminated string") | ||
9 | |||
10 | func gotoScanner(data []byte, h Handler) (err error) { | ||
11 | saveError := func(e error) { | ||
12 | if err == nil { | ||
13 | err = e | ||
14 | } | ||
15 | } | ||
16 | |||
17 | var c byte | ||
18 | var i int | ||
19 | var m int | ||
20 | var key []byte | ||
21 | var val []byte | ||
22 | var ok bool | ||
23 | var esc bool | ||
24 | |||
25 | garbage: | ||
26 | if i == len(data) { | ||
27 | return | ||
28 | } | ||
29 | |||
30 | c = data[i] | ||
31 | switch { | ||
32 | case c > ' ' && c != '"' && c != '=': | ||
33 | key, val = nil, nil | ||
34 | m = i | ||
35 | i++ | ||
36 | goto key | ||
37 | default: | ||
38 | i++ | ||
39 | goto garbage | ||
40 | } | ||
41 | |||
42 | key: | ||
43 | if i >= len(data) { | ||
44 | if m >= 0 { | ||
45 | key = data[m:i] | ||
46 | saveError(h.HandleLogfmt(key, nil)) | ||
47 | } | ||
48 | return | ||
49 | } | ||
50 | |||
51 | c = data[i] | ||
52 | switch { | ||
53 | case c > ' ' && c != '"' && c != '=': | ||
54 | i++ | ||
55 | goto key | ||
56 | case c == '=': | ||
57 | key = data[m:i] | ||
58 | i++ | ||
59 | goto equal | ||
60 | default: | ||
61 | key = data[m:i] | ||
62 | i++ | ||
63 | saveError(h.HandleLogfmt(key, nil)) | ||
64 | goto garbage | ||
65 | } | ||
66 | |||
67 | equal: | ||
68 | if i >= len(data) { | ||
69 | if m >= 0 { | ||
70 | i-- | ||
71 | key = data[m:i] | ||
72 | saveError(h.HandleLogfmt(key, nil)) | ||
73 | } | ||
74 | return | ||
75 | } | ||
76 | |||
77 | c = data[i] | ||
78 | switch { | ||
79 | case c > ' ' && c != '"' && c != '=': | ||
80 | m = i | ||
81 | i++ | ||
82 | goto ivalue | ||
83 | case c == '"': | ||
84 | m = i | ||
85 | i++ | ||
86 | esc = false | ||
87 | goto qvalue | ||
88 | default: | ||
89 | if key != nil { | ||
90 | saveError(h.HandleLogfmt(key, val)) | ||
91 | } | ||
92 | i++ | ||
93 | goto garbage | ||
94 | } | ||
95 | |||
96 | ivalue: | ||
97 | if i >= len(data) { | ||
98 | if m >= 0 { | ||
99 | val = data[m:i] | ||
100 | saveError(h.HandleLogfmt(key, val)) | ||
101 | } | ||
102 | return | ||
103 | } | ||
104 | |||
105 | c = data[i] | ||
106 | switch { | ||
107 | case c > ' ' && c != '"' && c != '=': | ||
108 | i++ | ||
109 | goto ivalue | ||
110 | default: | ||
111 | val = data[m:i] | ||
112 | saveError(h.HandleLogfmt(key, val)) | ||
113 | i++ | ||
114 | goto garbage | ||
115 | } | ||
116 | |||
117 | qvalue: | ||
118 | if i >= len(data) { | ||
119 | if m >= 0 { | ||
120 | saveError(ErrUnterminatedString) | ||
121 | } | ||
122 | return | ||
123 | } | ||
124 | |||
125 | c = data[i] | ||
126 | switch c { | ||
127 | case '\\': | ||
128 | i += 2 | ||
129 | esc = true | ||
130 | goto qvalue | ||
131 | case '"': | ||
132 | i++ | ||
133 | val = data[m:i] | ||
134 | if esc { | ||
135 | val, ok = unquoteBytes(val) | ||
136 | if !ok { | ||
137 | saveError(fmt.Errorf("logfmt: error unquoting bytes %q", string(val))) | ||
138 | goto garbage | ||
139 | } | ||
140 | } else { | ||
141 | val = val[1 : len(val)-1] | ||
142 | } | ||
143 | saveError(h.HandleLogfmt(key, val)) | ||
144 | goto garbage | ||
145 | default: | ||
146 | i++ | ||
147 | goto qvalue | ||
148 | } | ||
149 | } | ||
diff --git a/vendor/github.com/kr/logfmt/unquote.go b/vendor/github.com/kr/logfmt/unquote.go new file mode 100644 index 0000000..fb088a4 --- /dev/null +++ b/vendor/github.com/kr/logfmt/unquote.go | |||
@@ -0,0 +1,149 @@ | |||
1 | package logfmt | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | "unicode" | ||
6 | "unicode/utf16" | ||
7 | "unicode/utf8" | ||
8 | ) | ||
9 | |||
10 | // Taken from Go's encoding/json | ||
11 | |||
12 | // Copyright 2010 The Go Authors. All rights reserved. | ||
13 | // Use of this source code is governed by a BSD-style | ||
14 | // license that can be found in the LICENSE file. | ||
15 | |||
16 | // getu4 decodes \uXXXX from the beginning of s, returning the hex value, | ||
17 | // or it returns -1. | ||
18 | func getu4(s []byte) rune { | ||
19 | if len(s) < 6 || s[0] != '\\' || s[1] != 'u' { | ||
20 | return -1 | ||
21 | } | ||
22 | r, err := strconv.ParseUint(string(s[2:6]), 16, 64) | ||
23 | if err != nil { | ||
24 | return -1 | ||
25 | } | ||
26 | return rune(r) | ||
27 | } | ||
28 | |||
29 | // unquote converts a quoted JSON string literal s into an actual string t. | ||
30 | // The rules are different than for Go, so cannot use strconv.Unquote. | ||
31 | func unquote(s []byte) (t string, ok bool) { | ||
32 | s, ok = unquoteBytes(s) | ||
33 | t = string(s) | ||
34 | return | ||
35 | } | ||
36 | |||
37 | func unquoteBytes(s []byte) (t []byte, ok bool) { | ||
38 | if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' { | ||
39 | return | ||
40 | } | ||
41 | s = s[1 : len(s)-1] | ||
42 | |||
43 | // Check for unusual characters. If there are none, | ||
44 | // then no unquoting is needed, so return a slice of the | ||
45 | // original bytes. | ||
46 | r := 0 | ||
47 | for r < len(s) { | ||
48 | c := s[r] | ||
49 | if c == '\\' || c == '"' || c < ' ' { | ||
50 | break | ||
51 | } | ||
52 | if c < utf8.RuneSelf { | ||
53 | r++ | ||
54 | continue | ||
55 | } | ||
56 | rr, size := utf8.DecodeRune(s[r:]) | ||
57 | if rr == utf8.RuneError && size == 1 { | ||
58 | break | ||
59 | } | ||
60 | r += size | ||
61 | } | ||
62 | if r == len(s) { | ||
63 | return s, true | ||
64 | } | ||
65 | |||
66 | b := make([]byte, len(s)+2*utf8.UTFMax) | ||
67 | w := copy(b, s[0:r]) | ||
68 | for r < len(s) { | ||
69 | // Out of room? Can only happen if s is full of | ||
70 | // malformed UTF-8 and we're replacing each | ||
71 | // byte with RuneError. | ||
72 | if w >= len(b)-2*utf8.UTFMax { | ||
73 | nb := make([]byte, (len(b)+utf8.UTFMax)*2) | ||
74 | copy(nb, b[0:w]) | ||
75 | b = nb | ||
76 | } | ||
77 | switch c := s[r]; { | ||
78 | case c == '\\': | ||
79 | r++ | ||
80 | if r >= len(s) { | ||
81 | return | ||
82 | } | ||
83 | switch s[r] { | ||
84 | default: | ||
85 | return | ||
86 | case '"', '\\', '/', '\'': | ||
87 | b[w] = s[r] | ||
88 | r++ | ||
89 | w++ | ||
90 | case 'b': | ||
91 | b[w] = '\b' | ||
92 | r++ | ||
93 | w++ | ||
94 | case 'f': | ||
95 | b[w] = '\f' | ||
96 | r++ | ||
97 | w++ | ||
98 | case 'n': | ||
99 | b[w] = '\n' | ||
100 | r++ | ||
101 | w++ | ||
102 | case 'r': | ||
103 | b[w] = '\r' | ||
104 | r++ | ||
105 | w++ | ||
106 | case 't': | ||
107 | b[w] = '\t' | ||
108 | r++ | ||
109 | w++ | ||
110 | case 'u': | ||
111 | r-- | ||
112 | rr := getu4(s[r:]) | ||
113 | if rr < 0 { | ||
114 | return | ||
115 | } | ||
116 | r += 6 | ||
117 | if utf16.IsSurrogate(rr) { | ||
118 | rr1 := getu4(s[r:]) | ||
119 | if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { | ||
120 | // A valid pair; consume. | ||
121 | r += 6 | ||
122 | w += utf8.EncodeRune(b[w:], dec) | ||
123 | break | ||
124 | } | ||
125 | // Invalid surrogate; fall back to replacement rune. | ||
126 | rr = unicode.ReplacementChar | ||
127 | } | ||
128 | w += utf8.EncodeRune(b[w:], rr) | ||
129 | } | ||
130 | |||
131 | // Quote, control characters are invalid. | ||
132 | case c == '"', c < ' ': | ||
133 | return | ||
134 | |||
135 | // ASCII | ||
136 | case c < utf8.RuneSelf: | ||
137 | b[w] = c | ||
138 | r++ | ||
139 | w++ | ||
140 | |||
141 | // Coerce to well-formed UTF-8. | ||
142 | default: | ||
143 | rr, size := utf8.DecodeRune(s[r:]) | ||
144 | r += size | ||
145 | w += utf8.EncodeRune(b[w:], rr) | ||
146 | } | ||
147 | } | ||
148 | return b[0:w], true | ||
149 | } | ||
diff --git a/vendor/github.com/prometheus/common/log/eventlog_formatter.go b/vendor/github.com/prometheus/common/log/eventlog_formatter.go deleted file mode 100644 index bcf68e6..0000000 --- a/vendor/github.com/prometheus/common/log/eventlog_formatter.go +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | // Copyright 2015 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | // +build windows | ||
15 | |||
16 | package log | ||
17 | |||
18 | import ( | ||
19 | "fmt" | ||
20 | "os" | ||
21 | |||
22 | "golang.org/x/sys/windows/svc/eventlog" | ||
23 | |||
24 | "github.com/sirupsen/logrus" | ||
25 | ) | ||
26 | |||
27 | func init() { | ||
28 | setEventlogFormatter = func(l logger, name string, debugAsInfo bool) error { | ||
29 | if name == "" { | ||
30 | return fmt.Errorf("missing name parameter") | ||
31 | } | ||
32 | |||
33 | fmter, err := newEventlogger(name, debugAsInfo, l.entry.Logger.Formatter) | ||
34 | if err != nil { | ||
35 | fmt.Fprintf(os.Stderr, "error creating eventlog formatter: %v\n", err) | ||
36 | l.Errorf("can't connect logger to eventlog: %v", err) | ||
37 | return err | ||
38 | } | ||
39 | l.entry.Logger.Formatter = fmter | ||
40 | return nil | ||
41 | } | ||
42 | } | ||
43 | |||
44 | type eventlogger struct { | ||
45 | log *eventlog.Log | ||
46 | debugAsInfo bool | ||
47 | wrap logrus.Formatter | ||
48 | } | ||
49 | |||
50 | func newEventlogger(name string, debugAsInfo bool, fmter logrus.Formatter) (*eventlogger, error) { | ||
51 | logHandle, err := eventlog.Open(name) | ||
52 | if err != nil { | ||
53 | return nil, err | ||
54 | } | ||
55 | return &eventlogger{log: logHandle, debugAsInfo: debugAsInfo, wrap: fmter}, nil | ||
56 | } | ||
57 | |||
58 | func (s *eventlogger) Format(e *logrus.Entry) ([]byte, error) { | ||
59 | data, err := s.wrap.Format(e) | ||
60 | if err != nil { | ||
61 | fmt.Fprintf(os.Stderr, "eventlogger: can't format entry: %v\n", err) | ||
62 | return data, err | ||
63 | } | ||
64 | |||
65 | switch e.Level { | ||
66 | case logrus.PanicLevel: | ||
67 | fallthrough | ||
68 | case logrus.FatalLevel: | ||
69 | fallthrough | ||
70 | case logrus.ErrorLevel: | ||
71 | err = s.log.Error(102, e.Message) | ||
72 | case logrus.WarnLevel: | ||
73 | err = s.log.Warning(101, e.Message) | ||
74 | case logrus.InfoLevel: | ||
75 | err = s.log.Info(100, e.Message) | ||
76 | case logrus.DebugLevel: | ||
77 | if s.debugAsInfo { | ||
78 | err = s.log.Info(100, e.Message) | ||
79 | } | ||
80 | default: | ||
81 | err = s.log.Info(100, e.Message) | ||
82 | } | ||
83 | |||
84 | if err != nil { | ||
85 | fmt.Fprintf(os.Stderr, "eventlogger: can't send log to eventlog: %v\n", err) | ||
86 | } | ||
87 | |||
88 | return data, err | ||
89 | } | ||
diff --git a/vendor/github.com/prometheus/common/log/log.go b/vendor/github.com/prometheus/common/log/log.go deleted file mode 100644 index 1088302..0000000 --- a/vendor/github.com/prometheus/common/log/log.go +++ /dev/null | |||
@@ -1,364 +0,0 @@ | |||
1 | // Copyright 2015 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | package log | ||
15 | |||
16 | import ( | ||
17 | "fmt" | ||
18 | "io" | ||
19 | "io/ioutil" | ||
20 | "log" | ||
21 | "net/url" | ||
22 | "os" | ||
23 | "runtime" | ||
24 | "strconv" | ||
25 | "strings" | ||
26 | |||
27 | "github.com/sirupsen/logrus" | ||
28 | "gopkg.in/alecthomas/kingpin.v2" | ||
29 | ) | ||
30 | |||
31 | // setSyslogFormatter is nil if the target architecture does not support syslog. | ||
32 | var setSyslogFormatter func(logger, string, string) error | ||
33 | |||
34 | // setEventlogFormatter is nil if the target OS does not support Eventlog (i.e., is not Windows). | ||
35 | var setEventlogFormatter func(logger, string, bool) error | ||
36 | |||
37 | func setJSONFormatter() { | ||
38 | origLogger.Formatter = &logrus.JSONFormatter{} | ||
39 | } | ||
40 | |||
41 | type loggerSettings struct { | ||
42 | level string | ||
43 | format string | ||
44 | } | ||
45 | |||
46 | func (s *loggerSettings) apply(ctx *kingpin.ParseContext) error { | ||
47 | err := baseLogger.SetLevel(s.level) | ||
48 | if err != nil { | ||
49 | return err | ||
50 | } | ||
51 | err = baseLogger.SetFormat(s.format) | ||
52 | return err | ||
53 | } | ||
54 | |||
55 | // AddFlags adds the flags used by this package to the Kingpin application. | ||
56 | // To use the default Kingpin application, call AddFlags(kingpin.CommandLine) | ||
57 | func AddFlags(a *kingpin.Application) { | ||
58 | s := loggerSettings{} | ||
59 | a.Flag("log.level", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]"). | ||
60 | Default(origLogger.Level.String()). | ||
61 | StringVar(&s.level) | ||
62 | defaultFormat := url.URL{Scheme: "logger", Opaque: "stderr"} | ||
63 | a.Flag("log.format", `Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"`). | ||
64 | Default(defaultFormat.String()). | ||
65 | StringVar(&s.format) | ||
66 | a.Action(s.apply) | ||
67 | } | ||
68 | |||
69 | // Logger is the interface for loggers used in the Prometheus components. | ||
70 | type Logger interface { | ||
71 | Debug(...interface{}) | ||
72 | Debugln(...interface{}) | ||
73 | Debugf(string, ...interface{}) | ||
74 | |||
75 | Info(...interface{}) | ||
76 | Infoln(...interface{}) | ||
77 | Infof(string, ...interface{}) | ||
78 | |||
79 | Warn(...interface{}) | ||
80 | Warnln(...interface{}) | ||
81 | Warnf(string, ...interface{}) | ||
82 | |||
83 | Error(...interface{}) | ||
84 | Errorln(...interface{}) | ||
85 | Errorf(string, ...interface{}) | ||
86 | |||
87 | Fatal(...interface{}) | ||
88 | Fatalln(...interface{}) | ||
89 | Fatalf(string, ...interface{}) | ||
90 | |||
91 | With(key string, value interface{}) Logger | ||
92 | |||
93 | SetFormat(string) error | ||
94 | SetLevel(string) error | ||
95 | } | ||
96 | |||
97 | type logger struct { | ||
98 | entry *logrus.Entry | ||
99 | } | ||
100 | |||
101 | func (l logger) With(key string, value interface{}) Logger { | ||
102 | return logger{l.entry.WithField(key, value)} | ||
103 | } | ||
104 | |||
105 | // Debug logs a message at level Debug on the standard logger. | ||
106 | func (l logger) Debug(args ...interface{}) { | ||
107 | l.sourced().Debug(args...) | ||
108 | } | ||
109 | |||
110 | // Debug logs a message at level Debug on the standard logger. | ||
111 | func (l logger) Debugln(args ...interface{}) { | ||
112 | l.sourced().Debugln(args...) | ||
113 | } | ||
114 | |||
115 | // Debugf logs a message at level Debug on the standard logger. | ||
116 | func (l logger) Debugf(format string, args ...interface{}) { | ||
117 | l.sourced().Debugf(format, args...) | ||
118 | } | ||
119 | |||
120 | // Info logs a message at level Info on the standard logger. | ||
121 | func (l logger) Info(args ...interface{}) { | ||
122 | l.sourced().Info(args...) | ||
123 | } | ||
124 | |||
125 | // Info logs a message at level Info on the standard logger. | ||
126 | func (l logger) Infoln(args ...interface{}) { | ||
127 | l.sourced().Infoln(args...) | ||
128 | } | ||
129 | |||
130 | // Infof logs a message at level Info on the standard logger. | ||
131 | func (l logger) Infof(format string, args ...interface{}) { | ||
132 | l.sourced().Infof(format, args...) | ||
133 | } | ||
134 | |||
135 | // Warn logs a message at level Warn on the standard logger. | ||
136 | func (l logger) Warn(args ...interface{}) { | ||
137 | l.sourced().Warn(args...) | ||
138 | } | ||
139 | |||
140 | // Warn logs a message at level Warn on the standard logger. | ||
141 | func (l logger) Warnln(args ...interface{}) { | ||
142 | l.sourced().Warnln(args...) | ||
143 | } | ||
144 | |||
145 | // Warnf logs a message at level Warn on the standard logger. | ||
146 | func (l logger) Warnf(format string, args ...interface{}) { | ||
147 | l.sourced().Warnf(format, args...) | ||
148 | } | ||
149 | |||
150 | // Error logs a message at level Error on the standard logger. | ||
151 | func (l logger) Error(args ...interface{}) { | ||
152 | l.sourced().Error(args...) | ||
153 | } | ||
154 | |||
155 | // Error logs a message at level Error on the standard logger. | ||
156 | func (l logger) Errorln(args ...interface{}) { | ||
157 | l.sourced().Errorln(args...) | ||
158 | } | ||
159 | |||
160 | // Errorf logs a message at level Error on the standard logger. | ||
161 | func (l logger) Errorf(format string, args ...interface{}) { | ||
162 | l.sourced().Errorf(format, args...) | ||
163 | } | ||
164 | |||
165 | // Fatal logs a message at level Fatal on the standard logger. | ||
166 | func (l logger) Fatal(args ...interface{}) { | ||
167 | l.sourced().Fatal(args...) | ||
168 | } | ||
169 | |||
170 | // Fatal logs a message at level Fatal on the standard logger. | ||
171 | func (l logger) Fatalln(args ...interface{}) { | ||
172 | l.sourced().Fatalln(args...) | ||
173 | } | ||
174 | |||
175 | // Fatalf logs a message at level Fatal on the standard logger. | ||
176 | func (l logger) Fatalf(format string, args ...interface{}) { | ||
177 | l.sourced().Fatalf(format, args...) | ||
178 | } | ||
179 | |||
180 | func (l logger) SetLevel(level string) error { | ||
181 | lvl, err := logrus.ParseLevel(level) | ||
182 | if err != nil { | ||
183 | return err | ||
184 | } | ||
185 | |||
186 | l.entry.Logger.Level = lvl | ||
187 | return nil | ||
188 | } | ||
189 | |||
190 | func (l logger) SetFormat(format string) error { | ||
191 | u, err := url.Parse(format) | ||
192 | if err != nil { | ||
193 | return err | ||
194 | } | ||
195 | if u.Scheme != "logger" { | ||
196 | return fmt.Errorf("invalid scheme %s", u.Scheme) | ||
197 | } | ||
198 | jsonq := u.Query().Get("json") | ||
199 | if jsonq == "true" { | ||
200 | setJSONFormatter() | ||
201 | } | ||
202 | |||
203 | switch u.Opaque { | ||
204 | case "syslog": | ||
205 | if setSyslogFormatter == nil { | ||
206 | return fmt.Errorf("system does not support syslog") | ||
207 | } | ||
208 | appname := u.Query().Get("appname") | ||
209 | facility := u.Query().Get("local") | ||
210 | return setSyslogFormatter(l, appname, facility) | ||
211 | case "eventlog": | ||
212 | if setEventlogFormatter == nil { | ||
213 | return fmt.Errorf("system does not support eventlog") | ||
214 | } | ||
215 | name := u.Query().Get("name") | ||
216 | debugAsInfo := false | ||
217 | debugAsInfoRaw := u.Query().Get("debugAsInfo") | ||
218 | if parsedDebugAsInfo, err := strconv.ParseBool(debugAsInfoRaw); err == nil { | ||
219 | debugAsInfo = parsedDebugAsInfo | ||
220 | } | ||
221 | return setEventlogFormatter(l, name, debugAsInfo) | ||
222 | case "stdout": | ||
223 | l.entry.Logger.Out = os.Stdout | ||
224 | case "stderr": | ||
225 | l.entry.Logger.Out = os.Stderr | ||
226 | default: | ||
227 | return fmt.Errorf("unsupported logger %q", u.Opaque) | ||
228 | } | ||
229 | return nil | ||
230 | } | ||
231 | |||
232 | // sourced adds a source field to the logger that contains | ||
233 | // the file name and line where the logging happened. | ||
234 | func (l logger) sourced() *logrus.Entry { | ||
235 | _, file, line, ok := runtime.Caller(2) | ||
236 | if !ok { | ||
237 | file = "<???>" | ||
238 | line = 1 | ||
239 | } else { | ||
240 | slash := strings.LastIndex(file, "/") | ||
241 | file = file[slash+1:] | ||
242 | } | ||
243 | return l.entry.WithField("source", fmt.Sprintf("%s:%d", file, line)) | ||
244 | } | ||
245 | |||
246 | var origLogger = logrus.New() | ||
247 | var baseLogger = logger{entry: logrus.NewEntry(origLogger)} | ||
248 | |||
249 | // Base returns the default Logger logging to | ||
250 | func Base() Logger { | ||
251 | return baseLogger | ||
252 | } | ||
253 | |||
254 | // NewLogger returns a new Logger logging to out. | ||
255 | func NewLogger(w io.Writer) Logger { | ||
256 | l := logrus.New() | ||
257 | l.Out = w | ||
258 | return logger{entry: logrus.NewEntry(l)} | ||
259 | } | ||
260 | |||
261 | // NewNopLogger returns a logger that discards all log messages. | ||
262 | func NewNopLogger() Logger { | ||
263 | l := logrus.New() | ||
264 | l.Out = ioutil.Discard | ||
265 | return logger{entry: logrus.NewEntry(l)} | ||
266 | } | ||
267 | |||
268 | // With adds a field to the logger. | ||
269 | func With(key string, value interface{}) Logger { | ||
270 | return baseLogger.With(key, value) | ||
271 | } | ||
272 | |||
273 | // Debug logs a message at level Debug on the standard logger. | ||
274 | func Debug(args ...interface{}) { | ||
275 | baseLogger.sourced().Debug(args...) | ||
276 | } | ||
277 | |||
278 | // Debugln logs a message at level Debug on the standard logger. | ||
279 | func Debugln(args ...interface{}) { | ||
280 | baseLogger.sourced().Debugln(args...) | ||
281 | } | ||
282 | |||
283 | // Debugf logs a message at level Debug on the standard logger. | ||
284 | func Debugf(format string, args ...interface{}) { | ||
285 | baseLogger.sourced().Debugf(format, args...) | ||
286 | } | ||
287 | |||
288 | // Info logs a message at level Info on the standard logger. | ||
289 | func Info(args ...interface{}) { | ||
290 | baseLogger.sourced().Info(args...) | ||
291 | } | ||
292 | |||
293 | // Infoln logs a message at level Info on the standard logger. | ||
294 | func Infoln(args ...interface{}) { | ||
295 | baseLogger.sourced().Infoln(args...) | ||
296 | } | ||
297 | |||
298 | // Infof logs a message at level Info on the standard logger. | ||
299 | func Infof(format string, args ...interface{}) { | ||
300 | baseLogger.sourced().Infof(format, args...) | ||
301 | } | ||
302 | |||
303 | // Warn logs a message at level Warn on the standard logger. | ||
304 | func Warn(args ...interface{}) { | ||
305 | baseLogger.sourced().Warn(args...) | ||
306 | } | ||
307 | |||
308 | // Warnln logs a message at level Warn on the standard logger. | ||
309 | func Warnln(args ...interface{}) { | ||
310 | baseLogger.sourced().Warnln(args...) | ||
311 | } | ||
312 | |||
313 | // Warnf logs a message at level Warn on the standard logger. | ||
314 | func Warnf(format string, args ...interface{}) { | ||
315 | baseLogger.sourced().Warnf(format, args...) | ||
316 | } | ||
317 | |||
318 | // Error logs a message at level Error on the standard logger. | ||
319 | func Error(args ...interface{}) { | ||
320 | baseLogger.sourced().Error(args...) | ||
321 | } | ||
322 | |||
323 | // Errorln logs a message at level Error on the standard logger. | ||
324 | func Errorln(args ...interface{}) { | ||
325 | baseLogger.sourced().Errorln(args...) | ||
326 | } | ||
327 | |||
328 | // Errorf logs a message at level Error on the standard logger. | ||
329 | func Errorf(format string, args ...interface{}) { | ||
330 | baseLogger.sourced().Errorf(format, args...) | ||
331 | } | ||
332 | |||
333 | // Fatal logs a message at level Fatal on the standard logger. | ||
334 | func Fatal(args ...interface{}) { | ||
335 | baseLogger.sourced().Fatal(args...) | ||
336 | } | ||
337 | |||
338 | // Fatalln logs a message at level Fatal on the standard logger. | ||
339 | func Fatalln(args ...interface{}) { | ||
340 | baseLogger.sourced().Fatalln(args...) | ||
341 | } | ||
342 | |||
343 | // Fatalf logs a message at level Fatal on the standard logger. | ||
344 | func Fatalf(format string, args ...interface{}) { | ||
345 | baseLogger.sourced().Fatalf(format, args...) | ||
346 | } | ||
347 | |||
348 | // AddHook adds hook to Prometheus' original logger. | ||
349 | func AddHook(hook logrus.Hook) { | ||
350 | origLogger.Hooks.Add(hook) | ||
351 | } | ||
352 | |||
353 | type errorLogWriter struct{} | ||
354 | |||
355 | func (errorLogWriter) Write(b []byte) (int, error) { | ||
356 | baseLogger.sourced().Error(string(b)) | ||
357 | return len(b), nil | ||
358 | } | ||
359 | |||
360 | // NewErrorLogger returns a log.Logger that is meant to be used | ||
361 | // in the ErrorLog field of an http.Server to log HTTP server errors. | ||
362 | func NewErrorLogger() *log.Logger { | ||
363 | return log.New(&errorLogWriter{}, "", 0) | ||
364 | } | ||
diff --git a/vendor/github.com/prometheus/common/log/syslog_formatter.go b/vendor/github.com/prometheus/common/log/syslog_formatter.go deleted file mode 100644 index f882f2f..0000000 --- a/vendor/github.com/prometheus/common/log/syslog_formatter.go +++ /dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | // Copyright 2015 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | // +build !windows,!nacl,!plan9 | ||
15 | |||
16 | package log | ||
17 | |||
18 | import ( | ||
19 | "fmt" | ||
20 | "log/syslog" | ||
21 | "os" | ||
22 | |||
23 | "github.com/sirupsen/logrus" | ||
24 | ) | ||
25 | |||
26 | var _ logrus.Formatter = (*syslogger)(nil) | ||
27 | |||
28 | func init() { | ||
29 | setSyslogFormatter = func(l logger, appname, local string) error { | ||
30 | if appname == "" { | ||
31 | return fmt.Errorf("missing appname parameter") | ||
32 | } | ||
33 | if local == "" { | ||
34 | return fmt.Errorf("missing local parameter") | ||
35 | } | ||
36 | |||
37 | fmter, err := newSyslogger(appname, local, l.entry.Logger.Formatter) | ||
38 | if err != nil { | ||
39 | fmt.Fprintf(os.Stderr, "error creating syslog formatter: %v\n", err) | ||
40 | l.entry.Errorf("can't connect logger to syslog: %v", err) | ||
41 | return err | ||
42 | } | ||
43 | l.entry.Logger.Formatter = fmter | ||
44 | return nil | ||
45 | } | ||
46 | } | ||
47 | |||
48 | var prefixTag []byte | ||
49 | |||
50 | type syslogger struct { | ||
51 | wrap logrus.Formatter | ||
52 | out *syslog.Writer | ||
53 | } | ||
54 | |||
55 | func newSyslogger(appname string, facility string, fmter logrus.Formatter) (*syslogger, error) { | ||
56 | priority, err := getFacility(facility) | ||
57 | if err != nil { | ||
58 | return nil, err | ||
59 | } | ||
60 | out, err := syslog.New(priority, appname) | ||
61 | _, isJSON := fmter.(*logrus.JSONFormatter) | ||
62 | if isJSON { | ||
63 | // add cee tag to json formatted syslogs | ||
64 | prefixTag = []byte("@cee:") | ||
65 | } | ||
66 | return &syslogger{ | ||
67 | out: out, | ||
68 | wrap: fmter, | ||
69 | }, err | ||
70 | } | ||
71 | |||
72 | func getFacility(facility string) (syslog.Priority, error) { | ||
73 | switch facility { | ||
74 | case "0": | ||
75 | return syslog.LOG_LOCAL0, nil | ||
76 | case "1": | ||
77 | return syslog.LOG_LOCAL1, nil | ||
78 | case "2": | ||
79 | return syslog.LOG_LOCAL2, nil | ||
80 | case "3": | ||
81 | return syslog.LOG_LOCAL3, nil | ||
82 | case "4": | ||
83 | return syslog.LOG_LOCAL4, nil | ||
84 | case "5": | ||
85 | return syslog.LOG_LOCAL5, nil | ||
86 | case "6": | ||
87 | return syslog.LOG_LOCAL6, nil | ||
88 | case "7": | ||
89 | return syslog.LOG_LOCAL7, nil | ||
90 | } | ||
91 | return syslog.LOG_LOCAL0, fmt.Errorf("invalid local(%s) for syslog", facility) | ||
92 | } | ||
93 | |||
94 | func (s *syslogger) Format(e *logrus.Entry) ([]byte, error) { | ||
95 | data, err := s.wrap.Format(e) | ||
96 | if err != nil { | ||
97 | fmt.Fprintf(os.Stderr, "syslogger: can't format entry: %v\n", err) | ||
98 | return data, err | ||
99 | } | ||
100 | // only append tag to data sent to syslog (line), not to what | ||
101 | // is returned | ||
102 | line := string(append(prefixTag, data...)) | ||
103 | |||
104 | switch e.Level { | ||
105 | case logrus.PanicLevel: | ||
106 | err = s.out.Crit(line) | ||
107 | case logrus.FatalLevel: | ||
108 | err = s.out.Crit(line) | ||
109 | case logrus.ErrorLevel: | ||
110 | err = s.out.Err(line) | ||
111 | case logrus.WarnLevel: | ||
112 | err = s.out.Warning(line) | ||
113 | case logrus.InfoLevel: | ||
114 | err = s.out.Info(line) | ||
115 | case logrus.DebugLevel: | ||
116 | err = s.out.Debug(line) | ||
117 | default: | ||
118 | err = s.out.Notice(line) | ||
119 | } | ||
120 | |||
121 | if err != nil { | ||
122 | fmt.Fprintf(os.Stderr, "syslogger: can't send log to syslog: %v\n", err) | ||
123 | } | ||
124 | |||
125 | return data, err | ||
126 | } | ||
diff --git a/vendor/github.com/prometheus/common/promlog/flag/flag.go b/vendor/github.com/prometheus/common/promlog/flag/flag.go new file mode 100644 index 0000000..ec55008 --- /dev/null +++ b/vendor/github.com/prometheus/common/promlog/flag/flag.go | |||
@@ -0,0 +1,45 @@ | |||
1 | // Copyright 2017 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | package flag | ||
15 | |||
16 | import ( | ||
17 | "github.com/prometheus/common/promlog" | ||
18 | kingpin "gopkg.in/alecthomas/kingpin.v2" | ||
19 | ) | ||
20 | |||
21 | // LevelFlagName is the canonical flag name to configure the allowed log level | ||
22 | // within Prometheus projects. | ||
23 | const LevelFlagName = "log.level" | ||
24 | |||
25 | // LevelFlagHelp is the help description for the log.level flag. | ||
26 | const LevelFlagHelp = "Only log messages with the given severity or above. One of: [debug, info, warn, error]" | ||
27 | |||
28 | // FormatFlagName is the canonical flag name to configure the log format | ||
29 | // within Prometheus projects. | ||
30 | const FormatFlagName = "log.format" | ||
31 | |||
32 | // FormatFlagHelp is the help description for the log.format flag. | ||
33 | const FormatFlagHelp = "Output format of log messages. One of: [logfmt, json]" | ||
34 | |||
35 | // AddFlags adds the flags used by this package to the Kingpin application. | ||
36 | // To use the default Kingpin application, call AddFlags(kingpin.CommandLine) | ||
37 | func AddFlags(a *kingpin.Application, config *promlog.Config) { | ||
38 | config.Level = &promlog.AllowedLevel{} | ||
39 | a.Flag(LevelFlagName, LevelFlagHelp). | ||
40 | Default("info").SetValue(config.Level) | ||
41 | |||
42 | config.Format = &promlog.AllowedFormat{} | ||
43 | a.Flag(FormatFlagName, FormatFlagHelp). | ||
44 | Default("logfmt").SetValue(config.Format) | ||
45 | } | ||
diff --git a/vendor/github.com/prometheus/common/promlog/log.go b/vendor/github.com/prometheus/common/promlog/log.go new file mode 100644 index 0000000..45fcbc4 --- /dev/null +++ b/vendor/github.com/prometheus/common/promlog/log.go | |||
@@ -0,0 +1,106 @@ | |||
1 | // Copyright 2017 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | // Package promlog defines standardised ways to initialize Go kit loggers | ||
15 | // across Prometheus components. | ||
16 | // It should typically only ever be imported by main packages. | ||
17 | package promlog | ||
18 | |||
19 | import ( | ||
20 | "os" | ||
21 | "time" | ||
22 | |||
23 | "github.com/go-kit/kit/log" | ||
24 | "github.com/go-kit/kit/log/level" | ||
25 | "github.com/pkg/errors" | ||
26 | ) | ||
27 | |||
28 | var ( | ||
29 | // This timestamp format differs from RFC3339Nano by using .000 instead | ||
30 | // of .999999999 which changes the timestamp from 9 variable to 3 fixed | ||
31 | // decimals (.130 instead of .130987456). | ||
32 | timestampFormat = log.TimestampFormat( | ||
33 | func() time.Time { return time.Now().UTC() }, | ||
34 | "2006-01-02T15:04:05.000Z07:00", | ||
35 | ) | ||
36 | ) | ||
37 | |||
38 | // AllowedLevel is a settable identifier for the minimum level a log entry | ||
39 | // must be have. | ||
40 | type AllowedLevel struct { | ||
41 | s string | ||
42 | o level.Option | ||
43 | } | ||
44 | |||
45 | func (l *AllowedLevel) String() string { | ||
46 | return l.s | ||
47 | } | ||
48 | |||
49 | // Set updates the value of the allowed level. | ||
50 | func (l *AllowedLevel) Set(s string) error { | ||
51 | switch s { | ||
52 | case "debug": | ||
53 | l.o = level.AllowDebug() | ||
54 | case "info": | ||
55 | l.o = level.AllowInfo() | ||
56 | case "warn": | ||
57 | l.o = level.AllowWarn() | ||
58 | case "error": | ||
59 | l.o = level.AllowError() | ||
60 | default: | ||
61 | return errors.Errorf("unrecognized log level %q", s) | ||
62 | } | ||
63 | l.s = s | ||
64 | return nil | ||
65 | } | ||
66 | |||
67 | // AllowedFormat is a settable identifier for the output format that the logger can have. | ||
68 | type AllowedFormat struct { | ||
69 | s string | ||
70 | } | ||
71 | |||
72 | func (f *AllowedFormat) String() string { | ||
73 | return f.s | ||
74 | } | ||
75 | |||
76 | // Set updates the value of the allowed format. | ||
77 | func (f *AllowedFormat) Set(s string) error { | ||
78 | switch s { | ||
79 | case "logfmt", "json": | ||
80 | f.s = s | ||
81 | default: | ||
82 | return errors.Errorf("unrecognized log format %q", s) | ||
83 | } | ||
84 | return nil | ||
85 | } | ||
86 | |||
87 | // Config is a struct containing configurable settings for the logger | ||
88 | type Config struct { | ||
89 | Level *AllowedLevel | ||
90 | Format *AllowedFormat | ||
91 | } | ||
92 | |||
93 | // New returns a new leveled oklog logger. Each logged line will be annotated | ||
94 | // with a timestamp. The output always goes to stderr. | ||
95 | func New(config *Config) log.Logger { | ||
96 | var l log.Logger | ||
97 | if config.Format.s == "logfmt" { | ||
98 | l = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) | ||
99 | } else { | ||
100 | l = log.NewJSONLogger(log.NewSyncWriter(os.Stderr)) | ||
101 | } | ||
102 | |||
103 | l = level.NewFilter(l, config.Level.o) | ||
104 | l = log.With(l, "ts", timestampFormat, "caller", log.DefaultCaller) | ||
105 | return l | ||
106 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/.gitignore b/vendor/github.com/sirupsen/logrus/.gitignore deleted file mode 100644 index 6b7d7d1..0000000 --- a/vendor/github.com/sirupsen/logrus/.gitignore +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | logrus | ||
2 | vendor | ||
diff --git a/vendor/github.com/sirupsen/logrus/.travis.yml b/vendor/github.com/sirupsen/logrus/.travis.yml deleted file mode 100644 index 848938a..0000000 --- a/vendor/github.com/sirupsen/logrus/.travis.yml +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | language: go | ||
2 | go_import_path: github.com/sirupsen/logrus | ||
3 | git: | ||
4 | depth: 1 | ||
5 | env: | ||
6 | - GO111MODULE=on | ||
7 | - GO111MODULE=off | ||
8 | go: [ 1.11.x, 1.12.x ] | ||
9 | os: [ linux, osx ] | ||
10 | matrix: | ||
11 | exclude: | ||
12 | - go: 1.12.x | ||
13 | env: GO111MODULE=off | ||
14 | - go: 1.11.x | ||
15 | os: osx | ||
16 | install: | ||
17 | - ./travis/install.sh | ||
18 | - if [[ "$GO111MODULE" == "on" ]]; then go mod download; fi | ||
19 | - if [[ "$GO111MODULE" == "off" ]]; then go get github.com/stretchr/testify/assert golang.org/x/sys/unix github.com/konsorten/go-windows-terminal-sequences; fi | ||
20 | script: | ||
21 | - ./travis/cross_build.sh | ||
22 | - export GOMAXPROCS=4 | ||
23 | - export GORACE=halt_on_error=1 | ||
24 | - go test -race -v ./... | ||
25 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then go test -race -v -tags appengine ./... ; fi | ||
diff --git a/vendor/github.com/sirupsen/logrus/CHANGELOG.md b/vendor/github.com/sirupsen/logrus/CHANGELOG.md deleted file mode 100644 index 51a7ab0..0000000 --- a/vendor/github.com/sirupsen/logrus/CHANGELOG.md +++ /dev/null | |||
@@ -1,200 +0,0 @@ | |||
1 | # 1.4.2 | ||
2 | * Fixes build break for plan9, nacl, solaris | ||
3 | # 1.4.1 | ||
4 | This new release introduces: | ||
5 | * Enhance TextFormatter to not print caller information when they are empty (#944) | ||
6 | * Remove dependency on golang.org/x/crypto (#932, #943) | ||
7 | |||
8 | Fixes: | ||
9 | * Fix Entry.WithContext method to return a copy of the initial entry (#941) | ||
10 | |||
11 | # 1.4.0 | ||
12 | This new release introduces: | ||
13 | * Add `DeferExitHandler`, similar to `RegisterExitHandler` but prepending the handler to the list of handlers (semantically like `defer`) (#848). | ||
14 | * Add `CallerPrettyfier` to `JSONFormatter` and `TextFormatter (#909, #911) | ||
15 | * Add `Entry.WithContext()` and `Entry.Context`, to set a context on entries to be used e.g. in hooks (#919). | ||
16 | |||
17 | Fixes: | ||
18 | * Fix wrong method calls `Logger.Print` and `Logger.Warningln` (#893). | ||
19 | * Update `Entry.Logf` to not do string formatting unless the log level is enabled (#903) | ||
20 | * Fix infinite recursion on unknown `Level.String()` (#907) | ||
21 | * Fix race condition in `getCaller` (#916). | ||
22 | |||
23 | |||
24 | # 1.3.0 | ||
25 | This new release introduces: | ||
26 | * Log, Logf, Logln functions for Logger and Entry that take a Level | ||
27 | |||
28 | Fixes: | ||
29 | * Building prometheus node_exporter on AIX (#840) | ||
30 | * Race condition in TextFormatter (#468) | ||
31 | * Travis CI import path (#868) | ||
32 | * Remove coloured output on Windows (#862) | ||
33 | * Pointer to func as field in JSONFormatter (#870) | ||
34 | * Properly marshal Levels (#873) | ||
35 | |||
36 | # 1.2.0 | ||
37 | This new release introduces: | ||
38 | * A new method `SetReportCaller` in the `Logger` to enable the file, line and calling function from which the trace has been issued | ||
39 | * A new trace level named `Trace` whose level is below `Debug` | ||
40 | * A configurable exit function to be called upon a Fatal trace | ||
41 | * The `Level` object now implements `encoding.TextUnmarshaler` interface | ||
42 | |||
43 | # 1.1.1 | ||
44 | This is a bug fix release. | ||
45 | * fix the build break on Solaris | ||
46 | * don't drop a whole trace in JSONFormatter when a field param is a function pointer which can not be serialized | ||
47 | |||
48 | # 1.1.0 | ||
49 | This new release introduces: | ||
50 | * several fixes: | ||
51 | * a fix for a race condition on entry formatting | ||
52 | * proper cleanup of previously used entries before putting them back in the pool | ||
53 | * the extra new line at the end of message in text formatter has been removed | ||
54 | * a new global public API to check if a level is activated: IsLevelEnabled | ||
55 | * the following methods have been added to the Logger object | ||
56 | * IsLevelEnabled | ||
57 | * SetFormatter | ||
58 | * SetOutput | ||
59 | * ReplaceHooks | ||
60 | * introduction of go module | ||
61 | * an indent configuration for the json formatter | ||
62 | * output colour support for windows | ||
63 | * the field sort function is now configurable for text formatter | ||
64 | * the CLICOLOR and CLICOLOR\_FORCE environment variable support in text formater | ||
65 | |||
66 | # 1.0.6 | ||
67 | |||
68 | This new release introduces: | ||
69 | * a new api WithTime which allows to easily force the time of the log entry | ||
70 | which is mostly useful for logger wrapper | ||
71 | * a fix reverting the immutability of the entry given as parameter to the hooks | ||
72 | a new configuration field of the json formatter in order to put all the fields | ||
73 | in a nested dictionnary | ||
74 | * a new SetOutput method in the Logger | ||
75 | * a new configuration of the textformatter to configure the name of the default keys | ||
76 | * a new configuration of the text formatter to disable the level truncation | ||
77 | |||
78 | # 1.0.5 | ||
79 | |||
80 | * Fix hooks race (#707) | ||
81 | * Fix panic deadlock (#695) | ||
82 | |||
83 | # 1.0.4 | ||
84 | |||
85 | * Fix race when adding hooks (#612) | ||
86 | * Fix terminal check in AppEngine (#635) | ||
87 | |||
88 | # 1.0.3 | ||
89 | |||
90 | * Replace example files with testable examples | ||
91 | |||
92 | # 1.0.2 | ||
93 | |||
94 | * bug: quote non-string values in text formatter (#583) | ||
95 | * Make (*Logger) SetLevel a public method | ||
96 | |||
97 | # 1.0.1 | ||
98 | |||
99 | * bug: fix escaping in text formatter (#575) | ||
100 | |||
101 | # 1.0.0 | ||
102 | |||
103 | * Officially changed name to lower-case | ||
104 | * bug: colors on Windows 10 (#541) | ||
105 | * bug: fix race in accessing level (#512) | ||
106 | |||
107 | # 0.11.5 | ||
108 | |||
109 | * feature: add writer and writerlevel to entry (#372) | ||
110 | |||
111 | # 0.11.4 | ||
112 | |||
113 | * bug: fix undefined variable on solaris (#493) | ||
114 | |||
115 | # 0.11.3 | ||
116 | |||
117 | * formatter: configure quoting of empty values (#484) | ||
118 | * formatter: configure quoting character (default is `"`) (#484) | ||
119 | * bug: fix not importing io correctly in non-linux environments (#481) | ||
120 | |||
121 | # 0.11.2 | ||
122 | |||
123 | * bug: fix windows terminal detection (#476) | ||
124 | |||
125 | # 0.11.1 | ||
126 | |||
127 | * bug: fix tty detection with custom out (#471) | ||
128 | |||
129 | # 0.11.0 | ||
130 | |||
131 | * performance: Use bufferpool to allocate (#370) | ||
132 | * terminal: terminal detection for app-engine (#343) | ||
133 | * feature: exit handler (#375) | ||
134 | |||
135 | # 0.10.0 | ||
136 | |||
137 | * feature: Add a test hook (#180) | ||
138 | * feature: `ParseLevel` is now case-insensitive (#326) | ||
139 | * feature: `FieldLogger` interface that generalizes `Logger` and `Entry` (#308) | ||
140 | * performance: avoid re-allocations on `WithFields` (#335) | ||
141 | |||
142 | # 0.9.0 | ||
143 | |||
144 | * logrus/text_formatter: don't emit empty msg | ||
145 | * logrus/hooks/airbrake: move out of main repository | ||
146 | * logrus/hooks/sentry: move out of main repository | ||
147 | * logrus/hooks/papertrail: move out of main repository | ||
148 | * logrus/hooks/bugsnag: move out of main repository | ||
149 | * logrus/core: run tests with `-race` | ||
150 | * logrus/core: detect TTY based on `stderr` | ||
151 | * logrus/core: support `WithError` on logger | ||
152 | * logrus/core: Solaris support | ||
153 | |||
154 | # 0.8.7 | ||
155 | |||
156 | * logrus/core: fix possible race (#216) | ||
157 | * logrus/doc: small typo fixes and doc improvements | ||
158 | |||
159 | |||
160 | # 0.8.6 | ||
161 | |||
162 | * hooks/raven: allow passing an initialized client | ||
163 | |||
164 | # 0.8.5 | ||
165 | |||
166 | * logrus/core: revert #208 | ||
167 | |||
168 | # 0.8.4 | ||
169 | |||
170 | * formatter/text: fix data race (#218) | ||
171 | |||
172 | # 0.8.3 | ||
173 | |||
174 | * logrus/core: fix entry log level (#208) | ||
175 | * logrus/core: improve performance of text formatter by 40% | ||
176 | * logrus/core: expose `LevelHooks` type | ||
177 | * logrus/core: add support for DragonflyBSD and NetBSD | ||
178 | * formatter/text: print structs more verbosely | ||
179 | |||
180 | # 0.8.2 | ||
181 | |||
182 | * logrus: fix more Fatal family functions | ||
183 | |||
184 | # 0.8.1 | ||
185 | |||
186 | * logrus: fix not exiting on `Fatalf` and `Fatalln` | ||
187 | |||
188 | # 0.8.0 | ||
189 | |||
190 | * logrus: defaults to stderr instead of stdout | ||
191 | * hooks/sentry: add special field for `*http.Request` | ||
192 | * formatter/text: ignore Windows for colors | ||
193 | |||
194 | # 0.7.3 | ||
195 | |||
196 | * formatter/\*: allow configuration of timestamp layout | ||
197 | |||
198 | # 0.7.2 | ||
199 | |||
200 | * formatter/text: Add configuration option for time format (#158) | ||
diff --git a/vendor/github.com/sirupsen/logrus/README.md b/vendor/github.com/sirupsen/logrus/README.md deleted file mode 100644 index a4796eb..0000000 --- a/vendor/github.com/sirupsen/logrus/README.md +++ /dev/null | |||
@@ -1,495 +0,0 @@ | |||
1 | # Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus) | ||
2 | |||
3 | Logrus is a structured logger for Go (golang), completely API compatible with | ||
4 | the standard library logger. | ||
5 | |||
6 | **Seeing weird case-sensitive problems?** It's in the past been possible to | ||
7 | import Logrus as both upper- and lower-case. Due to the Go package environment, | ||
8 | this caused issues in the community and we needed a standard. Some environments | ||
9 | experienced problems with the upper-case variant, so the lower-case was decided. | ||
10 | Everything using `logrus` will need to use the lower-case: | ||
11 | `github.com/sirupsen/logrus`. Any package that isn't, should be changed. | ||
12 | |||
13 | To fix Glide, see [these | ||
14 | comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437). | ||
15 | For an in-depth explanation of the casing issue, see [this | ||
16 | comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276). | ||
17 | |||
18 | **Are you interested in assisting in maintaining Logrus?** Currently I have a | ||
19 | lot of obligations, and I am unable to provide Logrus with the maintainership it | ||
20 | needs. If you'd like to help, please reach out to me at `simon at author's | ||
21 | username dot com`. | ||
22 | |||
23 | Nicely color-coded in development (when a TTY is attached, otherwise just | ||
24 | plain text): | ||
25 | |||
26 | ![Colored](http://i.imgur.com/PY7qMwd.png) | ||
27 | |||
28 | With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash | ||
29 | or Splunk: | ||
30 | |||
31 | ```json | ||
32 | {"animal":"walrus","level":"info","msg":"A group of walrus emerges from the | ||
33 | ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"} | ||
34 | |||
35 | {"level":"warning","msg":"The group's number increased tremendously!", | ||
36 | "number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"} | ||
37 | |||
38 | {"animal":"walrus","level":"info","msg":"A giant walrus appears!", | ||
39 | "size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"} | ||
40 | |||
41 | {"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.", | ||
42 | "size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"} | ||
43 | |||
44 | {"level":"fatal","msg":"The ice breaks!","number":100,"omg":true, | ||
45 | "time":"2014-03-10 19:57:38.562543128 -0400 EDT"} | ||
46 | ``` | ||
47 | |||
48 | With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not | ||
49 | attached, the output is compatible with the | ||
50 | [logfmt](http://godoc.org/github.com/kr/logfmt) format: | ||
51 | |||
52 | ```text | ||
53 | time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8 | ||
54 | time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10 | ||
55 | time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true | ||
56 | time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4 | ||
57 | time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009 | ||
58 | time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true | ||
59 | ``` | ||
60 | To ensure this behaviour even if a TTY is attached, set your formatter as follows: | ||
61 | |||
62 | ```go | ||
63 | log.SetFormatter(&log.TextFormatter{ | ||
64 | DisableColors: true, | ||
65 | FullTimestamp: true, | ||
66 | }) | ||
67 | ``` | ||
68 | |||
69 | #### Logging Method Name | ||
70 | |||
71 | If you wish to add the calling method as a field, instruct the logger via: | ||
72 | ```go | ||
73 | log.SetReportCaller(true) | ||
74 | ``` | ||
75 | This adds the caller as 'method' like so: | ||
76 | |||
77 | ```json | ||
78 | {"animal":"penguin","level":"fatal","method":"github.com/sirupsen/arcticcreatures.migrate","msg":"a penguin swims by", | ||
79 | "time":"2014-03-10 19:57:38.562543129 -0400 EDT"} | ||
80 | ``` | ||
81 | |||
82 | ```text | ||
83 | time="2015-03-26T01:27:38-04:00" level=fatal method=github.com/sirupsen/arcticcreatures.migrate msg="a penguin swims by" animal=penguin | ||
84 | ``` | ||
85 | Note that this does add measurable overhead - the cost will depend on the version of Go, but is | ||
86 | between 20 and 40% in recent tests with 1.6 and 1.7. You can validate this in your | ||
87 | environment via benchmarks: | ||
88 | ``` | ||
89 | go test -bench=.*CallerTracing | ||
90 | ``` | ||
91 | |||
92 | |||
93 | #### Case-sensitivity | ||
94 | |||
95 | The organization's name was changed to lower-case--and this will not be changed | ||
96 | back. If you are getting import conflicts due to case sensitivity, please use | ||
97 | the lower-case import: `github.com/sirupsen/logrus`. | ||
98 | |||
99 | #### Example | ||
100 | |||
101 | The simplest way to use Logrus is simply the package-level exported logger: | ||
102 | |||
103 | ```go | ||
104 | package main | ||
105 | |||
106 | import ( | ||
107 | log "github.com/sirupsen/logrus" | ||
108 | ) | ||
109 | |||
110 | func main() { | ||
111 | log.WithFields(log.Fields{ | ||
112 | "animal": "walrus", | ||
113 | }).Info("A walrus appears") | ||
114 | } | ||
115 | ``` | ||
116 | |||
117 | Note that it's completely api-compatible with the stdlib logger, so you can | ||
118 | replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"` | ||
119 | and you'll now have the flexibility of Logrus. You can customize it all you | ||
120 | want: | ||
121 | |||
122 | ```go | ||
123 | package main | ||
124 | |||
125 | import ( | ||
126 | "os" | ||
127 | log "github.com/sirupsen/logrus" | ||
128 | ) | ||
129 | |||
130 | func init() { | ||
131 | // Log as JSON instead of the default ASCII formatter. | ||
132 | log.SetFormatter(&log.JSONFormatter{}) | ||
133 | |||
134 | // Output to stdout instead of the default stderr | ||
135 | // Can be any io.Writer, see below for File example | ||
136 | log.SetOutput(os.Stdout) | ||
137 | |||
138 | // Only log the warning severity or above. | ||
139 | log.SetLevel(log.WarnLevel) | ||
140 | } | ||
141 | |||
142 | func main() { | ||
143 | log.WithFields(log.Fields{ | ||
144 | "animal": "walrus", | ||
145 | "size": 10, | ||
146 | }).Info("A group of walrus emerges from the ocean") | ||
147 | |||
148 | log.WithFields(log.Fields{ | ||
149 | "omg": true, | ||
150 | "number": 122, | ||
151 | }).Warn("The group's number increased tremendously!") | ||
152 | |||
153 | log.WithFields(log.Fields{ | ||
154 | "omg": true, | ||
155 | "number": 100, | ||
156 | }).Fatal("The ice breaks!") | ||
157 | |||
158 | // A common pattern is to re-use fields between logging statements by re-using | ||
159 | // the logrus.Entry returned from WithFields() | ||
160 | contextLogger := log.WithFields(log.Fields{ | ||
161 | "common": "this is a common field", | ||
162 | "other": "I also should be logged always", | ||
163 | }) | ||
164 | |||
165 | contextLogger.Info("I'll be logged with common and other field") | ||
166 | contextLogger.Info("Me too") | ||
167 | } | ||
168 | ``` | ||
169 | |||
170 | For more advanced usage such as logging to multiple locations from the same | ||
171 | application, you can also create an instance of the `logrus` Logger: | ||
172 | |||
173 | ```go | ||
174 | package main | ||
175 | |||
176 | import ( | ||
177 | "os" | ||
178 | "github.com/sirupsen/logrus" | ||
179 | ) | ||
180 | |||
181 | // Create a new instance of the logger. You can have any number of instances. | ||
182 | var log = logrus.New() | ||
183 | |||
184 | func main() { | ||
185 | // The API for setting attributes is a little different than the package level | ||
186 | // exported logger. See Godoc. | ||
187 | log.Out = os.Stdout | ||
188 | |||
189 | // You could set this to any `io.Writer` such as a file | ||
190 | // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666) | ||
191 | // if err == nil { | ||
192 | // log.Out = file | ||
193 | // } else { | ||
194 | // log.Info("Failed to log to file, using default stderr") | ||
195 | // } | ||
196 | |||
197 | log.WithFields(logrus.Fields{ | ||
198 | "animal": "walrus", | ||
199 | "size": 10, | ||
200 | }).Info("A group of walrus emerges from the ocean") | ||
201 | } | ||
202 | ``` | ||
203 | |||
204 | #### Fields | ||
205 | |||
206 | Logrus encourages careful, structured logging through logging fields instead of | ||
207 | long, unparseable error messages. For example, instead of: `log.Fatalf("Failed | ||
208 | to send event %s to topic %s with key %d")`, you should log the much more | ||
209 | discoverable: | ||
210 | |||
211 | ```go | ||
212 | log.WithFields(log.Fields{ | ||
213 | "event": event, | ||
214 | "topic": topic, | ||
215 | "key": key, | ||
216 | }).Fatal("Failed to send event") | ||
217 | ``` | ||
218 | |||
219 | We've found this API forces you to think about logging in a way that produces | ||
220 | much more useful logging messages. We've been in countless situations where just | ||
221 | a single added field to a log statement that was already there would've saved us | ||
222 | hours. The `WithFields` call is optional. | ||
223 | |||
224 | In general, with Logrus using any of the `printf`-family functions should be | ||
225 | seen as a hint you should add a field, however, you can still use the | ||
226 | `printf`-family functions with Logrus. | ||
227 | |||
228 | #### Default Fields | ||
229 | |||
230 | Often it's helpful to have fields _always_ attached to log statements in an | ||
231 | application or parts of one. For example, you may want to always log the | ||
232 | `request_id` and `user_ip` in the context of a request. Instead of writing | ||
233 | `log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on | ||
234 | every line, you can create a `logrus.Entry` to pass around instead: | ||
235 | |||
236 | ```go | ||
237 | requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip}) | ||
238 | requestLogger.Info("something happened on that request") # will log request_id and user_ip | ||
239 | requestLogger.Warn("something not great happened") | ||
240 | ``` | ||
241 | |||
242 | #### Hooks | ||
243 | |||
244 | You can add hooks for logging levels. For example to send errors to an exception | ||
245 | tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to | ||
246 | multiple places simultaneously, e.g. syslog. | ||
247 | |||
248 | Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in | ||
249 | `init`: | ||
250 | |||
251 | ```go | ||
252 | import ( | ||
253 | log "github.com/sirupsen/logrus" | ||
254 | "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "airbrake" | ||
255 | logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" | ||
256 | "log/syslog" | ||
257 | ) | ||
258 | |||
259 | func init() { | ||
260 | |||
261 | // Use the Airbrake hook to report errors that have Error severity or above to | ||
262 | // an exception tracker. You can create custom hooks, see the Hooks section. | ||
263 | log.AddHook(airbrake.NewHook(123, "xyz", "production")) | ||
264 | |||
265 | hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "") | ||
266 | if err != nil { | ||
267 | log.Error("Unable to connect to local syslog daemon") | ||
268 | } else { | ||
269 | log.AddHook(hook) | ||
270 | } | ||
271 | } | ||
272 | ``` | ||
273 | Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md). | ||
274 | |||
275 | A list of currently known of service hook can be found in this wiki [page](https://github.com/sirupsen/logrus/wiki/Hooks) | ||
276 | |||
277 | |||
278 | #### Level logging | ||
279 | |||
280 | Logrus has seven logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic. | ||
281 | |||
282 | ```go | ||
283 | log.Trace("Something very low level.") | ||
284 | log.Debug("Useful debugging information.") | ||
285 | log.Info("Something noteworthy happened!") | ||
286 | log.Warn("You should probably take a look at this.") | ||
287 | log.Error("Something failed but I'm not quitting.") | ||
288 | // Calls os.Exit(1) after logging | ||
289 | log.Fatal("Bye.") | ||
290 | // Calls panic() after logging | ||
291 | log.Panic("I'm bailing.") | ||
292 | ``` | ||
293 | |||
294 | You can set the logging level on a `Logger`, then it will only log entries with | ||
295 | that severity or anything above it: | ||
296 | |||
297 | ```go | ||
298 | // Will log anything that is info or above (warn, error, fatal, panic). Default. | ||
299 | log.SetLevel(log.InfoLevel) | ||
300 | ``` | ||
301 | |||
302 | It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose | ||
303 | environment if your application has that. | ||
304 | |||
305 | #### Entries | ||
306 | |||
307 | Besides the fields added with `WithField` or `WithFields` some fields are | ||
308 | automatically added to all logging events: | ||
309 | |||
310 | 1. `time`. The timestamp when the entry was created. | ||
311 | 2. `msg`. The logging message passed to `{Info,Warn,Error,Fatal,Panic}` after | ||
312 | the `AddFields` call. E.g. `Failed to send event.` | ||
313 | 3. `level`. The logging level. E.g. `info`. | ||
314 | |||
315 | #### Environments | ||
316 | |||
317 | Logrus has no notion of environment. | ||
318 | |||
319 | If you wish for hooks and formatters to only be used in specific environments, | ||
320 | you should handle that yourself. For example, if your application has a global | ||
321 | variable `Environment`, which is a string representation of the environment you | ||
322 | could do: | ||
323 | |||
324 | ```go | ||
325 | import ( | ||
326 | log "github.com/sirupsen/logrus" | ||
327 | ) | ||
328 | |||
329 | init() { | ||
330 | // do something here to set environment depending on an environment variable | ||
331 | // or command-line flag | ||
332 | if Environment == "production" { | ||
333 | log.SetFormatter(&log.JSONFormatter{}) | ||
334 | } else { | ||
335 | // The TextFormatter is default, you don't actually have to do this. | ||
336 | log.SetFormatter(&log.TextFormatter{}) | ||
337 | } | ||
338 | } | ||
339 | ``` | ||
340 | |||
341 | This configuration is how `logrus` was intended to be used, but JSON in | ||
342 | production is mostly only useful if you do log aggregation with tools like | ||
343 | Splunk or Logstash. | ||
344 | |||
345 | #### Formatters | ||
346 | |||
347 | The built-in logging formatters are: | ||
348 | |||
349 | * `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise | ||
350 | without colors. | ||
351 | * *Note:* to force colored output when there is no TTY, set the `ForceColors` | ||
352 | field to `true`. To force no colored output even if there is a TTY set the | ||
353 | `DisableColors` field to `true`. For Windows, see | ||
354 | [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable). | ||
355 | * When colors are enabled, levels are truncated to 4 characters by default. To disable | ||
356 | truncation set the `DisableLevelTruncation` field to `true`. | ||
357 | * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter). | ||
358 | * `logrus.JSONFormatter`. Logs fields as JSON. | ||
359 | * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter). | ||
360 | |||
361 | Third party logging formatters: | ||
362 | |||
363 | * [`FluentdFormatter`](https://github.com/joonix/log). Formats entries that can be parsed by Kubernetes and Google Container Engine. | ||
364 | * [`GELF`](https://github.com/fabienm/go-logrus-formatters). Formats entries so they comply to Graylog's [GELF 1.1 specification](http://docs.graylog.org/en/2.4/pages/gelf.html). | ||
365 | * [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events. | ||
366 | * [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout. | ||
367 | * [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦. | ||
368 | * [`nested-logrus-formatter`](https://github.com/antonfisher/nested-logrus-formatter). Converts logrus fields to a nested structure. | ||
369 | |||
370 | You can define your formatter by implementing the `Formatter` interface, | ||
371 | requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a | ||
372 | `Fields` type (`map[string]interface{}`) with all your fields as well as the | ||
373 | default ones (see Entries section above): | ||
374 | |||
375 | ```go | ||
376 | type MyJSONFormatter struct { | ||
377 | } | ||
378 | |||
379 | log.SetFormatter(new(MyJSONFormatter)) | ||
380 | |||
381 | func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) { | ||
382 | // Note this doesn't include Time, Level and Message which are available on | ||
383 | // the Entry. Consult `godoc` on information about those fields or read the | ||
384 | // source of the official loggers. | ||
385 | serialized, err := json.Marshal(entry.Data) | ||
386 | if err != nil { | ||
387 | return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) | ||
388 | } | ||
389 | return append(serialized, '\n'), nil | ||
390 | } | ||
391 | ``` | ||
392 | |||
393 | #### Logger as an `io.Writer` | ||
394 | |||
395 | Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it. | ||
396 | |||
397 | ```go | ||
398 | w := logger.Writer() | ||
399 | defer w.Close() | ||
400 | |||
401 | srv := http.Server{ | ||
402 | // create a stdlib log.Logger that writes to | ||
403 | // logrus.Logger. | ||
404 | ErrorLog: log.New(w, "", 0), | ||
405 | } | ||
406 | ``` | ||
407 | |||
408 | Each line written to that writer will be printed the usual way, using formatters | ||
409 | and hooks. The level for those entries is `info`. | ||
410 | |||
411 | This means that we can override the standard library logger easily: | ||
412 | |||
413 | ```go | ||
414 | logger := logrus.New() | ||
415 | logger.Formatter = &logrus.JSONFormatter{} | ||
416 | |||
417 | // Use logrus for standard log output | ||
418 | // Note that `log` here references stdlib's log | ||
419 | // Not logrus imported under the name `log`. | ||
420 | log.SetOutput(logger.Writer()) | ||
421 | ``` | ||
422 | |||
423 | #### Rotation | ||
424 | |||
425 | Log rotation is not provided with Logrus. Log rotation should be done by an | ||
426 | external program (like `logrotate(8)`) that can compress and delete old log | ||
427 | entries. It should not be a feature of the application-level logger. | ||
428 | |||
429 | #### Tools | ||
430 | |||
431 | | Tool | Description | | ||
432 | | ---- | ----------- | | ||
433 | |[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.| | ||
434 | |[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) | | ||
435 | |||
436 | #### Testing | ||
437 | |||
438 | Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides: | ||
439 | |||
440 | * decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just add the `test` hook | ||
441 | * a test logger (`test.NewNullLogger`) that just records log messages (and does not output any): | ||
442 | |||
443 | ```go | ||
444 | import( | ||
445 | "github.com/sirupsen/logrus" | ||
446 | "github.com/sirupsen/logrus/hooks/test" | ||
447 | "github.com/stretchr/testify/assert" | ||
448 | "testing" | ||
449 | ) | ||
450 | |||
451 | func TestSomething(t*testing.T){ | ||
452 | logger, hook := test.NewNullLogger() | ||
453 | logger.Error("Helloerror") | ||
454 | |||
455 | assert.Equal(t, 1, len(hook.Entries)) | ||
456 | assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) | ||
457 | assert.Equal(t, "Helloerror", hook.LastEntry().Message) | ||
458 | |||
459 | hook.Reset() | ||
460 | assert.Nil(t, hook.LastEntry()) | ||
461 | } | ||
462 | ``` | ||
463 | |||
464 | #### Fatal handlers | ||
465 | |||
466 | Logrus can register one or more functions that will be called when any `fatal` | ||
467 | level message is logged. The registered handlers will be executed before | ||
468 | logrus performs a `os.Exit(1)`. This behavior may be helpful if callers need | ||
469 | to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted. | ||
470 | |||
471 | ``` | ||
472 | ... | ||
473 | handler := func() { | ||
474 | // gracefully shutdown something... | ||
475 | } | ||
476 | logrus.RegisterExitHandler(handler) | ||
477 | ... | ||
478 | ``` | ||
479 | |||
480 | #### Thread safety | ||
481 | |||
482 | By default, Logger is protected by a mutex for concurrent writes. The mutex is held when calling hooks and writing logs. | ||
483 | If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking. | ||
484 | |||
485 | Situation when locking is not needed includes: | ||
486 | |||
487 | * You have no hooks registered, or hooks calling is already thread-safe. | ||
488 | |||
489 | * Writing to logger.Out is already thread-safe, for example: | ||
490 | |||
491 | 1) logger.Out is protected by locks. | ||
492 | |||
493 | 2) logger.Out is a os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allow multi-thread/multi-process writing) | ||
494 | |||
495 | (Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/) | ||
diff --git a/vendor/github.com/sirupsen/logrus/alt_exit.go b/vendor/github.com/sirupsen/logrus/alt_exit.go deleted file mode 100644 index 8fd189e..0000000 --- a/vendor/github.com/sirupsen/logrus/alt_exit.go +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | // The following code was sourced and modified from the | ||
4 | // https://github.com/tebeka/atexit package governed by the following license: | ||
5 | // | ||
6 | // Copyright (c) 2012 Miki Tebeka <miki.tebeka@gmail.com>. | ||
7 | // | ||
8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
9 | // this software and associated documentation files (the "Software"), to deal in | ||
10 | // the Software without restriction, including without limitation the rights to | ||
11 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
12 | // the Software, and to permit persons to whom the Software is furnished to do so, | ||
13 | // subject to the following conditions: | ||
14 | // | ||
15 | // The above copyright notice and this permission notice shall be included in all | ||
16 | // copies or substantial portions of the Software. | ||
17 | // | ||
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
20 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
21 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
22 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
23 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
24 | |||
25 | import ( | ||
26 | "fmt" | ||
27 | "os" | ||
28 | ) | ||
29 | |||
30 | var handlers = []func(){} | ||
31 | |||
32 | func runHandler(handler func()) { | ||
33 | defer func() { | ||
34 | if err := recover(); err != nil { | ||
35 | fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err) | ||
36 | } | ||
37 | }() | ||
38 | |||
39 | handler() | ||
40 | } | ||
41 | |||
42 | func runHandlers() { | ||
43 | for _, handler := range handlers { | ||
44 | runHandler(handler) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | // Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code) | ||
49 | func Exit(code int) { | ||
50 | runHandlers() | ||
51 | os.Exit(code) | ||
52 | } | ||
53 | |||
54 | // RegisterExitHandler appends a Logrus Exit handler to the list of handlers, | ||
55 | // call logrus.Exit to invoke all handlers. The handlers will also be invoked when | ||
56 | // any Fatal log entry is made. | ||
57 | // | ||
58 | // This method is useful when a caller wishes to use logrus to log a fatal | ||
59 | // message but also needs to gracefully shutdown. An example usecase could be | ||
60 | // closing database connections, or sending a alert that the application is | ||
61 | // closing. | ||
62 | func RegisterExitHandler(handler func()) { | ||
63 | handlers = append(handlers, handler) | ||
64 | } | ||
65 | |||
66 | // DeferExitHandler prepends a Logrus Exit handler to the list of handlers, | ||
67 | // call logrus.Exit to invoke all handlers. The handlers will also be invoked when | ||
68 | // any Fatal log entry is made. | ||
69 | // | ||
70 | // This method is useful when a caller wishes to use logrus to log a fatal | ||
71 | // message but also needs to gracefully shutdown. An example usecase could be | ||
72 | // closing database connections, or sending a alert that the application is | ||
73 | // closing. | ||
74 | func DeferExitHandler(handler func()) { | ||
75 | handlers = append([]func(){handler}, handlers...) | ||
76 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/appveyor.yml b/vendor/github.com/sirupsen/logrus/appveyor.yml deleted file mode 100644 index 96c2ce1..0000000 --- a/vendor/github.com/sirupsen/logrus/appveyor.yml +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | version: "{build}" | ||
2 | platform: x64 | ||
3 | clone_folder: c:\gopath\src\github.com\sirupsen\logrus | ||
4 | environment: | ||
5 | GOPATH: c:\gopath | ||
6 | branches: | ||
7 | only: | ||
8 | - master | ||
9 | install: | ||
10 | - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% | ||
11 | - go version | ||
12 | build_script: | ||
13 | - go get -t | ||
14 | - go test | ||
diff --git a/vendor/github.com/sirupsen/logrus/doc.go b/vendor/github.com/sirupsen/logrus/doc.go deleted file mode 100644 index da67aba..0000000 --- a/vendor/github.com/sirupsen/logrus/doc.go +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | /* | ||
2 | Package logrus is a structured logger for Go, completely API compatible with the standard library logger. | ||
3 | |||
4 | |||
5 | The simplest way to use Logrus is simply the package-level exported logger: | ||
6 | |||
7 | package main | ||
8 | |||
9 | import ( | ||
10 | log "github.com/sirupsen/logrus" | ||
11 | ) | ||
12 | |||
13 | func main() { | ||
14 | log.WithFields(log.Fields{ | ||
15 | "animal": "walrus", | ||
16 | "number": 1, | ||
17 | "size": 10, | ||
18 | }).Info("A walrus appears") | ||
19 | } | ||
20 | |||
21 | Output: | ||
22 | time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 | ||
23 | |||
24 | For a full guide visit https://github.com/sirupsen/logrus | ||
25 | */ | ||
26 | package logrus | ||
diff --git a/vendor/github.com/sirupsen/logrus/entry.go b/vendor/github.com/sirupsen/logrus/entry.go deleted file mode 100644 index 63e2558..0000000 --- a/vendor/github.com/sirupsen/logrus/entry.go +++ /dev/null | |||
@@ -1,407 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "context" | ||
6 | "fmt" | ||
7 | "os" | ||
8 | "reflect" | ||
9 | "runtime" | ||
10 | "strings" | ||
11 | "sync" | ||
12 | "time" | ||
13 | ) | ||
14 | |||
15 | var ( | ||
16 | bufferPool *sync.Pool | ||
17 | |||
18 | // qualified package name, cached at first use | ||
19 | logrusPackage string | ||
20 | |||
21 | // Positions in the call stack when tracing to report the calling method | ||
22 | minimumCallerDepth int | ||
23 | |||
24 | // Used for caller information initialisation | ||
25 | callerInitOnce sync.Once | ||
26 | ) | ||
27 | |||
28 | const ( | ||
29 | maximumCallerDepth int = 25 | ||
30 | knownLogrusFrames int = 4 | ||
31 | ) | ||
32 | |||
33 | func init() { | ||
34 | bufferPool = &sync.Pool{ | ||
35 | New: func() interface{} { | ||
36 | return new(bytes.Buffer) | ||
37 | }, | ||
38 | } | ||
39 | |||
40 | // start at the bottom of the stack before the package-name cache is primed | ||
41 | minimumCallerDepth = 1 | ||
42 | } | ||
43 | |||
44 | // Defines the key when adding errors using WithError. | ||
45 | var ErrorKey = "error" | ||
46 | |||
47 | // An entry is the final or intermediate Logrus logging entry. It contains all | ||
48 | // the fields passed with WithField{,s}. It's finally logged when Trace, Debug, | ||
49 | // Info, Warn, Error, Fatal or Panic is called on it. These objects can be | ||
50 | // reused and passed around as much as you wish to avoid field duplication. | ||
51 | type Entry struct { | ||
52 | Logger *Logger | ||
53 | |||
54 | // Contains all the fields set by the user. | ||
55 | Data Fields | ||
56 | |||
57 | // Time at which the log entry was created | ||
58 | Time time.Time | ||
59 | |||
60 | // Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic | ||
61 | // This field will be set on entry firing and the value will be equal to the one in Logger struct field. | ||
62 | Level Level | ||
63 | |||
64 | // Calling method, with package name | ||
65 | Caller *runtime.Frame | ||
66 | |||
67 | // Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic | ||
68 | Message string | ||
69 | |||
70 | // When formatter is called in entry.log(), a Buffer may be set to entry | ||
71 | Buffer *bytes.Buffer | ||
72 | |||
73 | // Contains the context set by the user. Useful for hook processing etc. | ||
74 | Context context.Context | ||
75 | |||
76 | // err may contain a field formatting error | ||
77 | err string | ||
78 | } | ||
79 | |||
80 | func NewEntry(logger *Logger) *Entry { | ||
81 | return &Entry{ | ||
82 | Logger: logger, | ||
83 | // Default is three fields, plus one optional. Give a little extra room. | ||
84 | Data: make(Fields, 6), | ||
85 | } | ||
86 | } | ||
87 | |||
88 | // Returns the string representation from the reader and ultimately the | ||
89 | // formatter. | ||
90 | func (entry *Entry) String() (string, error) { | ||
91 | serialized, err := entry.Logger.Formatter.Format(entry) | ||
92 | if err != nil { | ||
93 | return "", err | ||
94 | } | ||
95 | str := string(serialized) | ||
96 | return str, nil | ||
97 | } | ||
98 | |||
99 | // Add an error as single field (using the key defined in ErrorKey) to the Entry. | ||
100 | func (entry *Entry) WithError(err error) *Entry { | ||
101 | return entry.WithField(ErrorKey, err) | ||
102 | } | ||
103 | |||
104 | // Add a context to the Entry. | ||
105 | func (entry *Entry) WithContext(ctx context.Context) *Entry { | ||
106 | return &Entry{Logger: entry.Logger, Data: entry.Data, Time: entry.Time, err: entry.err, Context: ctx} | ||
107 | } | ||
108 | |||
109 | // Add a single field to the Entry. | ||
110 | func (entry *Entry) WithField(key string, value interface{}) *Entry { | ||
111 | return entry.WithFields(Fields{key: value}) | ||
112 | } | ||
113 | |||
114 | // Add a map of fields to the Entry. | ||
115 | func (entry *Entry) WithFields(fields Fields) *Entry { | ||
116 | data := make(Fields, len(entry.Data)+len(fields)) | ||
117 | for k, v := range entry.Data { | ||
118 | data[k] = v | ||
119 | } | ||
120 | fieldErr := entry.err | ||
121 | for k, v := range fields { | ||
122 | isErrField := false | ||
123 | if t := reflect.TypeOf(v); t != nil { | ||
124 | switch t.Kind() { | ||
125 | case reflect.Func: | ||
126 | isErrField = true | ||
127 | case reflect.Ptr: | ||
128 | isErrField = t.Elem().Kind() == reflect.Func | ||
129 | } | ||
130 | } | ||
131 | if isErrField { | ||
132 | tmp := fmt.Sprintf("can not add field %q", k) | ||
133 | if fieldErr != "" { | ||
134 | fieldErr = entry.err + ", " + tmp | ||
135 | } else { | ||
136 | fieldErr = tmp | ||
137 | } | ||
138 | } else { | ||
139 | data[k] = v | ||
140 | } | ||
141 | } | ||
142 | return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context} | ||
143 | } | ||
144 | |||
145 | // Overrides the time of the Entry. | ||
146 | func (entry *Entry) WithTime(t time.Time) *Entry { | ||
147 | return &Entry{Logger: entry.Logger, Data: entry.Data, Time: t, err: entry.err, Context: entry.Context} | ||
148 | } | ||
149 | |||
150 | // getPackageName reduces a fully qualified function name to the package name | ||
151 | // There really ought to be to be a better way... | ||
152 | func getPackageName(f string) string { | ||
153 | for { | ||
154 | lastPeriod := strings.LastIndex(f, ".") | ||
155 | lastSlash := strings.LastIndex(f, "/") | ||
156 | if lastPeriod > lastSlash { | ||
157 | f = f[:lastPeriod] | ||
158 | } else { | ||
159 | break | ||
160 | } | ||
161 | } | ||
162 | |||
163 | return f | ||
164 | } | ||
165 | |||
166 | // getCaller retrieves the name of the first non-logrus calling function | ||
167 | func getCaller() *runtime.Frame { | ||
168 | |||
169 | // cache this package's fully-qualified name | ||
170 | callerInitOnce.Do(func() { | ||
171 | pcs := make([]uintptr, 2) | ||
172 | _ = runtime.Callers(0, pcs) | ||
173 | logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name()) | ||
174 | |||
175 | // now that we have the cache, we can skip a minimum count of known-logrus functions | ||
176 | // XXX this is dubious, the number of frames may vary | ||
177 | minimumCallerDepth = knownLogrusFrames | ||
178 | }) | ||
179 | |||
180 | // Restrict the lookback frames to avoid runaway lookups | ||
181 | pcs := make([]uintptr, maximumCallerDepth) | ||
182 | depth := runtime.Callers(minimumCallerDepth, pcs) | ||
183 | frames := runtime.CallersFrames(pcs[:depth]) | ||
184 | |||
185 | for f, again := frames.Next(); again; f, again = frames.Next() { | ||
186 | pkg := getPackageName(f.Function) | ||
187 | |||
188 | // If the caller isn't part of this package, we're done | ||
189 | if pkg != logrusPackage { | ||
190 | return &f | ||
191 | } | ||
192 | } | ||
193 | |||
194 | // if we got here, we failed to find the caller's context | ||
195 | return nil | ||
196 | } | ||
197 | |||
198 | func (entry Entry) HasCaller() (has bool) { | ||
199 | return entry.Logger != nil && | ||
200 | entry.Logger.ReportCaller && | ||
201 | entry.Caller != nil | ||
202 | } | ||
203 | |||
204 | // This function is not declared with a pointer value because otherwise | ||
205 | // race conditions will occur when using multiple goroutines | ||
206 | func (entry Entry) log(level Level, msg string) { | ||
207 | var buffer *bytes.Buffer | ||
208 | |||
209 | // Default to now, but allow users to override if they want. | ||
210 | // | ||
211 | // We don't have to worry about polluting future calls to Entry#log() | ||
212 | // with this assignment because this function is declared with a | ||
213 | // non-pointer receiver. | ||
214 | if entry.Time.IsZero() { | ||
215 | entry.Time = time.Now() | ||
216 | } | ||
217 | |||
218 | entry.Level = level | ||
219 | entry.Message = msg | ||
220 | if entry.Logger.ReportCaller { | ||
221 | entry.Caller = getCaller() | ||
222 | } | ||
223 | |||
224 | entry.fireHooks() | ||
225 | |||
226 | buffer = bufferPool.Get().(*bytes.Buffer) | ||
227 | buffer.Reset() | ||
228 | defer bufferPool.Put(buffer) | ||
229 | entry.Buffer = buffer | ||
230 | |||
231 | entry.write() | ||
232 | |||
233 | entry.Buffer = nil | ||
234 | |||
235 | // To avoid Entry#log() returning a value that only would make sense for | ||
236 | // panic() to use in Entry#Panic(), we avoid the allocation by checking | ||
237 | // directly here. | ||
238 | if level <= PanicLevel { | ||
239 | panic(&entry) | ||
240 | } | ||
241 | } | ||
242 | |||
243 | func (entry *Entry) fireHooks() { | ||
244 | entry.Logger.mu.Lock() | ||
245 | defer entry.Logger.mu.Unlock() | ||
246 | err := entry.Logger.Hooks.Fire(entry.Level, entry) | ||
247 | if err != nil { | ||
248 | fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) | ||
249 | } | ||
250 | } | ||
251 | |||
252 | func (entry *Entry) write() { | ||
253 | entry.Logger.mu.Lock() | ||
254 | defer entry.Logger.mu.Unlock() | ||
255 | serialized, err := entry.Logger.Formatter.Format(entry) | ||
256 | if err != nil { | ||
257 | fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) | ||
258 | } else { | ||
259 | _, err = entry.Logger.Out.Write(serialized) | ||
260 | if err != nil { | ||
261 | fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) | ||
262 | } | ||
263 | } | ||
264 | } | ||
265 | |||
266 | func (entry *Entry) Log(level Level, args ...interface{}) { | ||
267 | if entry.Logger.IsLevelEnabled(level) { | ||
268 | entry.log(level, fmt.Sprint(args...)) | ||
269 | } | ||
270 | } | ||
271 | |||
272 | func (entry *Entry) Trace(args ...interface{}) { | ||
273 | entry.Log(TraceLevel, args...) | ||
274 | } | ||
275 | |||
276 | func (entry *Entry) Debug(args ...interface{}) { | ||
277 | entry.Log(DebugLevel, args...) | ||
278 | } | ||
279 | |||
280 | func (entry *Entry) Print(args ...interface{}) { | ||
281 | entry.Info(args...) | ||
282 | } | ||
283 | |||
284 | func (entry *Entry) Info(args ...interface{}) { | ||
285 | entry.Log(InfoLevel, args...) | ||
286 | } | ||
287 | |||
288 | func (entry *Entry) Warn(args ...interface{}) { | ||
289 | entry.Log(WarnLevel, args...) | ||
290 | } | ||
291 | |||
292 | func (entry *Entry) Warning(args ...interface{}) { | ||
293 | entry.Warn(args...) | ||
294 | } | ||
295 | |||
296 | func (entry *Entry) Error(args ...interface{}) { | ||
297 | entry.Log(ErrorLevel, args...) | ||
298 | } | ||
299 | |||
300 | func (entry *Entry) Fatal(args ...interface{}) { | ||
301 | entry.Log(FatalLevel, args...) | ||
302 | entry.Logger.Exit(1) | ||
303 | } | ||
304 | |||
305 | func (entry *Entry) Panic(args ...interface{}) { | ||
306 | entry.Log(PanicLevel, args...) | ||
307 | panic(fmt.Sprint(args...)) | ||
308 | } | ||
309 | |||
310 | // Entry Printf family functions | ||
311 | |||
312 | func (entry *Entry) Logf(level Level, format string, args ...interface{}) { | ||
313 | if entry.Logger.IsLevelEnabled(level) { | ||
314 | entry.Log(level, fmt.Sprintf(format, args...)) | ||
315 | } | ||
316 | } | ||
317 | |||
318 | func (entry *Entry) Tracef(format string, args ...interface{}) { | ||
319 | entry.Logf(TraceLevel, format, args...) | ||
320 | } | ||
321 | |||
322 | func (entry *Entry) Debugf(format string, args ...interface{}) { | ||
323 | entry.Logf(DebugLevel, format, args...) | ||
324 | } | ||
325 | |||
326 | func (entry *Entry) Infof(format string, args ...interface{}) { | ||
327 | entry.Logf(InfoLevel, format, args...) | ||
328 | } | ||
329 | |||
330 | func (entry *Entry) Printf(format string, args ...interface{}) { | ||
331 | entry.Infof(format, args...) | ||
332 | } | ||
333 | |||
334 | func (entry *Entry) Warnf(format string, args ...interface{}) { | ||
335 | entry.Logf(WarnLevel, format, args...) | ||
336 | } | ||
337 | |||
338 | func (entry *Entry) Warningf(format string, args ...interface{}) { | ||
339 | entry.Warnf(format, args...) | ||
340 | } | ||
341 | |||
342 | func (entry *Entry) Errorf(format string, args ...interface{}) { | ||
343 | entry.Logf(ErrorLevel, format, args...) | ||
344 | } | ||
345 | |||
346 | func (entry *Entry) Fatalf(format string, args ...interface{}) { | ||
347 | entry.Logf(FatalLevel, format, args...) | ||
348 | entry.Logger.Exit(1) | ||
349 | } | ||
350 | |||
351 | func (entry *Entry) Panicf(format string, args ...interface{}) { | ||
352 | entry.Logf(PanicLevel, format, args...) | ||
353 | } | ||
354 | |||
355 | // Entry Println family functions | ||
356 | |||
357 | func (entry *Entry) Logln(level Level, args ...interface{}) { | ||
358 | if entry.Logger.IsLevelEnabled(level) { | ||
359 | entry.Log(level, entry.sprintlnn(args...)) | ||
360 | } | ||
361 | } | ||
362 | |||
363 | func (entry *Entry) Traceln(args ...interface{}) { | ||
364 | entry.Logln(TraceLevel, args...) | ||
365 | } | ||
366 | |||
367 | func (entry *Entry) Debugln(args ...interface{}) { | ||
368 | entry.Logln(DebugLevel, args...) | ||
369 | } | ||
370 | |||
371 | func (entry *Entry) Infoln(args ...interface{}) { | ||
372 | entry.Logln(InfoLevel, args...) | ||
373 | } | ||
374 | |||
375 | func (entry *Entry) Println(args ...interface{}) { | ||
376 | entry.Infoln(args...) | ||
377 | } | ||
378 | |||
379 | func (entry *Entry) Warnln(args ...interface{}) { | ||
380 | entry.Logln(WarnLevel, args...) | ||
381 | } | ||
382 | |||
383 | func (entry *Entry) Warningln(args ...interface{}) { | ||
384 | entry.Warnln(args...) | ||
385 | } | ||
386 | |||
387 | func (entry *Entry) Errorln(args ...interface{}) { | ||
388 | entry.Logln(ErrorLevel, args...) | ||
389 | } | ||
390 | |||
391 | func (entry *Entry) Fatalln(args ...interface{}) { | ||
392 | entry.Logln(FatalLevel, args...) | ||
393 | entry.Logger.Exit(1) | ||
394 | } | ||
395 | |||
396 | func (entry *Entry) Panicln(args ...interface{}) { | ||
397 | entry.Logln(PanicLevel, args...) | ||
398 | } | ||
399 | |||
400 | // Sprintlnn => Sprint no newline. This is to get the behavior of how | ||
401 | // fmt.Sprintln where spaces are always added between operands, regardless of | ||
402 | // their type. Instead of vendoring the Sprintln implementation to spare a | ||
403 | // string allocation, we do the simplest thing. | ||
404 | func (entry *Entry) sprintlnn(args ...interface{}) string { | ||
405 | msg := fmt.Sprintln(args...) | ||
406 | return msg[:len(msg)-1] | ||
407 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/exported.go b/vendor/github.com/sirupsen/logrus/exported.go deleted file mode 100644 index 62fc2f2..0000000 --- a/vendor/github.com/sirupsen/logrus/exported.go +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "context" | ||
5 | "io" | ||
6 | "time" | ||
7 | ) | ||
8 | |||
9 | var ( | ||
10 | // std is the name of the standard logger in stdlib `log` | ||
11 | std = New() | ||
12 | ) | ||
13 | |||
14 | func StandardLogger() *Logger { | ||
15 | return std | ||
16 | } | ||
17 | |||
18 | // SetOutput sets the standard logger output. | ||
19 | func SetOutput(out io.Writer) { | ||
20 | std.SetOutput(out) | ||
21 | } | ||
22 | |||
23 | // SetFormatter sets the standard logger formatter. | ||
24 | func SetFormatter(formatter Formatter) { | ||
25 | std.SetFormatter(formatter) | ||
26 | } | ||
27 | |||
28 | // SetReportCaller sets whether the standard logger will include the calling | ||
29 | // method as a field. | ||
30 | func SetReportCaller(include bool) { | ||
31 | std.SetReportCaller(include) | ||
32 | } | ||
33 | |||
34 | // SetLevel sets the standard logger level. | ||
35 | func SetLevel(level Level) { | ||
36 | std.SetLevel(level) | ||
37 | } | ||
38 | |||
39 | // GetLevel returns the standard logger level. | ||
40 | func GetLevel() Level { | ||
41 | return std.GetLevel() | ||
42 | } | ||
43 | |||
44 | // IsLevelEnabled checks if the log level of the standard logger is greater than the level param | ||
45 | func IsLevelEnabled(level Level) bool { | ||
46 | return std.IsLevelEnabled(level) | ||
47 | } | ||
48 | |||
49 | // AddHook adds a hook to the standard logger hooks. | ||
50 | func AddHook(hook Hook) { | ||
51 | std.AddHook(hook) | ||
52 | } | ||
53 | |||
54 | // WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key. | ||
55 | func WithError(err error) *Entry { | ||
56 | return std.WithField(ErrorKey, err) | ||
57 | } | ||
58 | |||
59 | // WithContext creates an entry from the standard logger and adds a context to it. | ||
60 | func WithContext(ctx context.Context) *Entry { | ||
61 | return std.WithContext(ctx) | ||
62 | } | ||
63 | |||
64 | // WithField creates an entry from the standard logger and adds a field to | ||
65 | // it. If you want multiple fields, use `WithFields`. | ||
66 | // | ||
67 | // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal | ||
68 | // or Panic on the Entry it returns. | ||
69 | func WithField(key string, value interface{}) *Entry { | ||
70 | return std.WithField(key, value) | ||
71 | } | ||
72 | |||
73 | // WithFields creates an entry from the standard logger and adds multiple | ||
74 | // fields to it. This is simply a helper for `WithField`, invoking it | ||
75 | // once for each field. | ||
76 | // | ||
77 | // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal | ||
78 | // or Panic on the Entry it returns. | ||
79 | func WithFields(fields Fields) *Entry { | ||
80 | return std.WithFields(fields) | ||
81 | } | ||
82 | |||
83 | // WithTime creats an entry from the standard logger and overrides the time of | ||
84 | // logs generated with it. | ||
85 | // | ||
86 | // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal | ||
87 | // or Panic on the Entry it returns. | ||
88 | func WithTime(t time.Time) *Entry { | ||
89 | return std.WithTime(t) | ||
90 | } | ||
91 | |||
92 | // Trace logs a message at level Trace on the standard logger. | ||
93 | func Trace(args ...interface{}) { | ||
94 | std.Trace(args...) | ||
95 | } | ||
96 | |||
97 | // Debug logs a message at level Debug on the standard logger. | ||
98 | func Debug(args ...interface{}) { | ||
99 | std.Debug(args...) | ||
100 | } | ||
101 | |||
102 | // Print logs a message at level Info on the standard logger. | ||
103 | func Print(args ...interface{}) { | ||
104 | std.Print(args...) | ||
105 | } | ||
106 | |||
107 | // Info logs a message at level Info on the standard logger. | ||
108 | func Info(args ...interface{}) { | ||
109 | std.Info(args...) | ||
110 | } | ||
111 | |||
112 | // Warn logs a message at level Warn on the standard logger. | ||
113 | func Warn(args ...interface{}) { | ||
114 | std.Warn(args...) | ||
115 | } | ||
116 | |||
117 | // Warning logs a message at level Warn on the standard logger. | ||
118 | func Warning(args ...interface{}) { | ||
119 | std.Warning(args...) | ||
120 | } | ||
121 | |||
122 | // Error logs a message at level Error on the standard logger. | ||
123 | func Error(args ...interface{}) { | ||
124 | std.Error(args...) | ||
125 | } | ||
126 | |||
127 | // Panic logs a message at level Panic on the standard logger. | ||
128 | func Panic(args ...interface{}) { | ||
129 | std.Panic(args...) | ||
130 | } | ||
131 | |||
132 | // Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1. | ||
133 | func Fatal(args ...interface{}) { | ||
134 | std.Fatal(args...) | ||
135 | } | ||
136 | |||
137 | // Tracef logs a message at level Trace on the standard logger. | ||
138 | func Tracef(format string, args ...interface{}) { | ||
139 | std.Tracef(format, args...) | ||
140 | } | ||
141 | |||
142 | // Debugf logs a message at level Debug on the standard logger. | ||
143 | func Debugf(format string, args ...interface{}) { | ||
144 | std.Debugf(format, args...) | ||
145 | } | ||
146 | |||
147 | // Printf logs a message at level Info on the standard logger. | ||
148 | func Printf(format string, args ...interface{}) { | ||
149 | std.Printf(format, args...) | ||
150 | } | ||
151 | |||
152 | // Infof logs a message at level Info on the standard logger. | ||
153 | func Infof(format string, args ...interface{}) { | ||
154 | std.Infof(format, args...) | ||
155 | } | ||
156 | |||
157 | // Warnf logs a message at level Warn on the standard logger. | ||
158 | func Warnf(format string, args ...interface{}) { | ||
159 | std.Warnf(format, args...) | ||
160 | } | ||
161 | |||
162 | // Warningf logs a message at level Warn on the standard logger. | ||
163 | func Warningf(format string, args ...interface{}) { | ||
164 | std.Warningf(format, args...) | ||
165 | } | ||
166 | |||
167 | // Errorf logs a message at level Error on the standard logger. | ||
168 | func Errorf(format string, args ...interface{}) { | ||
169 | std.Errorf(format, args...) | ||
170 | } | ||
171 | |||
172 | // Panicf logs a message at level Panic on the standard logger. | ||
173 | func Panicf(format string, args ...interface{}) { | ||
174 | std.Panicf(format, args...) | ||
175 | } | ||
176 | |||
177 | // Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1. | ||
178 | func Fatalf(format string, args ...interface{}) { | ||
179 | std.Fatalf(format, args...) | ||
180 | } | ||
181 | |||
182 | // Traceln logs a message at level Trace on the standard logger. | ||
183 | func Traceln(args ...interface{}) { | ||
184 | std.Traceln(args...) | ||
185 | } | ||
186 | |||
187 | // Debugln logs a message at level Debug on the standard logger. | ||
188 | func Debugln(args ...interface{}) { | ||
189 | std.Debugln(args...) | ||
190 | } | ||
191 | |||
192 | // Println logs a message at level Info on the standard logger. | ||
193 | func Println(args ...interface{}) { | ||
194 | std.Println(args...) | ||
195 | } | ||
196 | |||
197 | // Infoln logs a message at level Info on the standard logger. | ||
198 | func Infoln(args ...interface{}) { | ||
199 | std.Infoln(args...) | ||
200 | } | ||
201 | |||
202 | // Warnln logs a message at level Warn on the standard logger. | ||
203 | func Warnln(args ...interface{}) { | ||
204 | std.Warnln(args...) | ||
205 | } | ||
206 | |||
207 | // Warningln logs a message at level Warn on the standard logger. | ||
208 | func Warningln(args ...interface{}) { | ||
209 | std.Warningln(args...) | ||
210 | } | ||
211 | |||
212 | // Errorln logs a message at level Error on the standard logger. | ||
213 | func Errorln(args ...interface{}) { | ||
214 | std.Errorln(args...) | ||
215 | } | ||
216 | |||
217 | // Panicln logs a message at level Panic on the standard logger. | ||
218 | func Panicln(args ...interface{}) { | ||
219 | std.Panicln(args...) | ||
220 | } | ||
221 | |||
222 | // Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1. | ||
223 | func Fatalln(args ...interface{}) { | ||
224 | std.Fatalln(args...) | ||
225 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/formatter.go b/vendor/github.com/sirupsen/logrus/formatter.go deleted file mode 100644 index 4088837..0000000 --- a/vendor/github.com/sirupsen/logrus/formatter.go +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import "time" | ||
4 | |||
5 | // Default key names for the default fields | ||
6 | const ( | ||
7 | defaultTimestampFormat = time.RFC3339 | ||
8 | FieldKeyMsg = "msg" | ||
9 | FieldKeyLevel = "level" | ||
10 | FieldKeyTime = "time" | ||
11 | FieldKeyLogrusError = "logrus_error" | ||
12 | FieldKeyFunc = "func" | ||
13 | FieldKeyFile = "file" | ||
14 | ) | ||
15 | |||
16 | // The Formatter interface is used to implement a custom Formatter. It takes an | ||
17 | // `Entry`. It exposes all the fields, including the default ones: | ||
18 | // | ||
19 | // * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. | ||
20 | // * `entry.Data["time"]`. The timestamp. | ||
21 | // * `entry.Data["level"]. The level the entry was logged at. | ||
22 | // | ||
23 | // Any additional fields added with `WithField` or `WithFields` are also in | ||
24 | // `entry.Data`. Format is expected to return an array of bytes which are then | ||
25 | // logged to `logger.Out`. | ||
26 | type Formatter interface { | ||
27 | Format(*Entry) ([]byte, error) | ||
28 | } | ||
29 | |||
30 | // This is to not silently overwrite `time`, `msg`, `func` and `level` fields when | ||
31 | // dumping it. If this code wasn't there doing: | ||
32 | // | ||
33 | // logrus.WithField("level", 1).Info("hello") | ||
34 | // | ||
35 | // Would just silently drop the user provided level. Instead with this code | ||
36 | // it'll logged as: | ||
37 | // | ||
38 | // {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} | ||
39 | // | ||
40 | // It's not exported because it's still using Data in an opinionated way. It's to | ||
41 | // avoid code duplication between the two default formatters. | ||
42 | func prefixFieldClashes(data Fields, fieldMap FieldMap, reportCaller bool) { | ||
43 | timeKey := fieldMap.resolve(FieldKeyTime) | ||
44 | if t, ok := data[timeKey]; ok { | ||
45 | data["fields."+timeKey] = t | ||
46 | delete(data, timeKey) | ||
47 | } | ||
48 | |||
49 | msgKey := fieldMap.resolve(FieldKeyMsg) | ||
50 | if m, ok := data[msgKey]; ok { | ||
51 | data["fields."+msgKey] = m | ||
52 | delete(data, msgKey) | ||
53 | } | ||
54 | |||
55 | levelKey := fieldMap.resolve(FieldKeyLevel) | ||
56 | if l, ok := data[levelKey]; ok { | ||
57 | data["fields."+levelKey] = l | ||
58 | delete(data, levelKey) | ||
59 | } | ||
60 | |||
61 | logrusErrKey := fieldMap.resolve(FieldKeyLogrusError) | ||
62 | if l, ok := data[logrusErrKey]; ok { | ||
63 | data["fields."+logrusErrKey] = l | ||
64 | delete(data, logrusErrKey) | ||
65 | } | ||
66 | |||
67 | // If reportCaller is not set, 'func' will not conflict. | ||
68 | if reportCaller { | ||
69 | funcKey := fieldMap.resolve(FieldKeyFunc) | ||
70 | if l, ok := data[funcKey]; ok { | ||
71 | data["fields."+funcKey] = l | ||
72 | } | ||
73 | fileKey := fieldMap.resolve(FieldKeyFile) | ||
74 | if l, ok := data[fileKey]; ok { | ||
75 | data["fields."+fileKey] = l | ||
76 | } | ||
77 | } | ||
78 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/go.mod b/vendor/github.com/sirupsen/logrus/go.mod deleted file mode 100644 index 12fdf98..0000000 --- a/vendor/github.com/sirupsen/logrus/go.mod +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | module github.com/sirupsen/logrus | ||
2 | |||
3 | require ( | ||
4 | github.com/davecgh/go-spew v1.1.1 // indirect | ||
5 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 | ||
6 | github.com/pmezard/go-difflib v1.0.0 // indirect | ||
7 | github.com/stretchr/objx v0.1.1 // indirect | ||
8 | github.com/stretchr/testify v1.2.2 | ||
9 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894 | ||
10 | ) | ||
diff --git a/vendor/github.com/sirupsen/logrus/go.sum b/vendor/github.com/sirupsen/logrus/go.sum deleted file mode 100644 index 596c318..0000000 --- a/vendor/github.com/sirupsen/logrus/go.sum +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
3 | github.com/konsorten/go-windows-terminal-sequences v0.0.0-20180402223658-b729f2633dfe h1:CHRGQ8V7OlCYtwaKPJi3iA7J+YdNKdo8j7nG5IgDhjs= | ||
4 | github.com/konsorten/go-windows-terminal-sequences v0.0.0-20180402223658-b729f2633dfe/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | ||
5 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= | ||
6 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | ||
7 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
8 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
9 | github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= | ||
10 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
11 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||
12 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
13 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= | ||
14 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
15 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= | ||
16 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
diff --git a/vendor/github.com/sirupsen/logrus/hooks.go b/vendor/github.com/sirupsen/logrus/hooks.go deleted file mode 100644 index 3f151cd..0000000 --- a/vendor/github.com/sirupsen/logrus/hooks.go +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | // A hook to be fired when logging on the logging levels returned from | ||
4 | // `Levels()` on your implementation of the interface. Note that this is not | ||
5 | // fired in a goroutine or a channel with workers, you should handle such | ||
6 | // functionality yourself if your call is non-blocking and you don't wish for | ||
7 | // the logging calls for levels returned from `Levels()` to block. | ||
8 | type Hook interface { | ||
9 | Levels() []Level | ||
10 | Fire(*Entry) error | ||
11 | } | ||
12 | |||
13 | // Internal type for storing the hooks on a logger instance. | ||
14 | type LevelHooks map[Level][]Hook | ||
15 | |||
16 | // Add a hook to an instance of logger. This is called with | ||
17 | // `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. | ||
18 | func (hooks LevelHooks) Add(hook Hook) { | ||
19 | for _, level := range hook.Levels() { | ||
20 | hooks[level] = append(hooks[level], hook) | ||
21 | } | ||
22 | } | ||
23 | |||
24 | // Fire all the hooks for the passed level. Used by `entry.log` to fire | ||
25 | // appropriate hooks for a log entry. | ||
26 | func (hooks LevelHooks) Fire(level Level, entry *Entry) error { | ||
27 | for _, hook := range hooks[level] { | ||
28 | if err := hook.Fire(entry); err != nil { | ||
29 | return err | ||
30 | } | ||
31 | } | ||
32 | |||
33 | return nil | ||
34 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/json_formatter.go b/vendor/github.com/sirupsen/logrus/json_formatter.go deleted file mode 100644 index 098a21a..0000000 --- a/vendor/github.com/sirupsen/logrus/json_formatter.go +++ /dev/null | |||
@@ -1,121 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "encoding/json" | ||
6 | "fmt" | ||
7 | "runtime" | ||
8 | ) | ||
9 | |||
10 | type fieldKey string | ||
11 | |||
12 | // FieldMap allows customization of the key names for default fields. | ||
13 | type FieldMap map[fieldKey]string | ||
14 | |||
15 | func (f FieldMap) resolve(key fieldKey) string { | ||
16 | if k, ok := f[key]; ok { | ||
17 | return k | ||
18 | } | ||
19 | |||
20 | return string(key) | ||
21 | } | ||
22 | |||
23 | // JSONFormatter formats logs into parsable json | ||
24 | type JSONFormatter struct { | ||
25 | // TimestampFormat sets the format used for marshaling timestamps. | ||
26 | TimestampFormat string | ||
27 | |||
28 | // DisableTimestamp allows disabling automatic timestamps in output | ||
29 | DisableTimestamp bool | ||
30 | |||
31 | // DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. | ||
32 | DataKey string | ||
33 | |||
34 | // FieldMap allows users to customize the names of keys for default fields. | ||
35 | // As an example: | ||
36 | // formatter := &JSONFormatter{ | ||
37 | // FieldMap: FieldMap{ | ||
38 | // FieldKeyTime: "@timestamp", | ||
39 | // FieldKeyLevel: "@level", | ||
40 | // FieldKeyMsg: "@message", | ||
41 | // FieldKeyFunc: "@caller", | ||
42 | // }, | ||
43 | // } | ||
44 | FieldMap FieldMap | ||
45 | |||
46 | // CallerPrettyfier can be set by the user to modify the content | ||
47 | // of the function and file keys in the json data when ReportCaller is | ||
48 | // activated. If any of the returned value is the empty string the | ||
49 | // corresponding key will be removed from json fields. | ||
50 | CallerPrettyfier func(*runtime.Frame) (function string, file string) | ||
51 | |||
52 | // PrettyPrint will indent all json logs | ||
53 | PrettyPrint bool | ||
54 | } | ||
55 | |||
56 | // Format renders a single log entry | ||
57 | func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { | ||
58 | data := make(Fields, len(entry.Data)+4) | ||
59 | for k, v := range entry.Data { | ||
60 | switch v := v.(type) { | ||
61 | case error: | ||
62 | // Otherwise errors are ignored by `encoding/json` | ||
63 | // https://github.com/sirupsen/logrus/issues/137 | ||
64 | data[k] = v.Error() | ||
65 | default: | ||
66 | data[k] = v | ||
67 | } | ||
68 | } | ||
69 | |||
70 | if f.DataKey != "" { | ||
71 | newData := make(Fields, 4) | ||
72 | newData[f.DataKey] = data | ||
73 | data = newData | ||
74 | } | ||
75 | |||
76 | prefixFieldClashes(data, f.FieldMap, entry.HasCaller()) | ||
77 | |||
78 | timestampFormat := f.TimestampFormat | ||
79 | if timestampFormat == "" { | ||
80 | timestampFormat = defaultTimestampFormat | ||
81 | } | ||
82 | |||
83 | if entry.err != "" { | ||
84 | data[f.FieldMap.resolve(FieldKeyLogrusError)] = entry.err | ||
85 | } | ||
86 | if !f.DisableTimestamp { | ||
87 | data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) | ||
88 | } | ||
89 | data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message | ||
90 | data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() | ||
91 | if entry.HasCaller() { | ||
92 | funcVal := entry.Caller.Function | ||
93 | fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) | ||
94 | if f.CallerPrettyfier != nil { | ||
95 | funcVal, fileVal = f.CallerPrettyfier(entry.Caller) | ||
96 | } | ||
97 | if funcVal != "" { | ||
98 | data[f.FieldMap.resolve(FieldKeyFunc)] = funcVal | ||
99 | } | ||
100 | if fileVal != "" { | ||
101 | data[f.FieldMap.resolve(FieldKeyFile)] = fileVal | ||
102 | } | ||
103 | } | ||
104 | |||
105 | var b *bytes.Buffer | ||
106 | if entry.Buffer != nil { | ||
107 | b = entry.Buffer | ||
108 | } else { | ||
109 | b = &bytes.Buffer{} | ||
110 | } | ||
111 | |||
112 | encoder := json.NewEncoder(b) | ||
113 | if f.PrettyPrint { | ||
114 | encoder.SetIndent("", " ") | ||
115 | } | ||
116 | if err := encoder.Encode(data); err != nil { | ||
117 | return nil, fmt.Errorf("failed to marshal fields to JSON, %v", err) | ||
118 | } | ||
119 | |||
120 | return b.Bytes(), nil | ||
121 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/logger.go b/vendor/github.com/sirupsen/logrus/logger.go deleted file mode 100644 index c0c0b1e..0000000 --- a/vendor/github.com/sirupsen/logrus/logger.go +++ /dev/null | |||
@@ -1,351 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "context" | ||
5 | "io" | ||
6 | "os" | ||
7 | "sync" | ||
8 | "sync/atomic" | ||
9 | "time" | ||
10 | ) | ||
11 | |||
12 | type Logger struct { | ||
13 | // The logs are `io.Copy`'d to this in a mutex. It's common to set this to a | ||
14 | // file, or leave it default which is `os.Stderr`. You can also set this to | ||
15 | // something more adventurous, such as logging to Kafka. | ||
16 | Out io.Writer | ||
17 | // Hooks for the logger instance. These allow firing events based on logging | ||
18 | // levels and log entries. For example, to send errors to an error tracking | ||
19 | // service, log to StatsD or dump the core on fatal errors. | ||
20 | Hooks LevelHooks | ||
21 | // All log entries pass through the formatter before logged to Out. The | ||
22 | // included formatters are `TextFormatter` and `JSONFormatter` for which | ||
23 | // TextFormatter is the default. In development (when a TTY is attached) it | ||
24 | // logs with colors, but to a file it wouldn't. You can easily implement your | ||
25 | // own that implements the `Formatter` interface, see the `README` or included | ||
26 | // formatters for examples. | ||
27 | Formatter Formatter | ||
28 | |||
29 | // Flag for whether to log caller info (off by default) | ||
30 | ReportCaller bool | ||
31 | |||
32 | // The logging level the logger should log at. This is typically (and defaults | ||
33 | // to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be | ||
34 | // logged. | ||
35 | Level Level | ||
36 | // Used to sync writing to the log. Locking is enabled by Default | ||
37 | mu MutexWrap | ||
38 | // Reusable empty entry | ||
39 | entryPool sync.Pool | ||
40 | // Function to exit the application, defaults to `os.Exit()` | ||
41 | ExitFunc exitFunc | ||
42 | } | ||
43 | |||
44 | type exitFunc func(int) | ||
45 | |||
46 | type MutexWrap struct { | ||
47 | lock sync.Mutex | ||
48 | disabled bool | ||
49 | } | ||
50 | |||
51 | func (mw *MutexWrap) Lock() { | ||
52 | if !mw.disabled { | ||
53 | mw.lock.Lock() | ||
54 | } | ||
55 | } | ||
56 | |||
57 | func (mw *MutexWrap) Unlock() { | ||
58 | if !mw.disabled { | ||
59 | mw.lock.Unlock() | ||
60 | } | ||
61 | } | ||
62 | |||
63 | func (mw *MutexWrap) Disable() { | ||
64 | mw.disabled = true | ||
65 | } | ||
66 | |||
67 | // Creates a new logger. Configuration should be set by changing `Formatter`, | ||
68 | // `Out` and `Hooks` directly on the default logger instance. You can also just | ||
69 | // instantiate your own: | ||
70 | // | ||
71 | // var log = &Logger{ | ||
72 | // Out: os.Stderr, | ||
73 | // Formatter: new(JSONFormatter), | ||
74 | // Hooks: make(LevelHooks), | ||
75 | // Level: logrus.DebugLevel, | ||
76 | // } | ||
77 | // | ||
78 | // It's recommended to make this a global instance called `log`. | ||
79 | func New() *Logger { | ||
80 | return &Logger{ | ||
81 | Out: os.Stderr, | ||
82 | Formatter: new(TextFormatter), | ||
83 | Hooks: make(LevelHooks), | ||
84 | Level: InfoLevel, | ||
85 | ExitFunc: os.Exit, | ||
86 | ReportCaller: false, | ||
87 | } | ||
88 | } | ||
89 | |||
90 | func (logger *Logger) newEntry() *Entry { | ||
91 | entry, ok := logger.entryPool.Get().(*Entry) | ||
92 | if ok { | ||
93 | return entry | ||
94 | } | ||
95 | return NewEntry(logger) | ||
96 | } | ||
97 | |||
98 | func (logger *Logger) releaseEntry(entry *Entry) { | ||
99 | entry.Data = map[string]interface{}{} | ||
100 | logger.entryPool.Put(entry) | ||
101 | } | ||
102 | |||
103 | // Adds a field to the log entry, note that it doesn't log until you call | ||
104 | // Debug, Print, Info, Warn, Error, Fatal or Panic. It only creates a log entry. | ||
105 | // If you want multiple fields, use `WithFields`. | ||
106 | func (logger *Logger) WithField(key string, value interface{}) *Entry { | ||
107 | entry := logger.newEntry() | ||
108 | defer logger.releaseEntry(entry) | ||
109 | return entry.WithField(key, value) | ||
110 | } | ||
111 | |||
112 | // Adds a struct of fields to the log entry. All it does is call `WithField` for | ||
113 | // each `Field`. | ||
114 | func (logger *Logger) WithFields(fields Fields) *Entry { | ||
115 | entry := logger.newEntry() | ||
116 | defer logger.releaseEntry(entry) | ||
117 | return entry.WithFields(fields) | ||
118 | } | ||
119 | |||
120 | // Add an error as single field to the log entry. All it does is call | ||
121 | // `WithError` for the given `error`. | ||
122 | func (logger *Logger) WithError(err error) *Entry { | ||
123 | entry := logger.newEntry() | ||
124 | defer logger.releaseEntry(entry) | ||
125 | return entry.WithError(err) | ||
126 | } | ||
127 | |||
128 | // Add a context to the log entry. | ||
129 | func (logger *Logger) WithContext(ctx context.Context) *Entry { | ||
130 | entry := logger.newEntry() | ||
131 | defer logger.releaseEntry(entry) | ||
132 | return entry.WithContext(ctx) | ||
133 | } | ||
134 | |||
135 | // Overrides the time of the log entry. | ||
136 | func (logger *Logger) WithTime(t time.Time) *Entry { | ||
137 | entry := logger.newEntry() | ||
138 | defer logger.releaseEntry(entry) | ||
139 | return entry.WithTime(t) | ||
140 | } | ||
141 | |||
142 | func (logger *Logger) Logf(level Level, format string, args ...interface{}) { | ||
143 | if logger.IsLevelEnabled(level) { | ||
144 | entry := logger.newEntry() | ||
145 | entry.Logf(level, format, args...) | ||
146 | logger.releaseEntry(entry) | ||
147 | } | ||
148 | } | ||
149 | |||
150 | func (logger *Logger) Tracef(format string, args ...interface{}) { | ||
151 | logger.Logf(TraceLevel, format, args...) | ||
152 | } | ||
153 | |||
154 | func (logger *Logger) Debugf(format string, args ...interface{}) { | ||
155 | logger.Logf(DebugLevel, format, args...) | ||
156 | } | ||
157 | |||
158 | func (logger *Logger) Infof(format string, args ...interface{}) { | ||
159 | logger.Logf(InfoLevel, format, args...) | ||
160 | } | ||
161 | |||
162 | func (logger *Logger) Printf(format string, args ...interface{}) { | ||
163 | entry := logger.newEntry() | ||
164 | entry.Printf(format, args...) | ||
165 | logger.releaseEntry(entry) | ||
166 | } | ||
167 | |||
168 | func (logger *Logger) Warnf(format string, args ...interface{}) { | ||
169 | logger.Logf(WarnLevel, format, args...) | ||
170 | } | ||
171 | |||
172 | func (logger *Logger) Warningf(format string, args ...interface{}) { | ||
173 | logger.Warnf(format, args...) | ||
174 | } | ||
175 | |||
176 | func (logger *Logger) Errorf(format string, args ...interface{}) { | ||
177 | logger.Logf(ErrorLevel, format, args...) | ||
178 | } | ||
179 | |||
180 | func (logger *Logger) Fatalf(format string, args ...interface{}) { | ||
181 | logger.Logf(FatalLevel, format, args...) | ||
182 | logger.Exit(1) | ||
183 | } | ||
184 | |||
185 | func (logger *Logger) Panicf(format string, args ...interface{}) { | ||
186 | logger.Logf(PanicLevel, format, args...) | ||
187 | } | ||
188 | |||
189 | func (logger *Logger) Log(level Level, args ...interface{}) { | ||
190 | if logger.IsLevelEnabled(level) { | ||
191 | entry := logger.newEntry() | ||
192 | entry.Log(level, args...) | ||
193 | logger.releaseEntry(entry) | ||
194 | } | ||
195 | } | ||
196 | |||
197 | func (logger *Logger) Trace(args ...interface{}) { | ||
198 | logger.Log(TraceLevel, args...) | ||
199 | } | ||
200 | |||
201 | func (logger *Logger) Debug(args ...interface{}) { | ||
202 | logger.Log(DebugLevel, args...) | ||
203 | } | ||
204 | |||
205 | func (logger *Logger) Info(args ...interface{}) { | ||
206 | logger.Log(InfoLevel, args...) | ||
207 | } | ||
208 | |||
209 | func (logger *Logger) Print(args ...interface{}) { | ||
210 | entry := logger.newEntry() | ||
211 | entry.Print(args...) | ||
212 | logger.releaseEntry(entry) | ||
213 | } | ||
214 | |||
215 | func (logger *Logger) Warn(args ...interface{}) { | ||
216 | logger.Log(WarnLevel, args...) | ||
217 | } | ||
218 | |||
219 | func (logger *Logger) Warning(args ...interface{}) { | ||
220 | logger.Warn(args...) | ||
221 | } | ||
222 | |||
223 | func (logger *Logger) Error(args ...interface{}) { | ||
224 | logger.Log(ErrorLevel, args...) | ||
225 | } | ||
226 | |||
227 | func (logger *Logger) Fatal(args ...interface{}) { | ||
228 | logger.Log(FatalLevel, args...) | ||
229 | logger.Exit(1) | ||
230 | } | ||
231 | |||
232 | func (logger *Logger) Panic(args ...interface{}) { | ||
233 | logger.Log(PanicLevel, args...) | ||
234 | } | ||
235 | |||
236 | func (logger *Logger) Logln(level Level, args ...interface{}) { | ||
237 | if logger.IsLevelEnabled(level) { | ||
238 | entry := logger.newEntry() | ||
239 | entry.Logln(level, args...) | ||
240 | logger.releaseEntry(entry) | ||
241 | } | ||
242 | } | ||
243 | |||
244 | func (logger *Logger) Traceln(args ...interface{}) { | ||
245 | logger.Logln(TraceLevel, args...) | ||
246 | } | ||
247 | |||
248 | func (logger *Logger) Debugln(args ...interface{}) { | ||
249 | logger.Logln(DebugLevel, args...) | ||
250 | } | ||
251 | |||
252 | func (logger *Logger) Infoln(args ...interface{}) { | ||
253 | logger.Logln(InfoLevel, args...) | ||
254 | } | ||
255 | |||
256 | func (logger *Logger) Println(args ...interface{}) { | ||
257 | entry := logger.newEntry() | ||
258 | entry.Println(args...) | ||
259 | logger.releaseEntry(entry) | ||
260 | } | ||
261 | |||
262 | func (logger *Logger) Warnln(args ...interface{}) { | ||
263 | logger.Logln(WarnLevel, args...) | ||
264 | } | ||
265 | |||
266 | func (logger *Logger) Warningln(args ...interface{}) { | ||
267 | logger.Warnln(args...) | ||
268 | } | ||
269 | |||
270 | func (logger *Logger) Errorln(args ...interface{}) { | ||
271 | logger.Logln(ErrorLevel, args...) | ||
272 | } | ||
273 | |||
274 | func (logger *Logger) Fatalln(args ...interface{}) { | ||
275 | logger.Logln(FatalLevel, args...) | ||
276 | logger.Exit(1) | ||
277 | } | ||
278 | |||
279 | func (logger *Logger) Panicln(args ...interface{}) { | ||
280 | logger.Logln(PanicLevel, args...) | ||
281 | } | ||
282 | |||
283 | func (logger *Logger) Exit(code int) { | ||
284 | runHandlers() | ||
285 | if logger.ExitFunc == nil { | ||
286 | logger.ExitFunc = os.Exit | ||
287 | } | ||
288 | logger.ExitFunc(code) | ||
289 | } | ||
290 | |||
291 | //When file is opened with appending mode, it's safe to | ||
292 | //write concurrently to a file (within 4k message on Linux). | ||
293 | //In these cases user can choose to disable the lock. | ||
294 | func (logger *Logger) SetNoLock() { | ||
295 | logger.mu.Disable() | ||
296 | } | ||
297 | |||
298 | func (logger *Logger) level() Level { | ||
299 | return Level(atomic.LoadUint32((*uint32)(&logger.Level))) | ||
300 | } | ||
301 | |||
302 | // SetLevel sets the logger level. | ||
303 | func (logger *Logger) SetLevel(level Level) { | ||
304 | atomic.StoreUint32((*uint32)(&logger.Level), uint32(level)) | ||
305 | } | ||
306 | |||
307 | // GetLevel returns the logger level. | ||
308 | func (logger *Logger) GetLevel() Level { | ||
309 | return logger.level() | ||
310 | } | ||
311 | |||
312 | // AddHook adds a hook to the logger hooks. | ||
313 | func (logger *Logger) AddHook(hook Hook) { | ||
314 | logger.mu.Lock() | ||
315 | defer logger.mu.Unlock() | ||
316 | logger.Hooks.Add(hook) | ||
317 | } | ||
318 | |||
319 | // IsLevelEnabled checks if the log level of the logger is greater than the level param | ||
320 | func (logger *Logger) IsLevelEnabled(level Level) bool { | ||
321 | return logger.level() >= level | ||
322 | } | ||
323 | |||
324 | // SetFormatter sets the logger formatter. | ||
325 | func (logger *Logger) SetFormatter(formatter Formatter) { | ||
326 | logger.mu.Lock() | ||
327 | defer logger.mu.Unlock() | ||
328 | logger.Formatter = formatter | ||
329 | } | ||
330 | |||
331 | // SetOutput sets the logger output. | ||
332 | func (logger *Logger) SetOutput(output io.Writer) { | ||
333 | logger.mu.Lock() | ||
334 | defer logger.mu.Unlock() | ||
335 | logger.Out = output | ||
336 | } | ||
337 | |||
338 | func (logger *Logger) SetReportCaller(reportCaller bool) { | ||
339 | logger.mu.Lock() | ||
340 | defer logger.mu.Unlock() | ||
341 | logger.ReportCaller = reportCaller | ||
342 | } | ||
343 | |||
344 | // ReplaceHooks replaces the logger hooks and returns the old ones | ||
345 | func (logger *Logger) ReplaceHooks(hooks LevelHooks) LevelHooks { | ||
346 | logger.mu.Lock() | ||
347 | oldHooks := logger.Hooks | ||
348 | logger.Hooks = hooks | ||
349 | logger.mu.Unlock() | ||
350 | return oldHooks | ||
351 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/logrus.go b/vendor/github.com/sirupsen/logrus/logrus.go deleted file mode 100644 index 8644761..0000000 --- a/vendor/github.com/sirupsen/logrus/logrus.go +++ /dev/null | |||
@@ -1,186 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "log" | ||
6 | "strings" | ||
7 | ) | ||
8 | |||
9 | // Fields type, used to pass to `WithFields`. | ||
10 | type Fields map[string]interface{} | ||
11 | |||
12 | // Level type | ||
13 | type Level uint32 | ||
14 | |||
15 | // Convert the Level to a string. E.g. PanicLevel becomes "panic". | ||
16 | func (level Level) String() string { | ||
17 | if b, err := level.MarshalText(); err == nil { | ||
18 | return string(b) | ||
19 | } else { | ||
20 | return "unknown" | ||
21 | } | ||
22 | } | ||
23 | |||
24 | // ParseLevel takes a string level and returns the Logrus log level constant. | ||
25 | func ParseLevel(lvl string) (Level, error) { | ||
26 | switch strings.ToLower(lvl) { | ||
27 | case "panic": | ||
28 | return PanicLevel, nil | ||
29 | case "fatal": | ||
30 | return FatalLevel, nil | ||
31 | case "error": | ||
32 | return ErrorLevel, nil | ||
33 | case "warn", "warning": | ||
34 | return WarnLevel, nil | ||
35 | case "info": | ||
36 | return InfoLevel, nil | ||
37 | case "debug": | ||
38 | return DebugLevel, nil | ||
39 | case "trace": | ||
40 | return TraceLevel, nil | ||
41 | } | ||
42 | |||
43 | var l Level | ||
44 | return l, fmt.Errorf("not a valid logrus Level: %q", lvl) | ||
45 | } | ||
46 | |||
47 | // UnmarshalText implements encoding.TextUnmarshaler. | ||
48 | func (level *Level) UnmarshalText(text []byte) error { | ||
49 | l, err := ParseLevel(string(text)) | ||
50 | if err != nil { | ||
51 | return err | ||
52 | } | ||
53 | |||
54 | *level = Level(l) | ||
55 | |||
56 | return nil | ||
57 | } | ||
58 | |||
59 | func (level Level) MarshalText() ([]byte, error) { | ||
60 | switch level { | ||
61 | case TraceLevel: | ||
62 | return []byte("trace"), nil | ||
63 | case DebugLevel: | ||
64 | return []byte("debug"), nil | ||
65 | case InfoLevel: | ||
66 | return []byte("info"), nil | ||
67 | case WarnLevel: | ||
68 | return []byte("warning"), nil | ||
69 | case ErrorLevel: | ||
70 | return []byte("error"), nil | ||
71 | case FatalLevel: | ||
72 | return []byte("fatal"), nil | ||
73 | case PanicLevel: | ||
74 | return []byte("panic"), nil | ||
75 | } | ||
76 | |||
77 | return nil, fmt.Errorf("not a valid logrus level %d", level) | ||
78 | } | ||
79 | |||
80 | // A constant exposing all logging levels | ||
81 | var AllLevels = []Level{ | ||
82 | PanicLevel, | ||
83 | FatalLevel, | ||
84 | ErrorLevel, | ||
85 | WarnLevel, | ||
86 | InfoLevel, | ||
87 | DebugLevel, | ||
88 | TraceLevel, | ||
89 | } | ||
90 | |||
91 | // These are the different logging levels. You can set the logging level to log | ||
92 | // on your instance of logger, obtained with `logrus.New()`. | ||
93 | const ( | ||
94 | // PanicLevel level, highest level of severity. Logs and then calls panic with the | ||
95 | // message passed to Debug, Info, ... | ||
96 | PanicLevel Level = iota | ||
97 | // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the | ||
98 | // logging level is set to Panic. | ||
99 | FatalLevel | ||
100 | // ErrorLevel level. Logs. Used for errors that should definitely be noted. | ||
101 | // Commonly used for hooks to send errors to an error tracking service. | ||
102 | ErrorLevel | ||
103 | // WarnLevel level. Non-critical entries that deserve eyes. | ||
104 | WarnLevel | ||
105 | // InfoLevel level. General operational entries about what's going on inside the | ||
106 | // application. | ||
107 | InfoLevel | ||
108 | // DebugLevel level. Usually only enabled when debugging. Very verbose logging. | ||
109 | DebugLevel | ||
110 | // TraceLevel level. Designates finer-grained informational events than the Debug. | ||
111 | TraceLevel | ||
112 | ) | ||
113 | |||
114 | // Won't compile if StdLogger can't be realized by a log.Logger | ||
115 | var ( | ||
116 | _ StdLogger = &log.Logger{} | ||
117 | _ StdLogger = &Entry{} | ||
118 | _ StdLogger = &Logger{} | ||
119 | ) | ||
120 | |||
121 | // StdLogger is what your logrus-enabled library should take, that way | ||
122 | // it'll accept a stdlib logger and a logrus logger. There's no standard | ||
123 | // interface, this is the closest we get, unfortunately. | ||
124 | type StdLogger interface { | ||
125 | Print(...interface{}) | ||
126 | Printf(string, ...interface{}) | ||
127 | Println(...interface{}) | ||
128 | |||
129 | Fatal(...interface{}) | ||
130 | Fatalf(string, ...interface{}) | ||
131 | Fatalln(...interface{}) | ||
132 | |||
133 | Panic(...interface{}) | ||
134 | Panicf(string, ...interface{}) | ||
135 | Panicln(...interface{}) | ||
136 | } | ||
137 | |||
138 | // The FieldLogger interface generalizes the Entry and Logger types | ||
139 | type FieldLogger interface { | ||
140 | WithField(key string, value interface{}) *Entry | ||
141 | WithFields(fields Fields) *Entry | ||
142 | WithError(err error) *Entry | ||
143 | |||
144 | Debugf(format string, args ...interface{}) | ||
145 | Infof(format string, args ...interface{}) | ||
146 | Printf(format string, args ...interface{}) | ||
147 | Warnf(format string, args ...interface{}) | ||
148 | Warningf(format string, args ...interface{}) | ||
149 | Errorf(format string, args ...interface{}) | ||
150 | Fatalf(format string, args ...interface{}) | ||
151 | Panicf(format string, args ...interface{}) | ||
152 | |||
153 | Debug(args ...interface{}) | ||
154 | Info(args ...interface{}) | ||
155 | Print(args ...interface{}) | ||
156 | Warn(args ...interface{}) | ||
157 | Warning(args ...interface{}) | ||
158 | Error(args ...interface{}) | ||
159 | Fatal(args ...interface{}) | ||
160 | Panic(args ...interface{}) | ||
161 | |||
162 | Debugln(args ...interface{}) | ||
163 | Infoln(args ...interface{}) | ||
164 | Println(args ...interface{}) | ||
165 | Warnln(args ...interface{}) | ||
166 | Warningln(args ...interface{}) | ||
167 | Errorln(args ...interface{}) | ||
168 | Fatalln(args ...interface{}) | ||
169 | Panicln(args ...interface{}) | ||
170 | |||
171 | // IsDebugEnabled() bool | ||
172 | // IsInfoEnabled() bool | ||
173 | // IsWarnEnabled() bool | ||
174 | // IsErrorEnabled() bool | ||
175 | // IsFatalEnabled() bool | ||
176 | // IsPanicEnabled() bool | ||
177 | } | ||
178 | |||
179 | // Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is | ||
180 | // here for consistancy. Do not use. Use Logger or Entry instead. | ||
181 | type Ext1FieldLogger interface { | ||
182 | FieldLogger | ||
183 | Tracef(format string, args ...interface{}) | ||
184 | Trace(args ...interface{}) | ||
185 | Traceln(args ...interface{}) | ||
186 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go b/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go deleted file mode 100644 index 2403de9..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | // +build appengine | ||
2 | |||
3 | package logrus | ||
4 | |||
5 | import ( | ||
6 | "io" | ||
7 | ) | ||
8 | |||
9 | func checkIfTerminal(w io.Writer) bool { | ||
10 | return true | ||
11 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go b/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go deleted file mode 100644 index 3c4f43f..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | // +build darwin dragonfly freebsd netbsd openbsd | ||
2 | |||
3 | package logrus | ||
4 | |||
5 | import "golang.org/x/sys/unix" | ||
6 | |||
7 | const ioctlReadTermios = unix.TIOCGETA | ||
8 | |||
9 | func isTerminal(fd int) bool { | ||
10 | _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) | ||
11 | return err == nil | ||
12 | } | ||
13 | |||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go b/vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go deleted file mode 100644 index 97af92c..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | // +build js nacl plan9 | ||
2 | |||
3 | package logrus | ||
4 | |||
5 | import ( | ||
6 | "io" | ||
7 | ) | ||
8 | |||
9 | func checkIfTerminal(w io.Writer) bool { | ||
10 | return false | ||
11 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go b/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go deleted file mode 100644 index 3293fb3..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | // +build !appengine,!js,!windows,!nacl,!plan9 | ||
2 | |||
3 | package logrus | ||
4 | |||
5 | import ( | ||
6 | "io" | ||
7 | "os" | ||
8 | ) | ||
9 | |||
10 | func checkIfTerminal(w io.Writer) bool { | ||
11 | switch v := w.(type) { | ||
12 | case *os.File: | ||
13 | return isTerminal(int(v.Fd())) | ||
14 | default: | ||
15 | return false | ||
16 | } | ||
17 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_solaris.go b/vendor/github.com/sirupsen/logrus/terminal_check_solaris.go deleted file mode 100644 index f6710b3..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_solaris.go +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "golang.org/x/sys/unix" | ||
5 | ) | ||
6 | |||
7 | // IsTerminal returns true if the given file descriptor is a terminal. | ||
8 | func isTerminal(fd int) bool { | ||
9 | _, err := unix.IoctlGetTermio(fd, unix.TCGETA) | ||
10 | return err == nil | ||
11 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_unix.go b/vendor/github.com/sirupsen/logrus/terminal_check_unix.go deleted file mode 100644 index 355dc96..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_unix.go +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | // +build linux aix | ||
2 | |||
3 | package logrus | ||
4 | |||
5 | import "golang.org/x/sys/unix" | ||
6 | |||
7 | const ioctlReadTermios = unix.TCGETS | ||
8 | |||
9 | func isTerminal(fd int) bool { | ||
10 | _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) | ||
11 | return err == nil | ||
12 | } | ||
13 | |||
diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_windows.go b/vendor/github.com/sirupsen/logrus/terminal_check_windows.go deleted file mode 100644 index 572889d..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_windows.go +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | // +build !appengine,!js,windows | ||
2 | |||
3 | package logrus | ||
4 | |||
5 | import ( | ||
6 | "io" | ||
7 | "os" | ||
8 | "syscall" | ||
9 | |||
10 | sequences "github.com/konsorten/go-windows-terminal-sequences" | ||
11 | ) | ||
12 | |||
13 | func initTerminal(w io.Writer) { | ||
14 | switch v := w.(type) { | ||
15 | case *os.File: | ||
16 | sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true) | ||
17 | } | ||
18 | } | ||
19 | |||
20 | func checkIfTerminal(w io.Writer) bool { | ||
21 | var ret bool | ||
22 | switch v := w.(type) { | ||
23 | case *os.File: | ||
24 | var mode uint32 | ||
25 | err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode) | ||
26 | ret = (err == nil) | ||
27 | default: | ||
28 | ret = false | ||
29 | } | ||
30 | if ret { | ||
31 | initTerminal(w) | ||
32 | } | ||
33 | return ret | ||
34 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/text_formatter.go b/vendor/github.com/sirupsen/logrus/text_formatter.go deleted file mode 100644 index e01587c..0000000 --- a/vendor/github.com/sirupsen/logrus/text_formatter.go +++ /dev/null | |||
@@ -1,295 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "fmt" | ||
6 | "os" | ||
7 | "runtime" | ||
8 | "sort" | ||
9 | "strings" | ||
10 | "sync" | ||
11 | "time" | ||
12 | ) | ||
13 | |||
14 | const ( | ||
15 | red = 31 | ||
16 | yellow = 33 | ||
17 | blue = 36 | ||
18 | gray = 37 | ||
19 | ) | ||
20 | |||
21 | var baseTimestamp time.Time | ||
22 | |||
23 | func init() { | ||
24 | baseTimestamp = time.Now() | ||
25 | } | ||
26 | |||
27 | // TextFormatter formats logs into text | ||
28 | type TextFormatter struct { | ||
29 | // Set to true to bypass checking for a TTY before outputting colors. | ||
30 | ForceColors bool | ||
31 | |||
32 | // Force disabling colors. | ||
33 | DisableColors bool | ||
34 | |||
35 | // Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/ | ||
36 | EnvironmentOverrideColors bool | ||
37 | |||
38 | // Disable timestamp logging. useful when output is redirected to logging | ||
39 | // system that already adds timestamps. | ||
40 | DisableTimestamp bool | ||
41 | |||
42 | // Enable logging the full timestamp when a TTY is attached instead of just | ||
43 | // the time passed since beginning of execution. | ||
44 | FullTimestamp bool | ||
45 | |||
46 | // TimestampFormat to use for display when a full timestamp is printed | ||
47 | TimestampFormat string | ||
48 | |||
49 | // The fields are sorted by default for a consistent output. For applications | ||
50 | // that log extremely frequently and don't use the JSON formatter this may not | ||
51 | // be desired. | ||
52 | DisableSorting bool | ||
53 | |||
54 | // The keys sorting function, when uninitialized it uses sort.Strings. | ||
55 | SortingFunc func([]string) | ||
56 | |||
57 | // Disables the truncation of the level text to 4 characters. | ||
58 | DisableLevelTruncation bool | ||
59 | |||
60 | // QuoteEmptyFields will wrap empty fields in quotes if true | ||
61 | QuoteEmptyFields bool | ||
62 | |||
63 | // Whether the logger's out is to a terminal | ||
64 | isTerminal bool | ||
65 | |||
66 | // FieldMap allows users to customize the names of keys for default fields. | ||
67 | // As an example: | ||
68 | // formatter := &TextFormatter{ | ||
69 | // FieldMap: FieldMap{ | ||
70 | // FieldKeyTime: "@timestamp", | ||
71 | // FieldKeyLevel: "@level", | ||
72 | // FieldKeyMsg: "@message"}} | ||
73 | FieldMap FieldMap | ||
74 | |||
75 | // CallerPrettyfier can be set by the user to modify the content | ||
76 | // of the function and file keys in the data when ReportCaller is | ||
77 | // activated. If any of the returned value is the empty string the | ||
78 | // corresponding key will be removed from fields. | ||
79 | CallerPrettyfier func(*runtime.Frame) (function string, file string) | ||
80 | |||
81 | terminalInitOnce sync.Once | ||
82 | } | ||
83 | |||
84 | func (f *TextFormatter) init(entry *Entry) { | ||
85 | if entry.Logger != nil { | ||
86 | f.isTerminal = checkIfTerminal(entry.Logger.Out) | ||
87 | } | ||
88 | } | ||
89 | |||
90 | func (f *TextFormatter) isColored() bool { | ||
91 | isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows")) | ||
92 | |||
93 | if f.EnvironmentOverrideColors { | ||
94 | if force, ok := os.LookupEnv("CLICOLOR_FORCE"); ok && force != "0" { | ||
95 | isColored = true | ||
96 | } else if ok && force == "0" { | ||
97 | isColored = false | ||
98 | } else if os.Getenv("CLICOLOR") == "0" { | ||
99 | isColored = false | ||
100 | } | ||
101 | } | ||
102 | |||
103 | return isColored && !f.DisableColors | ||
104 | } | ||
105 | |||
106 | // Format renders a single log entry | ||
107 | func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { | ||
108 | data := make(Fields) | ||
109 | for k, v := range entry.Data { | ||
110 | data[k] = v | ||
111 | } | ||
112 | prefixFieldClashes(data, f.FieldMap, entry.HasCaller()) | ||
113 | keys := make([]string, 0, len(data)) | ||
114 | for k := range data { | ||
115 | keys = append(keys, k) | ||
116 | } | ||
117 | |||
118 | var funcVal, fileVal string | ||
119 | |||
120 | fixedKeys := make([]string, 0, 4+len(data)) | ||
121 | if !f.DisableTimestamp { | ||
122 | fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyTime)) | ||
123 | } | ||
124 | fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyLevel)) | ||
125 | if entry.Message != "" { | ||
126 | fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyMsg)) | ||
127 | } | ||
128 | if entry.err != "" { | ||
129 | fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyLogrusError)) | ||
130 | } | ||
131 | if entry.HasCaller() { | ||
132 | if f.CallerPrettyfier != nil { | ||
133 | funcVal, fileVal = f.CallerPrettyfier(entry.Caller) | ||
134 | } else { | ||
135 | funcVal = entry.Caller.Function | ||
136 | fileVal = fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) | ||
137 | } | ||
138 | |||
139 | if funcVal != "" { | ||
140 | fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyFunc)) | ||
141 | } | ||
142 | if fileVal != "" { | ||
143 | fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyFile)) | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if !f.DisableSorting { | ||
148 | if f.SortingFunc == nil { | ||
149 | sort.Strings(keys) | ||
150 | fixedKeys = append(fixedKeys, keys...) | ||
151 | } else { | ||
152 | if !f.isColored() { | ||
153 | fixedKeys = append(fixedKeys, keys...) | ||
154 | f.SortingFunc(fixedKeys) | ||
155 | } else { | ||
156 | f.SortingFunc(keys) | ||
157 | } | ||
158 | } | ||
159 | } else { | ||
160 | fixedKeys = append(fixedKeys, keys...) | ||
161 | } | ||
162 | |||
163 | var b *bytes.Buffer | ||
164 | if entry.Buffer != nil { | ||
165 | b = entry.Buffer | ||
166 | } else { | ||
167 | b = &bytes.Buffer{} | ||
168 | } | ||
169 | |||
170 | f.terminalInitOnce.Do(func() { f.init(entry) }) | ||
171 | |||
172 | timestampFormat := f.TimestampFormat | ||
173 | if timestampFormat == "" { | ||
174 | timestampFormat = defaultTimestampFormat | ||
175 | } | ||
176 | if f.isColored() { | ||
177 | f.printColored(b, entry, keys, data, timestampFormat) | ||
178 | } else { | ||
179 | |||
180 | for _, key := range fixedKeys { | ||
181 | var value interface{} | ||
182 | switch { | ||
183 | case key == f.FieldMap.resolve(FieldKeyTime): | ||
184 | value = entry.Time.Format(timestampFormat) | ||
185 | case key == f.FieldMap.resolve(FieldKeyLevel): | ||
186 | value = entry.Level.String() | ||
187 | case key == f.FieldMap.resolve(FieldKeyMsg): | ||
188 | value = entry.Message | ||
189 | case key == f.FieldMap.resolve(FieldKeyLogrusError): | ||
190 | value = entry.err | ||
191 | case key == f.FieldMap.resolve(FieldKeyFunc) && entry.HasCaller(): | ||
192 | value = funcVal | ||
193 | case key == f.FieldMap.resolve(FieldKeyFile) && entry.HasCaller(): | ||
194 | value = fileVal | ||
195 | default: | ||
196 | value = data[key] | ||
197 | } | ||
198 | f.appendKeyValue(b, key, value) | ||
199 | } | ||
200 | } | ||
201 | |||
202 | b.WriteByte('\n') | ||
203 | return b.Bytes(), nil | ||
204 | } | ||
205 | |||
206 | func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, data Fields, timestampFormat string) { | ||
207 | var levelColor int | ||
208 | switch entry.Level { | ||
209 | case DebugLevel, TraceLevel: | ||
210 | levelColor = gray | ||
211 | case WarnLevel: | ||
212 | levelColor = yellow | ||
213 | case ErrorLevel, FatalLevel, PanicLevel: | ||
214 | levelColor = red | ||
215 | default: | ||
216 | levelColor = blue | ||
217 | } | ||
218 | |||
219 | levelText := strings.ToUpper(entry.Level.String()) | ||
220 | if !f.DisableLevelTruncation { | ||
221 | levelText = levelText[0:4] | ||
222 | } | ||
223 | |||
224 | // Remove a single newline if it already exists in the message to keep | ||
225 | // the behavior of logrus text_formatter the same as the stdlib log package | ||
226 | entry.Message = strings.TrimSuffix(entry.Message, "\n") | ||
227 | |||
228 | caller := "" | ||
229 | if entry.HasCaller() { | ||
230 | funcVal := fmt.Sprintf("%s()", entry.Caller.Function) | ||
231 | fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) | ||
232 | |||
233 | if f.CallerPrettyfier != nil { | ||
234 | funcVal, fileVal = f.CallerPrettyfier(entry.Caller) | ||
235 | } | ||
236 | |||
237 | if fileVal == "" { | ||
238 | caller = funcVal | ||
239 | } else if funcVal == "" { | ||
240 | caller = fileVal | ||
241 | } else { | ||
242 | caller = fileVal + " " + funcVal | ||
243 | } | ||
244 | } | ||
245 | |||
246 | if f.DisableTimestamp { | ||
247 | fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m%s %-44s ", levelColor, levelText, caller, entry.Message) | ||
248 | } else if !f.FullTimestamp { | ||
249 | fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d]%s %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), caller, entry.Message) | ||
250 | } else { | ||
251 | fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]%s %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), caller, entry.Message) | ||
252 | } | ||
253 | for _, k := range keys { | ||
254 | v := data[k] | ||
255 | fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k) | ||
256 | f.appendValue(b, v) | ||
257 | } | ||
258 | } | ||
259 | |||
260 | func (f *TextFormatter) needsQuoting(text string) bool { | ||
261 | if f.QuoteEmptyFields && len(text) == 0 { | ||
262 | return true | ||
263 | } | ||
264 | for _, ch := range text { | ||
265 | if !((ch >= 'a' && ch <= 'z') || | ||
266 | (ch >= 'A' && ch <= 'Z') || | ||
267 | (ch >= '0' && ch <= '9') || | ||
268 | ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') { | ||
269 | return true | ||
270 | } | ||
271 | } | ||
272 | return false | ||
273 | } | ||
274 | |||
275 | func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { | ||
276 | if b.Len() > 0 { | ||
277 | b.WriteByte(' ') | ||
278 | } | ||
279 | b.WriteString(key) | ||
280 | b.WriteByte('=') | ||
281 | f.appendValue(b, value) | ||
282 | } | ||
283 | |||
284 | func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { | ||
285 | stringVal, ok := value.(string) | ||
286 | if !ok { | ||
287 | stringVal = fmt.Sprint(value) | ||
288 | } | ||
289 | |||
290 | if !f.needsQuoting(stringVal) { | ||
291 | b.WriteString(stringVal) | ||
292 | } else { | ||
293 | b.WriteString(fmt.Sprintf("%q", stringVal)) | ||
294 | } | ||
295 | } | ||
diff --git a/vendor/github.com/sirupsen/logrus/writer.go b/vendor/github.com/sirupsen/logrus/writer.go deleted file mode 100644 index 9e1f751..0000000 --- a/vendor/github.com/sirupsen/logrus/writer.go +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | package logrus | ||
2 | |||
3 | import ( | ||
4 | "bufio" | ||
5 | "io" | ||
6 | "runtime" | ||
7 | ) | ||
8 | |||
9 | func (logger *Logger) Writer() *io.PipeWriter { | ||
10 | return logger.WriterLevel(InfoLevel) | ||
11 | } | ||
12 | |||
13 | func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { | ||
14 | return NewEntry(logger).WriterLevel(level) | ||
15 | } | ||
16 | |||
17 | func (entry *Entry) Writer() *io.PipeWriter { | ||
18 | return entry.WriterLevel(InfoLevel) | ||
19 | } | ||
20 | |||
21 | func (entry *Entry) WriterLevel(level Level) *io.PipeWriter { | ||
22 | reader, writer := io.Pipe() | ||
23 | |||
24 | var printFunc func(args ...interface{}) | ||
25 | |||
26 | switch level { | ||
27 | case TraceLevel: | ||
28 | printFunc = entry.Trace | ||
29 | case DebugLevel: | ||
30 | printFunc = entry.Debug | ||
31 | case InfoLevel: | ||
32 | printFunc = entry.Info | ||
33 | case WarnLevel: | ||
34 | printFunc = entry.Warn | ||
35 | case ErrorLevel: | ||
36 | printFunc = entry.Error | ||
37 | case FatalLevel: | ||
38 | printFunc = entry.Fatal | ||
39 | case PanicLevel: | ||
40 | printFunc = entry.Panic | ||
41 | default: | ||
42 | printFunc = entry.Print | ||
43 | } | ||
44 | |||
45 | go entry.writerScanner(reader, printFunc) | ||
46 | runtime.SetFinalizer(writer, writerFinalizer) | ||
47 | |||
48 | return writer | ||
49 | } | ||
50 | |||
51 | func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) { | ||
52 | scanner := bufio.NewScanner(reader) | ||
53 | for scanner.Scan() { | ||
54 | printFunc(scanner.Text()) | ||
55 | } | ||
56 | if err := scanner.Err(); err != nil { | ||
57 | entry.Errorf("Error while reading from Writer: %s", err) | ||
58 | } | ||
59 | reader.Close() | ||
60 | } | ||
61 | |||
62 | func writerFinalizer(writer *io.PipeWriter) { | ||
63 | writer.Close() | ||
64 | } | ||
diff --git a/vendor/golang.org/x/sys/windows/registry/key.go b/vendor/golang.org/x/sys/windows/registry/key.go deleted file mode 100644 index c256483..0000000 --- a/vendor/golang.org/x/sys/windows/registry/key.go +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | // Copyright 2015 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build windows | ||
6 | |||
7 | // Package registry provides access to the Windows registry. | ||
8 | // | ||
9 | // Here is a simple example, opening a registry key and reading a string value from it. | ||
10 | // | ||
11 | // k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) | ||
12 | // if err != nil { | ||
13 | // log.Fatal(err) | ||
14 | // } | ||
15 | // defer k.Close() | ||
16 | // | ||
17 | // s, _, err := k.GetStringValue("SystemRoot") | ||
18 | // if err != nil { | ||
19 | // log.Fatal(err) | ||
20 | // } | ||
21 | // fmt.Printf("Windows system root is %q\n", s) | ||
22 | // | ||
23 | package registry | ||
24 | |||
25 | import ( | ||
26 | "io" | ||
27 | "syscall" | ||
28 | "time" | ||
29 | ) | ||
30 | |||
31 | const ( | ||
32 | // Registry key security and access rights. | ||
33 | // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724878.aspx | ||
34 | // for details. | ||
35 | ALL_ACCESS = 0xf003f | ||
36 | CREATE_LINK = 0x00020 | ||
37 | CREATE_SUB_KEY = 0x00004 | ||
38 | ENUMERATE_SUB_KEYS = 0x00008 | ||
39 | EXECUTE = 0x20019 | ||
40 | NOTIFY = 0x00010 | ||
41 | QUERY_VALUE = 0x00001 | ||
42 | READ = 0x20019 | ||
43 | SET_VALUE = 0x00002 | ||
44 | WOW64_32KEY = 0x00200 | ||
45 | WOW64_64KEY = 0x00100 | ||
46 | WRITE = 0x20006 | ||
47 | ) | ||
48 | |||
49 | // Key is a handle to an open Windows registry key. | ||
50 | // Keys can be obtained by calling OpenKey; there are | ||
51 | // also some predefined root keys such as CURRENT_USER. | ||
52 | // Keys can be used directly in the Windows API. | ||
53 | type Key syscall.Handle | ||
54 | |||
55 | const ( | ||
56 | // Windows defines some predefined root keys that are always open. | ||
57 | // An application can use these keys as entry points to the registry. | ||
58 | // Normally these keys are used in OpenKey to open new keys, | ||
59 | // but they can also be used anywhere a Key is required. | ||
60 | CLASSES_ROOT = Key(syscall.HKEY_CLASSES_ROOT) | ||
61 | CURRENT_USER = Key(syscall.HKEY_CURRENT_USER) | ||
62 | LOCAL_MACHINE = Key(syscall.HKEY_LOCAL_MACHINE) | ||
63 | USERS = Key(syscall.HKEY_USERS) | ||
64 | CURRENT_CONFIG = Key(syscall.HKEY_CURRENT_CONFIG) | ||
65 | PERFORMANCE_DATA = Key(syscall.HKEY_PERFORMANCE_DATA) | ||
66 | ) | ||
67 | |||
68 | // Close closes open key k. | ||
69 | func (k Key) Close() error { | ||
70 | return syscall.RegCloseKey(syscall.Handle(k)) | ||
71 | } | ||
72 | |||
73 | // OpenKey opens a new key with path name relative to key k. | ||
74 | // It accepts any open key, including CURRENT_USER and others, | ||
75 | // and returns the new key and an error. | ||
76 | // The access parameter specifies desired access rights to the | ||
77 | // key to be opened. | ||
78 | func OpenKey(k Key, path string, access uint32) (Key, error) { | ||
79 | p, err := syscall.UTF16PtrFromString(path) | ||
80 | if err != nil { | ||
81 | return 0, err | ||
82 | } | ||
83 | var subkey syscall.Handle | ||
84 | err = syscall.RegOpenKeyEx(syscall.Handle(k), p, 0, access, &subkey) | ||
85 | if err != nil { | ||
86 | return 0, err | ||
87 | } | ||
88 | return Key(subkey), nil | ||
89 | } | ||
90 | |||
91 | // OpenRemoteKey opens a predefined registry key on another | ||
92 | // computer pcname. The key to be opened is specified by k, but | ||
93 | // can only be one of LOCAL_MACHINE, PERFORMANCE_DATA or USERS. | ||
94 | // If pcname is "", OpenRemoteKey returns local computer key. | ||
95 | func OpenRemoteKey(pcname string, k Key) (Key, error) { | ||
96 | var err error | ||
97 | var p *uint16 | ||
98 | if pcname != "" { | ||
99 | p, err = syscall.UTF16PtrFromString(`\\` + pcname) | ||
100 | if err != nil { | ||
101 | return 0, err | ||
102 | } | ||
103 | } | ||
104 | var remoteKey syscall.Handle | ||
105 | err = regConnectRegistry(p, syscall.Handle(k), &remoteKey) | ||
106 | if err != nil { | ||
107 | return 0, err | ||
108 | } | ||
109 | return Key(remoteKey), nil | ||
110 | } | ||
111 | |||
112 | // ReadSubKeyNames returns the names of subkeys of key k. | ||
113 | // The parameter n controls the number of returned names, | ||
114 | // analogous to the way os.File.Readdirnames works. | ||
115 | func (k Key) ReadSubKeyNames(n int) ([]string, error) { | ||
116 | names := make([]string, 0) | ||
117 | // Registry key size limit is 255 bytes and described there: | ||
118 | // https://msdn.microsoft.com/library/windows/desktop/ms724872.aspx | ||
119 | buf := make([]uint16, 256) //plus extra room for terminating zero byte | ||
120 | loopItems: | ||
121 | for i := uint32(0); ; i++ { | ||
122 | if n > 0 { | ||
123 | if len(names) == n { | ||
124 | return names, nil | ||
125 | } | ||
126 | } | ||
127 | l := uint32(len(buf)) | ||
128 | for { | ||
129 | err := syscall.RegEnumKeyEx(syscall.Handle(k), i, &buf[0], &l, nil, nil, nil, nil) | ||
130 | if err == nil { | ||
131 | break | ||
132 | } | ||
133 | if err == syscall.ERROR_MORE_DATA { | ||
134 | // Double buffer size and try again. | ||
135 | l = uint32(2 * len(buf)) | ||
136 | buf = make([]uint16, l) | ||
137 | continue | ||
138 | } | ||
139 | if err == _ERROR_NO_MORE_ITEMS { | ||
140 | break loopItems | ||
141 | } | ||
142 | return names, err | ||
143 | } | ||
144 | names = append(names, syscall.UTF16ToString(buf[:l])) | ||
145 | } | ||
146 | if n > len(names) { | ||
147 | return names, io.EOF | ||
148 | } | ||
149 | return names, nil | ||
150 | } | ||
151 | |||
152 | // CreateKey creates a key named path under open key k. | ||
153 | // CreateKey returns the new key and a boolean flag that reports | ||
154 | // whether the key already existed. | ||
155 | // The access parameter specifies the access rights for the key | ||
156 | // to be created. | ||
157 | func CreateKey(k Key, path string, access uint32) (newk Key, openedExisting bool, err error) { | ||
158 | var h syscall.Handle | ||
159 | var d uint32 | ||
160 | err = regCreateKeyEx(syscall.Handle(k), syscall.StringToUTF16Ptr(path), | ||
161 | 0, nil, _REG_OPTION_NON_VOLATILE, access, nil, &h, &d) | ||
162 | if err != nil { | ||
163 | return 0, false, err | ||
164 | } | ||
165 | return Key(h), d == _REG_OPENED_EXISTING_KEY, nil | ||
166 | } | ||
167 | |||
168 | // DeleteKey deletes the subkey path of key k and its values. | ||
169 | func DeleteKey(k Key, path string) error { | ||
170 | return regDeleteKey(syscall.Handle(k), syscall.StringToUTF16Ptr(path)) | ||
171 | } | ||
172 | |||
173 | // A KeyInfo describes the statistics of a key. It is returned by Stat. | ||
174 | type KeyInfo struct { | ||
175 | SubKeyCount uint32 | ||
176 | MaxSubKeyLen uint32 // size of the key's subkey with the longest name, in Unicode characters, not including the terminating zero byte | ||
177 | ValueCount uint32 | ||
178 | MaxValueNameLen uint32 // size of the key's longest value name, in Unicode characters, not including the terminating zero byte | ||
179 | MaxValueLen uint32 // longest data component among the key's values, in bytes | ||
180 | lastWriteTime syscall.Filetime | ||
181 | } | ||
182 | |||
183 | // ModTime returns the key's last write time. | ||
184 | func (ki *KeyInfo) ModTime() time.Time { | ||
185 | return time.Unix(0, ki.lastWriteTime.Nanoseconds()) | ||
186 | } | ||
187 | |||
188 | // Stat retrieves information about the open key k. | ||
189 | func (k Key) Stat() (*KeyInfo, error) { | ||
190 | var ki KeyInfo | ||
191 | err := syscall.RegQueryInfoKey(syscall.Handle(k), nil, nil, nil, | ||
192 | &ki.SubKeyCount, &ki.MaxSubKeyLen, nil, &ki.ValueCount, | ||
193 | &ki.MaxValueNameLen, &ki.MaxValueLen, nil, &ki.lastWriteTime) | ||
194 | if err != nil { | ||
195 | return nil, err | ||
196 | } | ||
197 | return &ki, nil | ||
198 | } | ||
diff --git a/vendor/golang.org/x/sys/windows/registry/mksyscall.go b/vendor/golang.org/x/sys/windows/registry/mksyscall.go deleted file mode 100644 index cf843ce..0000000 --- a/vendor/golang.org/x/sys/windows/registry/mksyscall.go +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | // Copyright 2015 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build generate | ||
6 | |||
7 | package registry | ||
8 | |||
9 | //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go | ||
diff --git a/vendor/golang.org/x/sys/windows/registry/syscall.go b/vendor/golang.org/x/sys/windows/registry/syscall.go deleted file mode 100644 index e66643c..0000000 --- a/vendor/golang.org/x/sys/windows/registry/syscall.go +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | // Copyright 2015 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build windows | ||
6 | |||
7 | package registry | ||
8 | |||
9 | import "syscall" | ||
10 | |||
11 | const ( | ||
12 | _REG_OPTION_NON_VOLATILE = 0 | ||
13 | |||
14 | _REG_CREATED_NEW_KEY = 1 | ||
15 | _REG_OPENED_EXISTING_KEY = 2 | ||
16 | |||
17 | _ERROR_NO_MORE_ITEMS syscall.Errno = 259 | ||
18 | ) | ||
19 | |||
20 | func LoadRegLoadMUIString() error { | ||
21 | return procRegLoadMUIStringW.Find() | ||
22 | } | ||
23 | |||
24 | //sys regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) = advapi32.RegCreateKeyExW | ||
25 | //sys regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) = advapi32.RegDeleteKeyW | ||
26 | //sys regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) = advapi32.RegSetValueExW | ||
27 | //sys regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegEnumValueW | ||
28 | //sys regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) = advapi32.RegDeleteValueW | ||
29 | //sys regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) = advapi32.RegLoadMUIStringW | ||
30 | //sys regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) = advapi32.RegConnectRegistryW | ||
31 | |||
32 | //sys expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) = kernel32.ExpandEnvironmentStringsW | ||
diff --git a/vendor/golang.org/x/sys/windows/registry/value.go b/vendor/golang.org/x/sys/windows/registry/value.go deleted file mode 100644 index 7487e05..0000000 --- a/vendor/golang.org/x/sys/windows/registry/value.go +++ /dev/null | |||
@@ -1,387 +0,0 @@ | |||
1 | // Copyright 2015 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build windows | ||
6 | |||
7 | package registry | ||
8 | |||
9 | import ( | ||
10 | "errors" | ||
11 | "io" | ||
12 | "syscall" | ||
13 | "unicode/utf16" | ||
14 | "unsafe" | ||
15 | ) | ||
16 | |||
17 | const ( | ||
18 | // Registry value types. | ||
19 | NONE = 0 | ||
20 | SZ = 1 | ||
21 | EXPAND_SZ = 2 | ||
22 | BINARY = 3 | ||
23 | DWORD = 4 | ||
24 | DWORD_BIG_ENDIAN = 5 | ||
25 | LINK = 6 | ||
26 | MULTI_SZ = 7 | ||
27 | RESOURCE_LIST = 8 | ||
28 | FULL_RESOURCE_DESCRIPTOR = 9 | ||
29 | RESOURCE_REQUIREMENTS_LIST = 10 | ||
30 | QWORD = 11 | ||
31 | ) | ||
32 | |||
33 | var ( | ||
34 | // ErrShortBuffer is returned when the buffer was too short for the operation. | ||
35 | ErrShortBuffer = syscall.ERROR_MORE_DATA | ||
36 | |||
37 | // ErrNotExist is returned when a registry key or value does not exist. | ||
38 | ErrNotExist = syscall.ERROR_FILE_NOT_FOUND | ||
39 | |||
40 | // ErrUnexpectedType is returned by Get*Value when the value's type was unexpected. | ||
41 | ErrUnexpectedType = errors.New("unexpected key value type") | ||
42 | ) | ||
43 | |||
44 | // GetValue retrieves the type and data for the specified value associated | ||
45 | // with an open key k. It fills up buffer buf and returns the retrieved | ||
46 | // byte count n. If buf is too small to fit the stored value it returns | ||
47 | // ErrShortBuffer error along with the required buffer size n. | ||
48 | // If no buffer is provided, it returns true and actual buffer size n. | ||
49 | // If no buffer is provided, GetValue returns the value's type only. | ||
50 | // If the value does not exist, the error returned is ErrNotExist. | ||
51 | // | ||
52 | // GetValue is a low level function. If value's type is known, use the appropriate | ||
53 | // Get*Value function instead. | ||
54 | func (k Key) GetValue(name string, buf []byte) (n int, valtype uint32, err error) { | ||
55 | pname, err := syscall.UTF16PtrFromString(name) | ||
56 | if err != nil { | ||
57 | return 0, 0, err | ||
58 | } | ||
59 | var pbuf *byte | ||
60 | if len(buf) > 0 { | ||
61 | pbuf = (*byte)(unsafe.Pointer(&buf[0])) | ||
62 | } | ||
63 | l := uint32(len(buf)) | ||
64 | err = syscall.RegQueryValueEx(syscall.Handle(k), pname, nil, &valtype, pbuf, &l) | ||
65 | if err != nil { | ||
66 | return int(l), valtype, err | ||
67 | } | ||
68 | return int(l), valtype, nil | ||
69 | } | ||
70 | |||
71 | func (k Key) getValue(name string, buf []byte) (data []byte, valtype uint32, err error) { | ||
72 | p, err := syscall.UTF16PtrFromString(name) | ||
73 | if err != nil { | ||
74 | return nil, 0, err | ||
75 | } | ||
76 | var t uint32 | ||
77 | n := uint32(len(buf)) | ||
78 | for { | ||
79 | err = syscall.RegQueryValueEx(syscall.Handle(k), p, nil, &t, (*byte)(unsafe.Pointer(&buf[0])), &n) | ||
80 | if err == nil { | ||
81 | return buf[:n], t, nil | ||
82 | } | ||
83 | if err != syscall.ERROR_MORE_DATA { | ||
84 | return nil, 0, err | ||
85 | } | ||
86 | if n <= uint32(len(buf)) { | ||
87 | return nil, 0, err | ||
88 | } | ||
89 | buf = make([]byte, n) | ||
90 | } | ||
91 | } | ||
92 | |||
93 | // GetStringValue retrieves the string value for the specified | ||
94 | // value name associated with an open key k. It also returns the value's type. | ||
95 | // If value does not exist, GetStringValue returns ErrNotExist. | ||
96 | // If value is not SZ or EXPAND_SZ, it will return the correct value | ||
97 | // type and ErrUnexpectedType. | ||
98 | func (k Key) GetStringValue(name string) (val string, valtype uint32, err error) { | ||
99 | data, typ, err2 := k.getValue(name, make([]byte, 64)) | ||
100 | if err2 != nil { | ||
101 | return "", typ, err2 | ||
102 | } | ||
103 | switch typ { | ||
104 | case SZ, EXPAND_SZ: | ||
105 | default: | ||
106 | return "", typ, ErrUnexpectedType | ||
107 | } | ||
108 | if len(data) == 0 { | ||
109 | return "", typ, nil | ||
110 | } | ||
111 | u := (*[1 << 29]uint16)(unsafe.Pointer(&data[0]))[:] | ||
112 | return syscall.UTF16ToString(u), typ, nil | ||
113 | } | ||
114 | |||
115 | // GetMUIStringValue retrieves the localized string value for | ||
116 | // the specified value name associated with an open key k. | ||
117 | // If the value name doesn't exist or the localized string value | ||
118 | // can't be resolved, GetMUIStringValue returns ErrNotExist. | ||
119 | // GetMUIStringValue panics if the system doesn't support | ||
120 | // regLoadMUIString; use LoadRegLoadMUIString to check if | ||
121 | // regLoadMUIString is supported before calling this function. | ||
122 | func (k Key) GetMUIStringValue(name string) (string, error) { | ||
123 | pname, err := syscall.UTF16PtrFromString(name) | ||
124 | if err != nil { | ||
125 | return "", err | ||
126 | } | ||
127 | |||
128 | buf := make([]uint16, 1024) | ||
129 | var buflen uint32 | ||
130 | var pdir *uint16 | ||
131 | |||
132 | err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir) | ||
133 | if err == syscall.ERROR_FILE_NOT_FOUND { // Try fallback path | ||
134 | |||
135 | // Try to resolve the string value using the system directory as | ||
136 | // a DLL search path; this assumes the string value is of the form | ||
137 | // @[path]\dllname,-strID but with no path given, e.g. @tzres.dll,-320. | ||
138 | |||
139 | // This approach works with tzres.dll but may have to be revised | ||
140 | // in the future to allow callers to provide custom search paths. | ||
141 | |||
142 | var s string | ||
143 | s, err = ExpandString("%SystemRoot%\\system32\\") | ||
144 | if err != nil { | ||
145 | return "", err | ||
146 | } | ||
147 | pdir, err = syscall.UTF16PtrFromString(s) | ||
148 | if err != nil { | ||
149 | return "", err | ||
150 | } | ||
151 | |||
152 | err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir) | ||
153 | } | ||
154 | |||
155 | for err == syscall.ERROR_MORE_DATA { // Grow buffer if needed | ||
156 | if buflen <= uint32(len(buf)) { | ||
157 | break // Buffer not growing, assume race; break | ||
158 | } | ||
159 | buf = make([]uint16, buflen) | ||
160 | err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir) | ||
161 | } | ||
162 | |||
163 | if err != nil { | ||
164 | return "", err | ||
165 | } | ||
166 | |||
167 | return syscall.UTF16ToString(buf), nil | ||
168 | } | ||
169 | |||
170 | // ExpandString expands environment-variable strings and replaces | ||
171 | // them with the values defined for the current user. | ||
172 | // Use ExpandString to expand EXPAND_SZ strings. | ||
173 | func ExpandString(value string) (string, error) { | ||
174 | if value == "" { | ||
175 | return "", nil | ||
176 | } | ||
177 | p, err := syscall.UTF16PtrFromString(value) | ||
178 | if err != nil { | ||
179 | return "", err | ||
180 | } | ||
181 | r := make([]uint16, 100) | ||
182 | for { | ||
183 | n, err := expandEnvironmentStrings(p, &r[0], uint32(len(r))) | ||
184 | if err != nil { | ||
185 | return "", err | ||
186 | } | ||
187 | if n <= uint32(len(r)) { | ||
188 | u := (*[1 << 29]uint16)(unsafe.Pointer(&r[0]))[:] | ||
189 | return syscall.UTF16ToString(u), nil | ||
190 | } | ||
191 | r = make([]uint16, n) | ||
192 | } | ||
193 | } | ||
194 | |||
195 | // GetStringsValue retrieves the []string value for the specified | ||
196 | // value name associated with an open key k. It also returns the value's type. | ||
197 | // If value does not exist, GetStringsValue returns ErrNotExist. | ||
198 | // If value is not MULTI_SZ, it will return the correct value | ||
199 | // type and ErrUnexpectedType. | ||
200 | func (k Key) GetStringsValue(name string) (val []string, valtype uint32, err error) { | ||
201 | data, typ, err2 := k.getValue(name, make([]byte, 64)) | ||
202 | if err2 != nil { | ||
203 | return nil, typ, err2 | ||
204 | } | ||
205 | if typ != MULTI_SZ { | ||
206 | return nil, typ, ErrUnexpectedType | ||
207 | } | ||
208 | if len(data) == 0 { | ||
209 | return nil, typ, nil | ||
210 | } | ||
211 | p := (*[1 << 29]uint16)(unsafe.Pointer(&data[0]))[:len(data)/2] | ||
212 | if len(p) == 0 { | ||
213 | return nil, typ, nil | ||
214 | } | ||
215 | if p[len(p)-1] == 0 { | ||
216 | p = p[:len(p)-1] // remove terminating null | ||
217 | } | ||
218 | val = make([]string, 0, 5) | ||
219 | from := 0 | ||
220 | for i, c := range p { | ||
221 | if c == 0 { | ||
222 | val = append(val, string(utf16.Decode(p[from:i]))) | ||
223 | from = i + 1 | ||
224 | } | ||
225 | } | ||
226 | return val, typ, nil | ||
227 | } | ||
228 | |||
229 | // GetIntegerValue retrieves the integer value for the specified | ||
230 | // value name associated with an open key k. It also returns the value's type. | ||
231 | // If value does not exist, GetIntegerValue returns ErrNotExist. | ||
232 | // If value is not DWORD or QWORD, it will return the correct value | ||
233 | // type and ErrUnexpectedType. | ||
234 | func (k Key) GetIntegerValue(name string) (val uint64, valtype uint32, err error) { | ||
235 | data, typ, err2 := k.getValue(name, make([]byte, 8)) | ||
236 | if err2 != nil { | ||
237 | return 0, typ, err2 | ||
238 | } | ||
239 | switch typ { | ||
240 | case DWORD: | ||
241 | if len(data) != 4 { | ||
242 | return 0, typ, errors.New("DWORD value is not 4 bytes long") | ||
243 | } | ||
244 | var val32 uint32 | ||
245 | copy((*[4]byte)(unsafe.Pointer(&val32))[:], data) | ||
246 | return uint64(val32), DWORD, nil | ||
247 | case QWORD: | ||
248 | if len(data) != 8 { | ||
249 | return 0, typ, errors.New("QWORD value is not 8 bytes long") | ||
250 | } | ||
251 | copy((*[8]byte)(unsafe.Pointer(&val))[:], data) | ||
252 | return val, QWORD, nil | ||
253 | default: | ||
254 | return 0, typ, ErrUnexpectedType | ||
255 | } | ||
256 | } | ||
257 | |||
258 | // GetBinaryValue retrieves the binary value for the specified | ||
259 | // value name associated with an open key k. It also returns the value's type. | ||
260 | // If value does not exist, GetBinaryValue returns ErrNotExist. | ||
261 | // If value is not BINARY, it will return the correct value | ||
262 | // type and ErrUnexpectedType. | ||
263 | func (k Key) GetBinaryValue(name string) (val []byte, valtype uint32, err error) { | ||
264 | data, typ, err2 := k.getValue(name, make([]byte, 64)) | ||
265 | if err2 != nil { | ||
266 | return nil, typ, err2 | ||
267 | } | ||
268 | if typ != BINARY { | ||
269 | return nil, typ, ErrUnexpectedType | ||
270 | } | ||
271 | return data, typ, nil | ||
272 | } | ||
273 | |||
274 | func (k Key) setValue(name string, valtype uint32, data []byte) error { | ||
275 | p, err := syscall.UTF16PtrFromString(name) | ||
276 | if err != nil { | ||
277 | return err | ||
278 | } | ||
279 | if len(data) == 0 { | ||
280 | return regSetValueEx(syscall.Handle(k), p, 0, valtype, nil, 0) | ||
281 | } | ||
282 | return regSetValueEx(syscall.Handle(k), p, 0, valtype, &data[0], uint32(len(data))) | ||
283 | } | ||
284 | |||
285 | // SetDWordValue sets the data and type of a name value | ||
286 | // under key k to value and DWORD. | ||
287 | func (k Key) SetDWordValue(name string, value uint32) error { | ||
288 | return k.setValue(name, DWORD, (*[4]byte)(unsafe.Pointer(&value))[:]) | ||
289 | } | ||
290 | |||
291 | // SetQWordValue sets the data and type of a name value | ||
292 | // under key k to value and QWORD. | ||
293 | func (k Key) SetQWordValue(name string, value uint64) error { | ||
294 | return k.setValue(name, QWORD, (*[8]byte)(unsafe.Pointer(&value))[:]) | ||
295 | } | ||
296 | |||
297 | func (k Key) setStringValue(name string, valtype uint32, value string) error { | ||
298 | v, err := syscall.UTF16FromString(value) | ||
299 | if err != nil { | ||
300 | return err | ||
301 | } | ||
302 | buf := (*[1 << 29]byte)(unsafe.Pointer(&v[0]))[:len(v)*2] | ||
303 | return k.setValue(name, valtype, buf) | ||
304 | } | ||
305 | |||
306 | // SetStringValue sets the data and type of a name value | ||
307 | // under key k to value and SZ. The value must not contain a zero byte. | ||
308 | func (k Key) SetStringValue(name, value string) error { | ||
309 | return k.setStringValue(name, SZ, value) | ||
310 | } | ||
311 | |||
312 | // SetExpandStringValue sets the data and type of a name value | ||
313 | // under key k to value and EXPAND_SZ. The value must not contain a zero byte. | ||
314 | func (k Key) SetExpandStringValue(name, value string) error { | ||
315 | return k.setStringValue(name, EXPAND_SZ, value) | ||
316 | } | ||
317 | |||
318 | // SetStringsValue sets the data and type of a name value | ||
319 | // under key k to value and MULTI_SZ. The value strings | ||
320 | // must not contain a zero byte. | ||
321 | func (k Key) SetStringsValue(name string, value []string) error { | ||
322 | ss := "" | ||
323 | for _, s := range value { | ||
324 | for i := 0; i < len(s); i++ { | ||
325 | if s[i] == 0 { | ||
326 | return errors.New("string cannot have 0 inside") | ||
327 | } | ||
328 | } | ||
329 | ss += s + "\x00" | ||
330 | } | ||
331 | v := utf16.Encode([]rune(ss + "\x00")) | ||
332 | buf := (*[1 << 29]byte)(unsafe.Pointer(&v[0]))[:len(v)*2] | ||
333 | return k.setValue(name, MULTI_SZ, buf) | ||
334 | } | ||
335 | |||
336 | // SetBinaryValue sets the data and type of a name value | ||
337 | // under key k to value and BINARY. | ||
338 | func (k Key) SetBinaryValue(name string, value []byte) error { | ||
339 | return k.setValue(name, BINARY, value) | ||
340 | } | ||
341 | |||
342 | // DeleteValue removes a named value from the key k. | ||
343 | func (k Key) DeleteValue(name string) error { | ||
344 | return regDeleteValue(syscall.Handle(k), syscall.StringToUTF16Ptr(name)) | ||
345 | } | ||
346 | |||
347 | // ReadValueNames returns the value names of key k. | ||
348 | // The parameter n controls the number of returned names, | ||
349 | // analogous to the way os.File.Readdirnames works. | ||
350 | func (k Key) ReadValueNames(n int) ([]string, error) { | ||
351 | ki, err := k.Stat() | ||
352 | if err != nil { | ||
353 | return nil, err | ||
354 | } | ||
355 | names := make([]string, 0, ki.ValueCount) | ||
356 | buf := make([]uint16, ki.MaxValueNameLen+1) // extra room for terminating null character | ||
357 | loopItems: | ||
358 | for i := uint32(0); ; i++ { | ||
359 | if n > 0 { | ||
360 | if len(names) == n { | ||
361 | return names, nil | ||
362 | } | ||
363 | } | ||
364 | l := uint32(len(buf)) | ||
365 | for { | ||
366 | err := regEnumValue(syscall.Handle(k), i, &buf[0], &l, nil, nil, nil, nil) | ||
367 | if err == nil { | ||
368 | break | ||
369 | } | ||
370 | if err == syscall.ERROR_MORE_DATA { | ||
371 | // Double buffer size and try again. | ||
372 | l = uint32(2 * len(buf)) | ||
373 | buf = make([]uint16, l) | ||
374 | continue | ||
375 | } | ||
376 | if err == _ERROR_NO_MORE_ITEMS { | ||
377 | break loopItems | ||
378 | } | ||
379 | return names, err | ||
380 | } | ||
381 | names = append(names, syscall.UTF16ToString(buf[:l])) | ||
382 | } | ||
383 | if n > len(names) { | ||
384 | return names, io.EOF | ||
385 | } | ||
386 | return names, nil | ||
387 | } | ||
diff --git a/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go deleted file mode 100644 index 3778075..0000000 --- a/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | // Code generated by 'go generate'; DO NOT EDIT. | ||
2 | |||
3 | package registry | ||
4 | |||
5 | import ( | ||
6 | "syscall" | ||
7 | "unsafe" | ||
8 | |||
9 | "golang.org/x/sys/windows" | ||
10 | ) | ||
11 | |||
12 | var _ unsafe.Pointer | ||
13 | |||
14 | // Do the interface allocations only once for common | ||
15 | // Errno values. | ||
16 | const ( | ||
17 | errnoERROR_IO_PENDING = 997 | ||
18 | ) | ||
19 | |||
20 | var ( | ||
21 | errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) | ||
22 | ) | ||
23 | |||
24 | // errnoErr returns common boxed Errno values, to prevent | ||
25 | // allocations at runtime. | ||
26 | func errnoErr(e syscall.Errno) error { | ||
27 | switch e { | ||
28 | case 0: | ||
29 | return nil | ||
30 | case errnoERROR_IO_PENDING: | ||
31 | return errERROR_IO_PENDING | ||
32 | } | ||
33 | // TODO: add more here, after collecting data on the common | ||
34 | // error values see on Windows. (perhaps when running | ||
35 | // all.bat?) | ||
36 | return e | ||
37 | } | ||
38 | |||
39 | var ( | ||
40 | modadvapi32 = windows.NewLazySystemDLL("advapi32.dll") | ||
41 | modkernel32 = windows.NewLazySystemDLL("kernel32.dll") | ||
42 | |||
43 | procRegCreateKeyExW = modadvapi32.NewProc("RegCreateKeyExW") | ||
44 | procRegDeleteKeyW = modadvapi32.NewProc("RegDeleteKeyW") | ||
45 | procRegSetValueExW = modadvapi32.NewProc("RegSetValueExW") | ||
46 | procRegEnumValueW = modadvapi32.NewProc("RegEnumValueW") | ||
47 | procRegDeleteValueW = modadvapi32.NewProc("RegDeleteValueW") | ||
48 | procRegLoadMUIStringW = modadvapi32.NewProc("RegLoadMUIStringW") | ||
49 | procRegConnectRegistryW = modadvapi32.NewProc("RegConnectRegistryW") | ||
50 | procExpandEnvironmentStringsW = modkernel32.NewProc("ExpandEnvironmentStringsW") | ||
51 | ) | ||
52 | |||
53 | func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) { | ||
54 | r0, _, _ := syscall.Syscall9(procRegCreateKeyExW.Addr(), 9, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition))) | ||
55 | if r0 != 0 { | ||
56 | regerrno = syscall.Errno(r0) | ||
57 | } | ||
58 | return | ||
59 | } | ||
60 | |||
61 | func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) { | ||
62 | r0, _, _ := syscall.Syscall(procRegDeleteKeyW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(subkey)), 0) | ||
63 | if r0 != 0 { | ||
64 | regerrno = syscall.Errno(r0) | ||
65 | } | ||
66 | return | ||
67 | } | ||
68 | |||
69 | func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) { | ||
70 | r0, _, _ := syscall.Syscall6(procRegSetValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize)) | ||
71 | if r0 != 0 { | ||
72 | regerrno = syscall.Errno(r0) | ||
73 | } | ||
74 | return | ||
75 | } | ||
76 | |||
77 | func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) { | ||
78 | r0, _, _ := syscall.Syscall9(procRegEnumValueW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)), 0) | ||
79 | if r0 != 0 { | ||
80 | regerrno = syscall.Errno(r0) | ||
81 | } | ||
82 | return | ||
83 | } | ||
84 | |||
85 | func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) { | ||
86 | r0, _, _ := syscall.Syscall(procRegDeleteValueW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(name)), 0) | ||
87 | if r0 != 0 { | ||
88 | regerrno = syscall.Errno(r0) | ||
89 | } | ||
90 | return | ||
91 | } | ||
92 | |||
93 | func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) { | ||
94 | r0, _, _ := syscall.Syscall9(procRegLoadMUIStringW.Addr(), 7, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir)), 0, 0) | ||
95 | if r0 != 0 { | ||
96 | regerrno = syscall.Errno(r0) | ||
97 | } | ||
98 | return | ||
99 | } | ||
100 | |||
101 | func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) { | ||
102 | r0, _, _ := syscall.Syscall(procRegConnectRegistryW.Addr(), 3, uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result))) | ||
103 | if r0 != 0 { | ||
104 | regerrno = syscall.Errno(r0) | ||
105 | } | ||
106 | return | ||
107 | } | ||
108 | |||
109 | func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) { | ||
110 | r0, _, e1 := syscall.Syscall(procExpandEnvironmentStringsW.Addr(), 3, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size)) | ||
111 | n = uint32(r0) | ||
112 | if n == 0 { | ||
113 | if e1 != 0 { | ||
114 | err = errnoErr(e1) | ||
115 | } else { | ||
116 | err = syscall.EINVAL | ||
117 | } | ||
118 | } | ||
119 | return | ||
120 | } | ||
diff --git a/vendor/golang.org/x/sys/windows/svc/eventlog/install.go b/vendor/golang.org/x/sys/windows/svc/eventlog/install.go deleted file mode 100644 index c76a376..0000000 --- a/vendor/golang.org/x/sys/windows/svc/eventlog/install.go +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | // Copyright 2012 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build windows | ||
6 | |||
7 | package eventlog | ||
8 | |||
9 | import ( | ||
10 | "errors" | ||
11 | |||
12 | "golang.org/x/sys/windows" | ||
13 | "golang.org/x/sys/windows/registry" | ||
14 | ) | ||
15 | |||
16 | const ( | ||
17 | // Log levels. | ||
18 | Info = windows.EVENTLOG_INFORMATION_TYPE | ||
19 | Warning = windows.EVENTLOG_WARNING_TYPE | ||
20 | Error = windows.EVENTLOG_ERROR_TYPE | ||
21 | ) | ||
22 | |||
23 | const addKeyName = `SYSTEM\CurrentControlSet\Services\EventLog\Application` | ||
24 | |||
25 | // Install modifies PC registry to allow logging with an event source src. | ||
26 | // It adds all required keys and values to the event log registry key. | ||
27 | // Install uses msgFile as the event message file. If useExpandKey is true, | ||
28 | // the event message file is installed as REG_EXPAND_SZ value, | ||
29 | // otherwise as REG_SZ. Use bitwise of log.Error, log.Warning and | ||
30 | // log.Info to specify events supported by the new event source. | ||
31 | func Install(src, msgFile string, useExpandKey bool, eventsSupported uint32) error { | ||
32 | appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.CREATE_SUB_KEY) | ||
33 | if err != nil { | ||
34 | return err | ||
35 | } | ||
36 | defer appkey.Close() | ||
37 | |||
38 | sk, alreadyExist, err := registry.CreateKey(appkey, src, registry.SET_VALUE) | ||
39 | if err != nil { | ||
40 | return err | ||
41 | } | ||
42 | defer sk.Close() | ||
43 | if alreadyExist { | ||
44 | return errors.New(addKeyName + `\` + src + " registry key already exists") | ||
45 | } | ||
46 | |||
47 | err = sk.SetDWordValue("CustomSource", 1) | ||
48 | if err != nil { | ||
49 | return err | ||
50 | } | ||
51 | if useExpandKey { | ||
52 | err = sk.SetExpandStringValue("EventMessageFile", msgFile) | ||
53 | } else { | ||
54 | err = sk.SetStringValue("EventMessageFile", msgFile) | ||
55 | } | ||
56 | if err != nil { | ||
57 | return err | ||
58 | } | ||
59 | err = sk.SetDWordValue("TypesSupported", eventsSupported) | ||
60 | if err != nil { | ||
61 | return err | ||
62 | } | ||
63 | return nil | ||
64 | } | ||
65 | |||
66 | // InstallAsEventCreate is the same as Install, but uses | ||
67 | // %SystemRoot%\System32\EventCreate.exe as the event message file. | ||
68 | func InstallAsEventCreate(src string, eventsSupported uint32) error { | ||
69 | return Install(src, "%SystemRoot%\\System32\\EventCreate.exe", true, eventsSupported) | ||
70 | } | ||
71 | |||
72 | // Remove deletes all registry elements installed by the correspondent Install. | ||
73 | func Remove(src string) error { | ||
74 | appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.SET_VALUE) | ||
75 | if err != nil { | ||
76 | return err | ||
77 | } | ||
78 | defer appkey.Close() | ||
79 | return registry.DeleteKey(appkey, src) | ||
80 | } | ||
diff --git a/vendor/golang.org/x/sys/windows/svc/eventlog/log.go b/vendor/golang.org/x/sys/windows/svc/eventlog/log.go deleted file mode 100644 index 46e5153..0000000 --- a/vendor/golang.org/x/sys/windows/svc/eventlog/log.go +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | // Copyright 2012 The Go Authors. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | // +build windows | ||
6 | |||
7 | // Package eventlog implements access to Windows event log. | ||
8 | // | ||
9 | package eventlog | ||
10 | |||
11 | import ( | ||
12 | "errors" | ||
13 | "syscall" | ||
14 | |||
15 | "golang.org/x/sys/windows" | ||
16 | ) | ||
17 | |||
18 | // Log provides access to the system log. | ||
19 | type Log struct { | ||
20 | Handle windows.Handle | ||
21 | } | ||
22 | |||
23 | // Open retrieves a handle to the specified event log. | ||
24 | func Open(source string) (*Log, error) { | ||
25 | return OpenRemote("", source) | ||
26 | } | ||
27 | |||
28 | // OpenRemote does the same as Open, but on different computer host. | ||
29 | func OpenRemote(host, source string) (*Log, error) { | ||
30 | if source == "" { | ||
31 | return nil, errors.New("Specify event log source") | ||
32 | } | ||
33 | var s *uint16 | ||
34 | if host != "" { | ||
35 | s = syscall.StringToUTF16Ptr(host) | ||
36 | } | ||
37 | h, err := windows.RegisterEventSource(s, syscall.StringToUTF16Ptr(source)) | ||
38 | if err != nil { | ||
39 | return nil, err | ||
40 | } | ||
41 | return &Log{Handle: h}, nil | ||
42 | } | ||
43 | |||
44 | // Close closes event log l. | ||
45 | func (l *Log) Close() error { | ||
46 | return windows.DeregisterEventSource(l.Handle) | ||
47 | } | ||
48 | |||
49 | func (l *Log) report(etype uint16, eid uint32, msg string) error { | ||
50 | ss := []*uint16{syscall.StringToUTF16Ptr(msg)} | ||
51 | return windows.ReportEvent(l.Handle, etype, 0, eid, 0, 1, 0, &ss[0], nil) | ||
52 | } | ||
53 | |||
54 | // Info writes an information event msg with event id eid to the end of event log l. | ||
55 | // When EventCreate.exe is used, eid must be between 1 and 1000. | ||
56 | func (l *Log) Info(eid uint32, msg string) error { | ||
57 | return l.report(windows.EVENTLOG_INFORMATION_TYPE, eid, msg) | ||
58 | } | ||
59 | |||
60 | // Warning writes an warning event msg with event id eid to the end of event log l. | ||
61 | // When EventCreate.exe is used, eid must be between 1 and 1000. | ||
62 | func (l *Log) Warning(eid uint32, msg string) error { | ||
63 | return l.report(windows.EVENTLOG_WARNING_TYPE, eid, msg) | ||
64 | } | ||
65 | |||
66 | // Error writes an error event msg with event id eid to the end of event log l. | ||
67 | // When EventCreate.exe is used, eid must be between 1 and 1000. | ||
68 | func (l *Log) Error(eid uint32, msg string) error { | ||
69 | return l.report(windows.EVENTLOG_ERROR_TYPE, eid, msg) | ||
70 | } | ||
diff --git a/vendor/modules.txt b/vendor/modules.txt index 4d02fda..b81ffcb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt | |||
@@ -11,14 +11,19 @@ github.com/beorn7/perks/quantile | |||
11 | github.com/coreos/go-systemd/dbus | 11 | github.com/coreos/go-systemd/dbus |
12 | # github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 | 12 | # github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 |
13 | github.com/ema/qdisc | 13 | github.com/ema/qdisc |
14 | # github.com/go-kit/kit v0.9.0 | ||
15 | github.com/go-kit/kit/log | ||
16 | github.com/go-kit/kit/log/level | ||
17 | # github.com/go-logfmt/logfmt v0.4.0 | ||
18 | github.com/go-logfmt/logfmt | ||
14 | # github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 | 19 | # github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 |
15 | github.com/godbus/dbus | 20 | github.com/godbus/dbus |
16 | # github.com/golang/protobuf v1.3.2 | 21 | # github.com/golang/protobuf v1.3.2 |
17 | github.com/golang/protobuf/proto | 22 | github.com/golang/protobuf/proto |
18 | # github.com/hodgesds/perf-utils v0.0.7 | 23 | # github.com/hodgesds/perf-utils v0.0.7 |
19 | github.com/hodgesds/perf-utils | 24 | github.com/hodgesds/perf-utils |
20 | # github.com/konsorten/go-windows-terminal-sequences v1.0.2 | 25 | # github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 |
21 | github.com/konsorten/go-windows-terminal-sequences | 26 | github.com/kr/logfmt |
22 | # github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3 | 27 | # github.com/lufia/iostat v0.0.0-20170605150913-9f7362b77ad3 |
23 | github.com/lufia/iostat | 28 | github.com/lufia/iostat |
24 | # github.com/mattn/go-xmlrpc v0.0.3 | 29 | # github.com/mattn/go-xmlrpc v0.0.3 |
@@ -44,8 +49,9 @@ github.com/prometheus/client_model/go | |||
44 | # github.com/prometheus/common v0.7.0 | 49 | # github.com/prometheus/common v0.7.0 |
45 | github.com/prometheus/common/expfmt | 50 | github.com/prometheus/common/expfmt |
46 | github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg | 51 | github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg |
47 | github.com/prometheus/common/log | ||
48 | github.com/prometheus/common/model | 52 | github.com/prometheus/common/model |
53 | github.com/prometheus/common/promlog | ||
54 | github.com/prometheus/common/promlog/flag | ||
49 | github.com/prometheus/common/version | 55 | github.com/prometheus/common/version |
50 | # github.com/prometheus/procfs v0.0.8 | 56 | # github.com/prometheus/procfs v0.0.8 |
51 | github.com/prometheus/procfs | 57 | github.com/prometheus/procfs |
@@ -57,8 +63,6 @@ github.com/prometheus/procfs/sysfs | |||
57 | github.com/prometheus/procfs/xfs | 63 | github.com/prometheus/procfs/xfs |
58 | # github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 | 64 | # github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 |
59 | github.com/siebenmann/go-kstat | 65 | github.com/siebenmann/go-kstat |
60 | # github.com/sirupsen/logrus v1.4.2 | ||
61 | github.com/sirupsen/logrus | ||
62 | # github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a | 66 | # github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a |
63 | github.com/soundcloud/go-runit/runit | 67 | github.com/soundcloud/go-runit/runit |
64 | # go.uber.org/atomic v1.3.2 | 68 | # go.uber.org/atomic v1.3.2 |
@@ -75,8 +79,6 @@ golang.org/x/sync/errgroup | |||
75 | # golang.org/x/sys v0.0.0-20190902133755-9109b7679e13 | 79 | # golang.org/x/sys v0.0.0-20190902133755-9109b7679e13 |
76 | golang.org/x/sys/unix | 80 | golang.org/x/sys/unix |
77 | golang.org/x/sys/windows | 81 | golang.org/x/sys/windows |
78 | golang.org/x/sys/windows/registry | ||
79 | golang.org/x/sys/windows/svc/eventlog | ||
80 | # gopkg.in/alecthomas/kingpin.v2 v2.2.6 | 82 | # gopkg.in/alecthomas/kingpin.v2 v2.2.6 |
81 | gopkg.in/alecthomas/kingpin.v2 | 83 | gopkg.in/alecthomas/kingpin.v2 |
82 | # gopkg.in/yaml.v2 v2.2.2 | 84 | # gopkg.in/yaml.v2 v2.2.2 |