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