summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/jwalterweatherman
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-08-10 00:29:54 +0200
committerGitHub <noreply@github.com>2020-08-10 00:29:54 +0200
commit4e50fd864921c556988c919269448efdb90fa961 (patch)
treea3625f03f8de3c4f3841364000a4ea3aa42c1533 /vendor/github.com/spf13/jwalterweatherman
parentdfdffa0027334e55ce213fc6eb62206dbf48baf6 (diff)
downloadmatterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.gz
matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.bz2
matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.zip
Use mattermost v5 module (#1192)
Diffstat (limited to 'vendor/github.com/spf13/jwalterweatherman')
-rw-r--r--vendor/github.com/spf13/jwalterweatherman/.gitignore2
-rw-r--r--vendor/github.com/spf13/jwalterweatherman/default_notepad.go30
-rw-r--r--vendor/github.com/spf13/jwalterweatherman/go.mod6
-rw-r--r--vendor/github.com/spf13/jwalterweatherman/log_counter.go51
-rw-r--r--vendor/github.com/spf13/jwalterweatherman/notepad.go57
5 files changed, 87 insertions, 59 deletions
diff --git a/vendor/github.com/spf13/jwalterweatherman/.gitignore b/vendor/github.com/spf13/jwalterweatherman/.gitignore
index 00268614..a71f88af 100644
--- a/vendor/github.com/spf13/jwalterweatherman/.gitignore
+++ b/vendor/github.com/spf13/jwalterweatherman/.gitignore
@@ -20,3 +20,5 @@ _cgo_export.*
_testmain.go
*.exe
+*.bench
+go.sum \ No newline at end of file
diff --git a/vendor/github.com/spf13/jwalterweatherman/default_notepad.go b/vendor/github.com/spf13/jwalterweatherman/default_notepad.go
index bcb76340..a018c15c 100644
--- a/vendor/github.com/spf13/jwalterweatherman/default_notepad.go
+++ b/vendor/github.com/spf13/jwalterweatherman/default_notepad.go
@@ -64,6 +64,13 @@ func SetStdoutThreshold(threshold Threshold) {
reloadDefaultNotepad()
}
+// SetStdoutOutput set the stdout output for the default notepad. Default is stdout.
+func SetStdoutOutput(handle io.Writer) {
+ defaultNotepad.outHandle = handle
+ defaultNotepad.init()
+ reloadDefaultNotepad()
+}
+
// SetPrefix set the prefix for the default logger. Empty by default.
func SetPrefix(prefix string) {
defaultNotepad.SetPrefix(prefix)
@@ -76,6 +83,13 @@ func SetFlags(flags int) {
reloadDefaultNotepad()
}
+// SetLogListeners configures the default logger with one or more log listeners.
+func SetLogListeners(l ...LogListener) {
+ defaultNotepad.logListeners = l
+ defaultNotepad.init()
+ reloadDefaultNotepad()
+}
+
// Level returns the current global log threshold.
func LogThreshold() Threshold {
return defaultNotepad.logThreshold
@@ -95,19 +109,3 @@ func GetLogThreshold() Threshold {
func GetStdoutThreshold() Threshold {
return defaultNotepad.GetStdoutThreshold()
}
-
-// LogCountForLevel returns the number of log invocations for a given threshold.
-func LogCountForLevel(l Threshold) uint64 {
- return defaultNotepad.LogCountForLevel(l)
-}
-
-// LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations
-// greater than or equal to a given threshold.
-func LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 {
- return defaultNotepad.LogCountForLevelsGreaterThanorEqualTo(threshold)
-}
-
-// ResetLogCounters resets the invocation counters for all levels.
-func ResetLogCounters() {
- defaultNotepad.ResetLogCounters()
-}
diff --git a/vendor/github.com/spf13/jwalterweatherman/go.mod b/vendor/github.com/spf13/jwalterweatherman/go.mod
index bce549c0..1dbcfd3e 100644
--- a/vendor/github.com/spf13/jwalterweatherman/go.mod
+++ b/vendor/github.com/spf13/jwalterweatherman/go.mod
@@ -1 +1,7 @@
module github.com/spf13/jwalterweatherman
+
+require (
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/stretchr/testify v1.2.2
+)
diff --git a/vendor/github.com/spf13/jwalterweatherman/log_counter.go b/vendor/github.com/spf13/jwalterweatherman/log_counter.go
index 11423ac4..41285f3d 100644
--- a/vendor/github.com/spf13/jwalterweatherman/log_counter.go
+++ b/vendor/github.com/spf13/jwalterweatherman/log_counter.go
@@ -6,50 +6,41 @@
package jwalterweatherman
import (
+ "io"
"sync/atomic"
)
-type logCounter struct {
- counter uint64
+// Counter is an io.Writer that increments a counter on Write.
+type Counter struct {
+ count uint64
}
-func (c *logCounter) incr() {
- atomic.AddUint64(&c.counter, 1)
+func (c *Counter) incr() {
+ atomic.AddUint64(&c.count, 1)
}
-func (c *logCounter) resetCounter() {
- atomic.StoreUint64(&c.counter, 0)
+// Reset resets the counter.
+func (c *Counter) Reset() {
+ atomic.StoreUint64(&c.count, 0)
}
-func (c *logCounter) getCount() uint64 {
- return atomic.LoadUint64(&c.counter)
+// Count returns the current count.
+func (c *Counter) Count() uint64 {
+ return atomic.LoadUint64(&c.count)
}
-func (c *logCounter) Write(p []byte) (n int, err error) {
+func (c *Counter) Write(p []byte) (n int, err error) {
c.incr()
return len(p), nil
}
-// 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()
+// 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
}
}
diff --git a/vendor/github.com/spf13/jwalterweatherman/notepad.go b/vendor/github.com/spf13/jwalterweatherman/notepad.go
index ae5aaf71..cc7957bf 100644
--- a/vendor/github.com/spf13/jwalterweatherman/notepad.go
+++ b/vendor/github.com/spf13/jwalterweatherman/notepad.go
@@ -8,6 +8,7 @@ package jwalterweatherman
import (
"fmt"
"io"
+ "io/ioutil"
"log"
)
@@ -58,13 +59,28 @@ type Notepad struct {
prefix string
flags int
- // One per Threshold
- logCounters [7]*logCounter
+ logListeners []LogListener
}
-// NewNotepad create a new notepad.
-func NewNotepad(outThreshold Threshold, logThreshold Threshold, outHandle, logHandle io.Writer, prefix string, flags int) *Notepad {
- n := &Notepad{}
+// A LogListener can ble supplied to a Notepad to listen on log writes for a given
+// threshold. This can be used to capture log events in unit tests and similar.
+// Note that this function will be invoked once for each log threshold. If
+// the given threshold is not of interest to you, return nil.
+// Note that these listeners will receive log events for a given threshold, even
+// if the current configuration says not to log it. That way you can count ERRORs even
+// if you don't print them to the console.
+type LogListener func(t Threshold) io.Writer
+
+// NewNotepad creates a new Notepad.
+func NewNotepad(
+ outThreshold Threshold,
+ logThreshold Threshold,
+ outHandle, logHandle io.Writer,
+ prefix string, flags int,
+ logListeners ...LogListener,
+) *Notepad {
+
+ n := &Notepad{logListeners: logListeners}
n.loggers = [7]**log.Logger{&n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL}
n.outHandle = outHandle
@@ -95,26 +111,41 @@ func (n *Notepad) init() {
for t, logger := range n.loggers {
threshold := Threshold(t)
- counter := &logCounter{}
- n.logCounters[t] = counter
prefix := n.prefix + threshold.String() + " "
switch {
case threshold >= n.logThreshold && threshold >= n.stdoutThreshold:
- *logger = log.New(io.MultiWriter(counter, logAndOut), prefix, n.flags)
+ *logger = log.New(n.createLogWriters(threshold, logAndOut), prefix, n.flags)
case threshold >= n.logThreshold:
- *logger = log.New(io.MultiWriter(counter, n.logHandle), prefix, n.flags)
+ *logger = log.New(n.createLogWriters(threshold, n.logHandle), prefix, n.flags)
case threshold >= n.stdoutThreshold:
- *logger = log.New(io.MultiWriter(counter, n.outHandle), prefix, n.flags)
+ *logger = log.New(n.createLogWriters(threshold, n.outHandle), prefix, n.flags)
default:
- // counter doesn't care about prefix and flags, so don't use them
- // for performance.
- *logger = log.New(counter, "", 0)
+ *logger = log.New(n.createLogWriters(threshold, ioutil.Discard), prefix, n.flags)
+ }
+ }
+}
+
+func (n *Notepad) createLogWriters(t Threshold, handle io.Writer) io.Writer {
+ if len(n.logListeners) == 0 {
+ return handle
+ }
+ writers := []io.Writer{handle}
+ for _, l := range n.logListeners {
+ w := l(t)
+ if w != nil {
+ writers = append(writers, w)
}
}
+
+ if len(writers) == 1 {
+ return handle
+ }
+
+ return io.MultiWriter(writers...)
}
// SetLogThreshold changes the threshold above which messages are written to the