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