From 7b320119ba532fd409ec7dade7ad02011c309599 Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Wed, 18 Oct 2017 13:15:14 +0100 Subject: Update dependencies --- .../spf13/jwalterweatherman/log_counter.go | 1 - .../github.com/spf13/jwalterweatherman/notepad.go | 89 +++++++++++----------- 2 files changed, 44 insertions(+), 46 deletions(-) (limited to 'vendor/github.com/spf13/jwalterweatherman') diff --git a/vendor/github.com/spf13/jwalterweatherman/log_counter.go b/vendor/github.com/spf13/jwalterweatherman/log_counter.go index 570db1d..11423ac 100644 --- a/vendor/github.com/spf13/jwalterweatherman/log_counter.go +++ b/vendor/github.com/spf13/jwalterweatherman/log_counter.go @@ -27,7 +27,6 @@ func (c *logCounter) getCount() uint64 { func (c *logCounter) Write(p []byte) (n int, err error) { c.incr() - return len(p), nil } diff --git a/vendor/github.com/spf13/jwalterweatherman/notepad.go b/vendor/github.com/spf13/jwalterweatherman/notepad.go index 5a623f4..ae5aaf7 100644 --- a/vendor/github.com/spf13/jwalterweatherman/notepad.go +++ b/vendor/github.com/spf13/jwalterweatherman/notepad.go @@ -9,7 +9,6 @@ import ( "fmt" "io" "log" - "os" ) type Threshold int @@ -38,11 +37,7 @@ var prefixes map[Threshold]string = map[Threshold]string{ LevelFatal: "FATAL", } -func prefix(t Threshold) string { - return t.String() + " " -} - -// Notepad is where you leave a note ! +// Notepad is where you leave a note! type Notepad struct { TRACE *log.Logger DEBUG *log.Logger @@ -55,7 +50,7 @@ type Notepad struct { LOG *log.Logger FEEDBACK *Feedback - loggers []**log.Logger + loggers [7]**log.Logger logHandle io.Writer outHandle io.Writer logThreshold Threshold @@ -71,11 +66,11 @@ type Notepad struct { func NewNotepad(outThreshold Threshold, logThreshold Threshold, outHandle, logHandle io.Writer, prefix string, flags int) *Notepad { n := &Notepad{} - n.loggers = append(n.loggers, &n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL) - n.logHandle = logHandle + n.loggers = [7]**log.Logger{&n.TRACE, &n.DEBUG, &n.INFO, &n.WARN, &n.ERROR, &n.CRITICAL, &n.FATAL} n.outHandle = outHandle - n.logThreshold = logThreshold + n.logHandle = logHandle n.stdoutThreshold = outThreshold + n.logThreshold = logThreshold if len(prefix) != 0 { n.prefix = "[" + prefix + "] " @@ -88,54 +83,48 @@ func NewNotepad(outThreshold Threshold, logThreshold Threshold, outHandle, logHa n.LOG = log.New(n.logHandle, "LOG: ", n.flags) - - n.FEEDBACK = &Feedback{n} + n.FEEDBACK = &Feedback{out: log.New(outHandle, "", 0), log: n.LOG} n.init() - return n } -// Feedback is special. It writes plainly to the output while -// logging with the standard extra information (date, file, etc) -// Only Println and Printf are currently provided for this -type Feedback struct { - *Notepad -} - -// init create the loggers for each level depending on the notepad thresholds +// init creates the loggers for each level depending on the notepad thresholds. func (n *Notepad) init() { - bothHandle := io.MultiWriter(n.outHandle, n.logHandle) + logAndOut := io.MultiWriter(n.outHandle, n.logHandle) 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, bothHandle), n.prefix+prefix(threshold), n.flags) + *logger = log.New(io.MultiWriter(counter, logAndOut), prefix, n.flags) case threshold >= n.logThreshold: - *logger = log.New(io.MultiWriter(counter, n.logHandle), n.prefix+prefix(threshold), n.flags) + *logger = log.New(io.MultiWriter(counter, n.logHandle), prefix, n.flags) case threshold >= n.stdoutThreshold: - *logger = log.New(io.MultiWriter(counter, os.Stdout), n.prefix+prefix(threshold), n.flags) + *logger = log.New(io.MultiWriter(counter, n.outHandle), prefix, n.flags) default: - *logger = log.New(counter, n.prefix+prefix(threshold), n.flags) + // counter doesn't care about prefix and flags, so don't use them + // for performance. + *logger = log.New(counter, "", 0) } } } -// SetLogThreshold change the threshold above which messages are written to the -// log file +// SetLogThreshold changes the threshold above which messages are written to the +// log file. func (n *Notepad) SetLogThreshold(threshold Threshold) { n.logThreshold = threshold n.init() } -// SetLogOutput change the file where log messages are written +// SetLogOutput changes the file where log messages are written. func (n *Notepad) SetLogOutput(handle io.Writer) { n.logHandle = handle n.init() @@ -146,8 +135,8 @@ func (n *Notepad) GetLogThreshold() Threshold { return n.logThreshold } -// SetStdoutThreshold change the threshold above which messages are written to the -// standard output +// SetStdoutThreshold changes the threshold above which messages are written to the +// standard output. func (n *Notepad) SetStdoutThreshold(threshold Threshold) { n.stdoutThreshold = threshold n.init() @@ -158,8 +147,8 @@ func (n *Notepad) GetStdoutThreshold() Threshold { return n.stdoutThreshold } -// SetPrefix change the prefix used by the notepad. Prefixes are displayed between -// brackets at the begining of the line. An empty prefix won't be displayed at all. +// SetPrefix changes the prefix used by the notepad. Prefixes are displayed between +// brackets at the beginning of the line. An empty prefix won't be displayed at all. func (n *Notepad) SetPrefix(prefix string) { if len(prefix) != 0 { n.prefix = "[" + prefix + "] " @@ -176,20 +165,30 @@ func (n *Notepad) SetFlags(flags int) { n.init() } -// Feedback is special. It writes plainly to the output while -// logging with the standard extra information (date, file, etc) -// Only Println and Printf are currently provided for this +// Feedback writes plainly to the outHandle while +// logging with the standard extra information (date, file, etc). +type Feedback struct { + out *log.Logger + log *log.Logger +} + func (fb *Feedback) Println(v ...interface{}) { - s := fmt.Sprintln(v...) - fmt.Print(s) - fb.LOG.Output(2, s) + fb.output(fmt.Sprintln(v...)) } -// Feedback is special. It writes plainly to the output while -// logging with the standard extra information (date, file, etc) -// Only Println and Printf are currently provided for this func (fb *Feedback) Printf(format string, v ...interface{}) { - s := fmt.Sprintf(format, v...) - fmt.Print(s) - fb.LOG.Output(2, s) + fb.output(fmt.Sprintf(format, v...)) +} + +func (fb *Feedback) Print(v ...interface{}) { + fb.output(fmt.Sprint(v...)) +} + +func (fb *Feedback) output(s string) { + if fb.out != nil { + fb.out.Output(2, s) + } + if fb.log != nil { + fb.log.Output(2, s) + } } -- cgit v1.2.3