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