summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/jwalterweatherman
diff options
context:
space:
mode:
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, 59 insertions, 87 deletions
diff --git a/vendor/github.com/spf13/jwalterweatherman/.gitignore b/vendor/github.com/spf13/jwalterweatherman/.gitignore
index a71f88af..00268614 100644
--- a/vendor/github.com/spf13/jwalterweatherman/.gitignore
+++ b/vendor/github.com/spf13/jwalterweatherman/.gitignore
@@ -20,5 +20,3 @@ _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 a018c15c..bcb76340 100644
--- a/vendor/github.com/spf13/jwalterweatherman/default_notepad.go
+++ b/vendor/github.com/spf13/jwalterweatherman/default_notepad.go
@@ -64,13 +64,6 @@ 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)
@@ -83,13 +76,6 @@ 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
@@ -109,3 +95,19 @@ 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 1dbcfd3e..bce549c0 100644
--- a/vendor/github.com/spf13/jwalterweatherman/go.mod
+++ b/vendor/github.com/spf13/jwalterweatherman/go.mod
@@ -1,7 +1 @@
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 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()
}
}
diff --git a/vendor/github.com/spf13/jwalterweatherman/notepad.go b/vendor/github.com/spf13/jwalterweatherman/notepad.go
index cc7957bf..ae5aaf71 100644
--- a/vendor/github.com/spf13/jwalterweatherman/notepad.go
+++ b/vendor/github.com/spf13/jwalterweatherman/notepad.go
@@ -8,7 +8,6 @@ package jwalterweatherman
import (
"fmt"
"io"
- "io/ioutil"
"log"
)
@@ -59,28 +58,13 @@ type Notepad struct {
prefix string
flags int
- logListeners []LogListener
+ // One per Threshold
+ logCounters [7]*logCounter
}
-// 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}
+// NewNotepad create a new notepad.
+func NewNotepad(outThreshold Threshold, logThreshold Threshold, outHandle, logHandle io.Writer, prefix string, flags int) *Notepad {
+ n := &Notepad{}
n.loggers = [7]**log.Logger{&n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL}
n.outHandle = outHandle
@@ -111,41 +95,26 @@ 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(n.createLogWriters(threshold, logAndOut), prefix, n.flags)
+ *logger = log.New(io.MultiWriter(counter, logAndOut), prefix, n.flags)
case threshold >= n.logThreshold:
- *logger = log.New(n.createLogWriters(threshold, n.logHandle), prefix, n.flags)
+ *logger = log.New(io.MultiWriter(counter, n.logHandle), prefix, n.flags)
case threshold >= n.stdoutThreshold:
- *logger = log.New(n.createLogWriters(threshold, n.outHandle), prefix, n.flags)
+ *logger = log.New(io.MultiWriter(counter, n.outHandle), prefix, n.flags)
default:
- *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)
+ // counter doesn't care about prefix and flags, so don't use them
+ // for performance.
+ *logger = log.New(counter, "", 0)
}
}
-
- if len(writers) == 1 {
- return handle
- }
-
- return io.MultiWriter(writers...)
}
// SetLogThreshold changes the threshold above which messages are written to the