podman
111 строк · 2.8 Кб
1// Copyright © 2016 Steve Francia <spf@spf13.com>.
2//
3// Use of this source code is governed by an MIT-style
4// license that can be found in the LICENSE file.
5
6package jwalterweatherman7
8import (9"io"10"io/ioutil"11"log"12"os"13)
14
15var (16TRACE *log.Logger17DEBUG *log.Logger18INFO *log.Logger19WARN *log.Logger20ERROR *log.Logger21CRITICAL *log.Logger22FATAL *log.Logger23
24LOG *log.Logger25FEEDBACK *Feedback26
27defaultNotepad *Notepad28)
29
30func reloadDefaultNotepad() {31TRACE = defaultNotepad.TRACE32DEBUG = defaultNotepad.DEBUG33INFO = defaultNotepad.INFO34WARN = defaultNotepad.WARN35ERROR = defaultNotepad.ERROR36CRITICAL = defaultNotepad.CRITICAL37FATAL = defaultNotepad.FATAL38
39LOG = defaultNotepad.LOG40FEEDBACK = defaultNotepad.FEEDBACK41}
42
43func init() {44defaultNotepad = NewNotepad(LevelError, LevelWarn, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)45reloadDefaultNotepad()46}
47
48// SetLogThreshold set the log threshold for the default notepad. Trace by default.
49func SetLogThreshold(threshold Threshold) {50defaultNotepad.SetLogThreshold(threshold)51reloadDefaultNotepad()52}
53
54// SetLogOutput set the log output for the default notepad. Discarded by default.
55func SetLogOutput(handle io.Writer) {56defaultNotepad.SetLogOutput(handle)57reloadDefaultNotepad()58}
59
60// SetStdoutThreshold set the standard output threshold for the default notepad.
61// Info by default.
62func SetStdoutThreshold(threshold Threshold) {63defaultNotepad.SetStdoutThreshold(threshold)64reloadDefaultNotepad()65}
66
67// SetStdoutOutput set the stdout output for the default notepad. Default is stdout.
68func SetStdoutOutput(handle io.Writer) {69defaultNotepad.outHandle = handle70defaultNotepad.init()71reloadDefaultNotepad()72}
73
74// SetPrefix set the prefix for the default logger. Empty by default.
75func SetPrefix(prefix string) {76defaultNotepad.SetPrefix(prefix)77reloadDefaultNotepad()78}
79
80// SetFlags set the flags for the default logger. "log.Ldate | log.Ltime" by default.
81func SetFlags(flags int) {82defaultNotepad.SetFlags(flags)83reloadDefaultNotepad()84}
85
86// SetLogListeners configures the default logger with one or more log listeners.
87func SetLogListeners(l ...LogListener) {88defaultNotepad.logListeners = l89defaultNotepad.init()90reloadDefaultNotepad()91}
92
93// Level returns the current global log threshold.
94func LogThreshold() Threshold {95return defaultNotepad.logThreshold96}
97
98// Level returns the current global output threshold.
99func StdoutThreshold() Threshold {100return defaultNotepad.stdoutThreshold101}
102
103// GetStdoutThreshold returns the defined Treshold for the log logger.
104func GetLogThreshold() Threshold {105return defaultNotepad.GetLogThreshold()106}
107
108// GetStdoutThreshold returns the Treshold for the stdout logger.
109func GetStdoutThreshold() Threshold {110return defaultNotepad.GetStdoutThreshold()111}
112