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