blob: 9a0120ac1ddb8a66f49923bf2737a6e6e33603d0 [file] [log] [blame]
Jonathan Hartf86817b2018-08-17 10:35:54 -07001package logrus
2
3import (
4 "io"
5)
6
7var (
8 // std is the name of the standard logger in stdlib `log`
9 std = New()
10)
11
12func StandardLogger() *Logger {
13 return std
14}
15
16// SetOutput sets the standard logger output.
17func SetOutput(out io.Writer) {
18 std.mu.Lock()
19 defer std.mu.Unlock()
20 std.Out = out
21}
22
23// SetFormatter sets the standard logger formatter.
24func SetFormatter(formatter Formatter) {
25 std.mu.Lock()
26 defer std.mu.Unlock()
27 std.Formatter = formatter
28}
29
30// SetLevel sets the standard logger level.
31func SetLevel(level Level) {
32 std.mu.Lock()
33 defer std.mu.Unlock()
34 std.Level = level
35}
36
37// GetLevel returns the standard logger level.
38func GetLevel() Level {
39 std.mu.Lock()
40 defer std.mu.Unlock()
41 return std.Level
42}
43
44// AddHook adds a hook to the standard logger hooks.
45func AddHook(hook Hook) {
46 std.mu.Lock()
47 defer std.mu.Unlock()
48 std.Hooks.Add(hook)
49}
50
51// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
52func WithError(err error) *Entry {
53 return std.WithField(ErrorKey, err)
54}
55
56// WithField creates an entry from the standard logger and adds a field to
57// it. If you want multiple fields, use `WithFields`.
58//
59// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
60// or Panic on the Entry it returns.
61func WithField(key string, value interface{}) *Entry {
62 return std.WithField(key, value)
63}
64
65// WithFields creates an entry from the standard logger and adds multiple
66// fields to it. This is simply a helper for `WithField`, invoking it
67// once for each field.
68//
69// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
70// or Panic on the Entry it returns.
71func WithFields(fields Fields) *Entry {
72 return std.WithFields(fields)
73}
74
75// Debug logs a message at level Debug on the standard logger.
76func Debug(args ...interface{}) {
77 std.Debug(args...)
78}
79
80// Print logs a message at level Info on the standard logger.
81func Print(args ...interface{}) {
82 std.Print(args...)
83}
84
85// Info logs a message at level Info on the standard logger.
86func Info(args ...interface{}) {
87 std.Info(args...)
88}
89
90// Warn logs a message at level Warn on the standard logger.
91func Warn(args ...interface{}) {
92 std.Warn(args...)
93}
94
95// Warning logs a message at level Warn on the standard logger.
96func Warning(args ...interface{}) {
97 std.Warning(args...)
98}
99
100// Error logs a message at level Error on the standard logger.
101func Error(args ...interface{}) {
102 std.Error(args...)
103}
104
105// Panic logs a message at level Panic on the standard logger.
106func Panic(args ...interface{}) {
107 std.Panic(args...)
108}
109
110// Fatal logs a message at level Fatal on the standard logger.
111func Fatal(args ...interface{}) {
112 std.Fatal(args...)
113}
114
115// Debugf logs a message at level Debug on the standard logger.
116func Debugf(format string, args ...interface{}) {
117 std.Debugf(format, args...)
118}
119
120// Printf logs a message at level Info on the standard logger.
121func Printf(format string, args ...interface{}) {
122 std.Printf(format, args...)
123}
124
125// Infof logs a message at level Info on the standard logger.
126func Infof(format string, args ...interface{}) {
127 std.Infof(format, args...)
128}
129
130// Warnf logs a message at level Warn on the standard logger.
131func Warnf(format string, args ...interface{}) {
132 std.Warnf(format, args...)
133}
134
135// Warningf logs a message at level Warn on the standard logger.
136func Warningf(format string, args ...interface{}) {
137 std.Warningf(format, args...)
138}
139
140// Errorf logs a message at level Error on the standard logger.
141func Errorf(format string, args ...interface{}) {
142 std.Errorf(format, args...)
143}
144
145// Panicf logs a message at level Panic on the standard logger.
146func Panicf(format string, args ...interface{}) {
147 std.Panicf(format, args...)
148}
149
150// Fatalf logs a message at level Fatal on the standard logger.
151func Fatalf(format string, args ...interface{}) {
152 std.Fatalf(format, args...)
153}
154
155// Debugln logs a message at level Debug on the standard logger.
156func Debugln(args ...interface{}) {
157 std.Debugln(args...)
158}
159
160// Println logs a message at level Info on the standard logger.
161func Println(args ...interface{}) {
162 std.Println(args...)
163}
164
165// Infoln logs a message at level Info on the standard logger.
166func Infoln(args ...interface{}) {
167 std.Infoln(args...)
168}
169
170// Warnln logs a message at level Warn on the standard logger.
171func Warnln(args ...interface{}) {
172 std.Warnln(args...)
173}
174
175// Warningln logs a message at level Warn on the standard logger.
176func Warningln(args ...interface{}) {
177 std.Warningln(args...)
178}
179
180// Errorln logs a message at level Error on the standard logger.
181func Errorln(args ...interface{}) {
182 std.Errorln(args...)
183}
184
185// Panicln logs a message at level Panic on the standard logger.
186func Panicln(args ...interface{}) {
187 std.Panicln(args...)
188}
189
190// Fatalln logs a message at level Fatal on the standard logger.
191func Fatalln(args ...interface{}) {
192 std.Fatalln(args...)
193}