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 creats 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// Tracef logs a message at level Trace on the standard logger.
138func Tracef(format string, args ...interface{}) {
139	std.Tracef(format, args...)
140}
141
142// Debugf logs a message at level Debug on the standard logger.
143func Debugf(format string, args ...interface{}) {
144	std.Debugf(format, args...)
145}
146
147// Printf logs a message at level Info on the standard logger.
148func Printf(format string, args ...interface{}) {
149	std.Printf(format, args...)
150}
151
152// Infof logs a message at level Info on the standard logger.
153func Infof(format string, args ...interface{}) {
154	std.Infof(format, args...)
155}
156
157// Warnf logs a message at level Warn on the standard logger.
158func Warnf(format string, args ...interface{}) {
159	std.Warnf(format, args...)
160}
161
162// Warningf logs a message at level Warn on the standard logger.
163func Warningf(format string, args ...interface{}) {
164	std.Warningf(format, args...)
165}
166
167// Errorf logs a message at level Error on the standard logger.
168func Errorf(format string, args ...interface{}) {
169	std.Errorf(format, args...)
170}
171
172// Panicf logs a message at level Panic on the standard logger.
173func Panicf(format string, args ...interface{}) {
174	std.Panicf(format, args...)
175}
176
177// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
178func Fatalf(format string, args ...interface{}) {
179	std.Fatalf(format, args...)
180}
181
182// Traceln logs a message at level Trace on the standard logger.
183func Traceln(args ...interface{}) {
184	std.Traceln(args...)
185}
186
187// Debugln logs a message at level Debug on the standard logger.
188func Debugln(args ...interface{}) {
189	std.Debugln(args...)
190}
191
192// Println logs a message at level Info on the standard logger.
193func Println(args ...interface{}) {
194	std.Println(args...)
195}
196
197// Infoln logs a message at level Info on the standard logger.
198func Infoln(args ...interface{}) {
199	std.Infoln(args...)
200}
201
202// Warnln logs a message at level Warn on the standard logger.
203func Warnln(args ...interface{}) {
204	std.Warnln(args...)
205}
206
207// Warningln logs a message at level Warn on the standard logger.
208func Warningln(args ...interface{}) {
209	std.Warningln(args...)
210}
211
212// Errorln logs a message at level Error on the standard logger.
213func Errorln(args ...interface{}) {
214	std.Errorln(args...)
215}
216
217// Panicln logs a message at level Panic on the standard logger.
218func Panicln(args ...interface{}) {
219	std.Panicln(args...)
220}
221
222// Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
223func Fatalln(args ...interface{}) {
224	std.Fatalln(args...)
225}
226