summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/jwalterweatherman/log_counter.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-03-20 22:40:23 +0100
committerGitHub <noreply@github.com>2021-03-20 22:40:23 +0100
commitee5d9b43b54a3becf3cb4025198f24608d35500d (patch)
treedd3614db7423da52f5a71da3001e48d1e4195ea1 /vendor/github.com/spf13/jwalterweatherman/log_counter.go
parent3a8857c8c9efb2c67fb8c175f31d2b9c617b771b (diff)
downloadmatterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.gz
matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.bz2
matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.zip
Update vendor (#1414)
Diffstat (limited to 'vendor/github.com/spf13/jwalterweatherman/log_counter.go')
-rw-r--r--vendor/github.com/spf13/jwalterweatherman/log_counter.go51
1 files changed, 30 insertions, 21 deletions
diff --git a/vendor/github.com/spf13/jwalterweatherman/log_counter.go b/vendor/github.com/spf13/jwalterweatherman/log_counter.go
index 41285f3d..11423ac4 100644
--- a/vendor/github.com/spf13/jwalterweatherman/log_counter.go
+++ b/vendor/github.com/spf13/jwalterweatherman/log_counter.go
@@ -6,41 +6,50 @@
package jwalterweatherman
import (
- "io"
"sync/atomic"
)
-// Counter is an io.Writer that increments a counter on Write.
-type Counter struct {
- count uint64
+type logCounter struct {
+ counter uint64
}
-func (c *Counter) incr() {
- atomic.AddUint64(&c.count, 1)
+func (c *logCounter) incr() {
+ atomic.AddUint64(&c.counter, 1)
}
-// Reset resets the counter.
-func (c *Counter) Reset() {
- atomic.StoreUint64(&c.count, 0)
+func (c *logCounter) resetCounter() {
+ atomic.StoreUint64(&c.counter, 0)
}
-// Count returns the current count.
-func (c *Counter) Count() uint64 {
- return atomic.LoadUint64(&c.count)
+func (c *logCounter) getCount() uint64 {
+ return atomic.LoadUint64(&c.counter)
}
-func (c *Counter) Write(p []byte) (n int, err error) {
+func (c *logCounter) Write(p []byte) (n int, err error) {
c.incr()
return len(p), nil
}
-// LogCounter creates a LogListener that counts log statements >= the given threshold.
-func LogCounter(counter *Counter, t1 Threshold) LogListener {
- return func(t2 Threshold) io.Writer {
- if t2 < t1 {
- // Not interested in this threshold.
- return nil
- }
- return counter
+// LogCountForLevel returns the number of log invocations for a given threshold.
+func (n *Notepad) LogCountForLevel(l Threshold) uint64 {
+ return n.logCounters[l].getCount()
+}
+
+// LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations
+// greater than or equal to a given threshold.
+func (n *Notepad) LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 {
+ var cnt uint64
+
+ for i := int(threshold); i < len(n.logCounters); i++ {
+ cnt += n.LogCountForLevel(Threshold(i))
+ }
+
+ return cnt
+}
+
+// ResetLogCounters resets the invocation counters for all levels.
+func (n *Notepad) ResetLogCounters() {
+ for _, np := range n.logCounters {
+ np.resetCounter()
}
}