| 1 |
// Copyright © 2016 Steve Francia <[email protected]>. |
| 2 |
// |
| 3 |
// Use of this source code is governed by an MIT-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package jwalterweatherman |
| 7 |
|
| 8 |
import ( |
| 9 |
"io" |
| 10 |
"io/ioutil" |
| 11 |
"log" |
| 12 |
"os" |
| 13 |
) |
| 14 |
|
| 15 |
var ( |
| 16 |
TRACE *log.Logger |
| 17 |
DEBUG *log.Logger |
| 18 |
INFO *log.Logger |
| 19 |
WARN *log.Logger |
| 20 |
ERROR *log.Logger |
| 21 |
CRITICAL *log.Logger |
| 22 |
FATAL *log.Logger |
| 23 |
|
| 24 |
LOG *log.Logger |
| 25 |
FEEDBACK *Feedback |
| 26 |
|
| 27 |
defaultNotepad *Notepad |
| 28 |
) |
| 29 |
|
| 30 |
func reloadDefaultNotepad() { |
| 31 |
TRACE = defaultNotepad.TRACE |
| 32 |
DEBUG = defaultNotepad.DEBUG |
| 33 |
INFO = defaultNotepad.INFO |
| 34 |
WARN = defaultNotepad.WARN |
| 35 |
ERROR = defaultNotepad.ERROR |
| 36 |
CRITICAL = defaultNotepad.CRITICAL |
| 37 |
FATAL = defaultNotepad.FATAL |
| 38 |
|
| 39 |
LOG = defaultNotepad.LOG |
| 40 |
FEEDBACK = defaultNotepad.FEEDBACK |
| 41 |
} |
| 42 |
|
| 43 |
func init() { |
| 44 |
defaultNotepad = NewNotepad(LevelError, LevelWarn, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime) |
| 45 |
reloadDefaultNotepad() |
| 46 |
} |
| 47 |
|
| 48 |
// SetLogThreshold set the log threshold for the default notepad. Trace by default. |
| 49 |
func SetLogThreshold(threshold Threshold) { |
| 50 |
defaultNotepad.SetLogThreshold(threshold) |
| 51 |
reloadDefaultNotepad() |
| 52 |
} |
| 53 |
|
| 54 |
// SetLogOutput set the log output for the default notepad. Discarded by default. |
| 55 |
func SetLogOutput(handle io.Writer) { |
| 56 |
defaultNotepad.SetLogOutput(handle) |
| 57 |
reloadDefaultNotepad() |
| 58 |
} |
| 59 |
|
| 60 |
// SetStdoutThreshold set the standard output threshold for the default notepad. |
| 61 |
// Info by default. |
| 62 |
func SetStdoutThreshold(threshold Threshold) { |
| 63 |
defaultNotepad.SetStdoutThreshold(threshold) |
| 64 |
reloadDefaultNotepad() |
| 65 |
} |
| 66 |
|
| 67 |
// SetPrefix set the prefix for the default logger. Empty by default. |
| 68 |
func SetPrefix(prefix string) { |
| 69 |
defaultNotepad.SetPrefix(prefix) |
| 70 |
reloadDefaultNotepad() |
| 71 |
} |
| 72 |
|
| 73 |
// SetFlags set the flags for the default logger. "log.Ldate | log.Ltime" by default. |
| 74 |
func SetFlags(flags int) { |
| 75 |
defaultNotepad.SetFlags(flags) |
| 76 |
reloadDefaultNotepad() |
| 77 |
} |
| 78 |
|
| 79 |
// Level returns the current global log threshold. |
| 80 |
func LogThreshold() Threshold { |
| 81 |
return defaultNotepad.logThreshold |
| 82 |
} |
| 83 |
|
| 84 |
// Level returns the current global output threshold. |
| 85 |
func StdoutThreshold() Threshold { |
| 86 |
return defaultNotepad.stdoutThreshold |
| 87 |
} |
| 88 |
|
| 89 |
// GetStdoutThreshold returns the defined Treshold for the log logger. |
| 90 |
func GetLogThreshold() Threshold { |
| 91 |
return defaultNotepad.GetLogThreshold() |
| 92 |
} |
| 93 |
|
| 94 |
// GetStdoutThreshold returns the Treshold for the stdout logger. |
| 95 |
func GetStdoutThreshold() Threshold { |
| 96 |
return defaultNotepad.GetStdoutThreshold() |
| 97 |
} |
| 98 |
|
| 99 |
// LogCountForLevel returns the number of log invocations for a given threshold. |
| 100 |
func LogCountForLevel(l Threshold) uint64 { |
| 101 |
return defaultNotepad.LogCountForLevel(l) |
| 102 |
} |
| 103 |
|
| 104 |
// LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations |
| 105 |
// greater than or equal to a given threshold. |
| 106 |
func LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 { |
| 107 |
return defaultNotepad.LogCountForLevelsGreaterThanorEqualTo(threshold) |
| 108 |
} |
| 109 |
|
| 110 |
// ResetLogCounters resets the invocation counters for all levels. |
| 111 |
func ResetLogCounters() { |
| 112 |
defaultNotepad.ResetLogCounters() |
| 113 |
} |