Dinesh Belwalkar | e63f7f9 | 2019-11-22 23:11:16 +0000 | [diff] [blame] | 1 | package logrus |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "io" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | var ( |
| 10 | // std is the name of the standard logger in stdlib `log` |
| 11 | std = New() |
| 12 | ) |
| 13 | |
| 14 | func StandardLogger() *Logger { |
| 15 | return std |
| 16 | } |
| 17 | |
| 18 | // SetOutput sets the standard logger output. |
| 19 | func SetOutput(out io.Writer) { |
| 20 | std.SetOutput(out) |
| 21 | } |
| 22 | |
| 23 | // SetFormatter sets the standard logger formatter. |
| 24 | func 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. |
| 30 | func SetReportCaller(include bool) { |
| 31 | std.SetReportCaller(include) |
| 32 | } |
| 33 | |
| 34 | // SetLevel sets the standard logger level. |
| 35 | func SetLevel(level Level) { |
| 36 | std.SetLevel(level) |
| 37 | } |
| 38 | |
| 39 | // GetLevel returns the standard logger level. |
| 40 | func 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 |
| 45 | func IsLevelEnabled(level Level) bool { |
| 46 | return std.IsLevelEnabled(level) |
| 47 | } |
| 48 | |
| 49 | // AddHook adds a hook to the standard logger hooks. |
| 50 | func 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. |
| 55 | func 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. |
| 60 | func 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. |
| 69 | func 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. |
| 79 | func 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. |
| 88 | func WithTime(t time.Time) *Entry { |
| 89 | return std.WithTime(t) |
| 90 | } |
| 91 | |
| 92 | // Trace logs a message at level Trace on the standard logger. |
| 93 | func Trace(args ...interface{}) { |
| 94 | std.Trace(args...) |
| 95 | } |
| 96 | |
| 97 | // Debug logs a message at level Debug on the standard logger. |
| 98 | func Debug(args ...interface{}) { |
| 99 | std.Debug(args...) |
| 100 | } |
| 101 | |
| 102 | // Print logs a message at level Info on the standard logger. |
| 103 | func Print(args ...interface{}) { |
| 104 | std.Print(args...) |
| 105 | } |
| 106 | |
| 107 | // Info logs a message at level Info on the standard logger. |
| 108 | func Info(args ...interface{}) { |
| 109 | std.Info(args...) |
| 110 | } |
| 111 | |
| 112 | // Warn logs a message at level Warn on the standard logger. |
| 113 | func Warn(args ...interface{}) { |
| 114 | std.Warn(args...) |
| 115 | } |
| 116 | |
| 117 | // Warning logs a message at level Warn on the standard logger. |
| 118 | func Warning(args ...interface{}) { |
| 119 | std.Warning(args...) |
| 120 | } |
| 121 | |
| 122 | // Error logs a message at level Error on the standard logger. |
| 123 | func Error(args ...interface{}) { |
| 124 | std.Error(args...) |
| 125 | } |
| 126 | |
| 127 | // Panic logs a message at level Panic on the standard logger. |
| 128 | func 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. |
| 133 | func Fatal(args ...interface{}) { |
| 134 | std.Fatal(args...) |
| 135 | } |
| 136 | |
| 137 | // Tracef logs a message at level Trace on the standard logger. |
| 138 | func Tracef(format string, args ...interface{}) { |
| 139 | std.Tracef(format, args...) |
| 140 | } |
| 141 | |
| 142 | // Debugf logs a message at level Debug on the standard logger. |
| 143 | func Debugf(format string, args ...interface{}) { |
| 144 | std.Debugf(format, args...) |
| 145 | } |
| 146 | |
| 147 | // Printf logs a message at level Info on the standard logger. |
| 148 | func Printf(format string, args ...interface{}) { |
| 149 | std.Printf(format, args...) |
| 150 | } |
| 151 | |
| 152 | // Infof logs a message at level Info on the standard logger. |
| 153 | func Infof(format string, args ...interface{}) { |
| 154 | std.Infof(format, args...) |
| 155 | } |
| 156 | |
| 157 | // Warnf logs a message at level Warn on the standard logger. |
| 158 | func Warnf(format string, args ...interface{}) { |
| 159 | std.Warnf(format, args...) |
| 160 | } |
| 161 | |
| 162 | // Warningf logs a message at level Warn on the standard logger. |
| 163 | func Warningf(format string, args ...interface{}) { |
| 164 | std.Warningf(format, args...) |
| 165 | } |
| 166 | |
| 167 | // Errorf logs a message at level Error on the standard logger. |
| 168 | func Errorf(format string, args ...interface{}) { |
| 169 | std.Errorf(format, args...) |
| 170 | } |
| 171 | |
| 172 | // Panicf logs a message at level Panic on the standard logger. |
| 173 | func 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. |
| 178 | func Fatalf(format string, args ...interface{}) { |
| 179 | std.Fatalf(format, args...) |
| 180 | } |
| 181 | |
| 182 | // Traceln logs a message at level Trace on the standard logger. |
| 183 | func Traceln(args ...interface{}) { |
| 184 | std.Traceln(args...) |
| 185 | } |
| 186 | |
| 187 | // Debugln logs a message at level Debug on the standard logger. |
| 188 | func Debugln(args ...interface{}) { |
| 189 | std.Debugln(args...) |
| 190 | } |
| 191 | |
| 192 | // Println logs a message at level Info on the standard logger. |
| 193 | func Println(args ...interface{}) { |
| 194 | std.Println(args...) |
| 195 | } |
| 196 | |
| 197 | // Infoln logs a message at level Info on the standard logger. |
| 198 | func Infoln(args ...interface{}) { |
| 199 | std.Infoln(args...) |
| 200 | } |
| 201 | |
| 202 | // Warnln logs a message at level Warn on the standard logger. |
| 203 | func Warnln(args ...interface{}) { |
| 204 | std.Warnln(args...) |
| 205 | } |
| 206 | |
| 207 | // Warningln logs a message at level Warn on the standard logger. |
| 208 | func Warningln(args ...interface{}) { |
| 209 | std.Warningln(args...) |
| 210 | } |
| 211 | |
| 212 | // Errorln logs a message at level Error on the standard logger. |
| 213 | func Errorln(args ...interface{}) { |
| 214 | std.Errorln(args...) |
| 215 | } |
| 216 | |
| 217 | // Panicln logs a message at level Panic on the standard logger. |
| 218 | func 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. |
| 223 | func Fatalln(args ...interface{}) { |
| 224 | std.Fatalln(args...) |
| 225 | } |