| 1 | // mauLogger - A logger for Go programs |
| 2 | // Copyright (c) 2016-2021 Tulir Asokan |
| 3 | // |
| 4 | // This Source Code Form is subject to the terms of the Mozilla Public |
| 5 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 | |
| 8 | package maulogger |
| 9 | |
| 10 | import ( |
| 11 | "os" |
| 12 | ) |
| 13 | |
| 14 | // DefaultLogger ... |
| 15 | var DefaultLogger = Create().(*BasicLogger) |
| 16 | |
| 17 | // SetWriter formats the given parts with fmt.Sprint and logs the result with the SetWriter level |
| 18 | func SetWriter(w *os.File) { |
| 19 | DefaultLogger.SetWriter(w) |
| 20 | } |
| 21 | |
| 22 | // OpenFile formats the given parts with fmt.Sprint and logs the result with the OpenFile level |
| 23 | func OpenFile() error { |
| 24 | return DefaultLogger.OpenFile() |
| 25 | } |
| 26 | |
| 27 | // Close formats the given parts with fmt.Sprint and logs the result with the Close level |
| 28 | func Close() error { |
| 29 | return DefaultLogger.Close() |
| 30 | } |
| 31 | |
| 32 | // Sub creates a Sublogger |
| 33 | func Sub(module string) Logger { |
| 34 | return DefaultLogger.Sub(module) |
| 35 | } |
| 36 | |
| 37 | // Raw formats the given parts with fmt.Sprint and logs the result with the Raw level |
| 38 | func Rawm(level Level, metadata map[string]interface{}, module, message string) { |
| 39 | DefaultLogger.Raw(level, metadata, module, message) |
| 40 | } |
| 41 | |
| 42 | func Raw(level Level, module, message string) { |
| 43 | DefaultLogger.Raw(level, map[string]interface{}{}, module, message) |
| 44 | } |
| 45 | |
| 46 | // Log formats the given parts with fmt.Sprint and logs the result with the given level |
| 47 | func Log(level Level, parts ...interface{}) { |
| 48 | DefaultLogger.DefaultSub.Log(level, parts...) |
| 49 | } |
| 50 | |
| 51 | // Logln formats the given parts with fmt.Sprintln and logs the result with the given level |
| 52 | func Logln(level Level, parts ...interface{}) { |
| 53 | DefaultLogger.DefaultSub.Logln(level, parts...) |
| 54 | } |
| 55 | |
| 56 | // Logf formats the given message and args with fmt.Sprintf and logs the result with the given level |
| 57 | func Logf(level Level, message string, args ...interface{}) { |
| 58 | DefaultLogger.DefaultSub.Logf(level, message, args...) |
| 59 | } |
| 60 | |
| 61 | // Logfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the given level |
| 62 | func Logfln(level Level, message string, args ...interface{}) { |
| 63 | DefaultLogger.DefaultSub.Logfln(level, message, args...) |
| 64 | } |
| 65 | |
| 66 | // Debug formats the given parts with fmt.Sprint and logs the result with the Debug level |
| 67 | func Debug(parts ...interface{}) { |
| 68 | DefaultLogger.DefaultSub.Debug(parts...) |
| 69 | } |
| 70 | |
| 71 | // Debugln formats the given parts with fmt.Sprintln and logs the result with the Debug level |
| 72 | func Debugln(parts ...interface{}) { |
| 73 | DefaultLogger.DefaultSub.Debugln(parts...) |
| 74 | } |
| 75 | |
| 76 | // Debugf formats the given message and args with fmt.Sprintf and logs the result with the Debug level |
| 77 | func Debugf(message string, args ...interface{}) { |
| 78 | DefaultLogger.DefaultSub.Debugf(message, args...) |
| 79 | } |
| 80 | |
| 81 | // Debugfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Debug level |
| 82 | func Debugfln(message string, args ...interface{}) { |
| 83 | DefaultLogger.DefaultSub.Debugfln(message, args...) |
| 84 | } |
| 85 | |
| 86 | // Info formats the given parts with fmt.Sprint and logs the result with the Info level |
| 87 | func Info(parts ...interface{}) { |
| 88 | DefaultLogger.DefaultSub.Info(parts...) |
| 89 | } |
| 90 | |
| 91 | // Infoln formats the given parts with fmt.Sprintln and logs the result with the Info level |
| 92 | func Infoln(parts ...interface{}) { |
| 93 | DefaultLogger.DefaultSub.Infoln(parts...) |
| 94 | } |
| 95 | |
| 96 | // Infof formats the given message and args with fmt.Sprintf and logs the result with the Info level |
| 97 | func Infof(message string, args ...interface{}) { |
| 98 | DefaultLogger.DefaultSub.Infof(message, args...) |
| 99 | } |
| 100 | |
| 101 | // Infofln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Info level |
| 102 | func Infofln(message string, args ...interface{}) { |
| 103 | DefaultLogger.DefaultSub.Infofln(message, args...) |
| 104 | } |
| 105 | |
| 106 | // Warn formats the given parts with fmt.Sprint and logs the result with the Warn level |
| 107 | func Warn(parts ...interface{}) { |
| 108 | DefaultLogger.DefaultSub.Warn(parts...) |
| 109 | } |
| 110 | |
| 111 | // Warnln formats the given parts with fmt.Sprintln and logs the result with the Warn level |
| 112 | func Warnln(parts ...interface{}) { |
| 113 | DefaultLogger.DefaultSub.Warnln(parts...) |
| 114 | } |
| 115 | |
| 116 | // Warnf formats the given message and args with fmt.Sprintf and logs the result with the Warn level |
| 117 | func Warnf(message string, args ...interface{}) { |
| 118 | DefaultLogger.DefaultSub.Warnf(message, args...) |
| 119 | } |
| 120 | |
| 121 | // Warnfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Warn level |
| 122 | func Warnfln(message string, args ...interface{}) { |
| 123 | DefaultLogger.DefaultSub.Warnfln(message, args...) |
| 124 | } |
| 125 | |
| 126 | // Error formats the given parts with fmt.Sprint and logs the result with the Error level |
| 127 | func Error(parts ...interface{}) { |
| 128 | DefaultLogger.DefaultSub.Error(parts...) |
| 129 | } |
| 130 | |
| 131 | // Errorln formats the given parts with fmt.Sprintln and logs the result with the Error level |
| 132 | func Errorln(parts ...interface{}) { |
| 133 | DefaultLogger.DefaultSub.Errorln(parts...) |
| 134 | } |
| 135 | |
| 136 | // Errorf formats the given message and args with fmt.Sprintf and logs the result with the Error level |
| 137 | func Errorf(message string, args ...interface{}) { |
| 138 | DefaultLogger.DefaultSub.Errorf(message, args...) |
| 139 | } |
| 140 | |
| 141 | // Errorfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Error level |
| 142 | func Errorfln(message string, args ...interface{}) { |
| 143 | DefaultLogger.DefaultSub.Errorfln(message, args...) |
| 144 | } |
| 145 | |
| 146 | // Fatal formats the given parts with fmt.Sprint and logs the result with the Fatal level |
| 147 | func Fatal(parts ...interface{}) { |
| 148 | DefaultLogger.DefaultSub.Fatal(parts...) |
| 149 | } |
| 150 | |
| 151 | // Fatalln formats the given parts with fmt.Sprintln and logs the result with the Fatal level |
| 152 | func Fatalln(parts ...interface{}) { |
| 153 | DefaultLogger.DefaultSub.Fatalln(parts...) |
| 154 | } |
| 155 | |
| 156 | // Fatalf formats the given message and args with fmt.Sprintf and logs the result with the Fatal level |
| 157 | func Fatalf(message string, args ...interface{}) { |
| 158 | DefaultLogger.DefaultSub.Fatalf(message, args...) |
| 159 | } |
| 160 | |
| 161 | // Fatalfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Fatal level |
| 162 | func Fatalfln(message string, args ...interface{}) { |
| 163 | DefaultLogger.DefaultSub.Fatalfln(message, args...) |
| 164 | } |
| 165 | |
| 166 | // Log formats the given parts with fmt.Sprint and logs the result with the given level |
| 167 | func (log *BasicLogger) Log(level Level, parts ...interface{}) { |
| 168 | log.DefaultSub.Log(level, parts...) |
| 169 | } |
| 170 | |
| 171 | // Logln formats the given parts with fmt.Sprintln and logs the result with the given level |
| 172 | func (log *BasicLogger) Logln(level Level, parts ...interface{}) { |
| 173 | log.DefaultSub.Logln(level, parts...) |
| 174 | } |
| 175 | |
| 176 | // Logf formats the given message and args with fmt.Sprintf and logs the result with the given level |
| 177 | func (log *BasicLogger) Logf(level Level, message string, args ...interface{}) { |
| 178 | log.DefaultSub.Logf(level, message, args...) |
| 179 | } |
| 180 | |
| 181 | // Logfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the given level |
| 182 | func (log *BasicLogger) Logfln(level Level, message string, args ...interface{}) { |
| 183 | log.DefaultSub.Logfln(level, message, args...) |
| 184 | } |
| 185 | |
| 186 | // Debug formats the given parts with fmt.Sprint and logs the result with the Debug level |
| 187 | func (log *BasicLogger) Debug(parts ...interface{}) { |
| 188 | log.DefaultSub.Debug(parts...) |
| 189 | } |
| 190 | |
| 191 | // Debugln formats the given parts with fmt.Sprintln and logs the result with the Debug level |
| 192 | func (log *BasicLogger) Debugln(parts ...interface{}) { |
| 193 | log.DefaultSub.Debugln(parts...) |
| 194 | } |
| 195 | |
| 196 | // Debugf formats the given message and args with fmt.Sprintf and logs the result with the Debug level |
| 197 | func (log *BasicLogger) Debugf(message string, args ...interface{}) { |
| 198 | log.DefaultSub.Debugf(message, args...) |
| 199 | } |
| 200 | |
| 201 | // Debugfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Debug level |
| 202 | func (log *BasicLogger) Debugfln(message string, args ...interface{}) { |
| 203 | log.DefaultSub.Debugfln(message, args...) |
| 204 | } |
| 205 | |
| 206 | // Info formats the given parts with fmt.Sprint and logs the result with the Info level |
| 207 | func (log *BasicLogger) Info(parts ...interface{}) { |
| 208 | log.DefaultSub.Info(parts...) |
| 209 | } |
| 210 | |
| 211 | // Infoln formats the given parts with fmt.Sprintln and logs the result with the Info level |
| 212 | func (log *BasicLogger) Infoln(parts ...interface{}) { |
| 213 | log.DefaultSub.Infoln(parts...) |
| 214 | } |
| 215 | |
| 216 | // Infofln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Info level |
| 217 | func (log *BasicLogger) Infofln(message string, args ...interface{}) { |
| 218 | log.DefaultSub.Infofln(message, args...) |
| 219 | } |
| 220 | |
| 221 | // Infof formats the given message and args with fmt.Sprintf and logs the result with the Info level |
| 222 | func (log *BasicLogger) Infof(message string, args ...interface{}) { |
| 223 | log.DefaultSub.Infof(message, args...) |
| 224 | } |
| 225 | |
| 226 | // Warn formats the given parts with fmt.Sprint and logs the result with the Warn level |
| 227 | func (log *BasicLogger) Warn(parts ...interface{}) { |
| 228 | log.DefaultSub.Warn(parts...) |
| 229 | } |
| 230 | |
| 231 | // Warnln formats the given parts with fmt.Sprintln and logs the result with the Warn level |
| 232 | func (log *BasicLogger) Warnln(parts ...interface{}) { |
| 233 | log.DefaultSub.Warnln(parts...) |
| 234 | } |
| 235 | |
| 236 | // Warnfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Warn level |
| 237 | func (log *BasicLogger) Warnfln(message string, args ...interface{}) { |
| 238 | log.DefaultSub.Warnfln(message, args...) |
| 239 | } |
| 240 | |
| 241 | // Warnf formats the given message and args with fmt.Sprintf and logs the result with the Warn level |
| 242 | func (log *BasicLogger) Warnf(message string, args ...interface{}) { |
| 243 | log.DefaultSub.Warnf(message, args...) |
| 244 | } |
| 245 | |
| 246 | // Error formats the given parts with fmt.Sprint and logs the result with the Error level |
| 247 | func (log *BasicLogger) Error(parts ...interface{}) { |
| 248 | log.DefaultSub.Error(parts...) |
| 249 | } |
| 250 | |
| 251 | // Errorln formats the given parts with fmt.Sprintln and logs the result with the Error level |
| 252 | func (log *BasicLogger) Errorln(parts ...interface{}) { |
| 253 | log.DefaultSub.Errorln(parts...) |
| 254 | } |
| 255 | |
| 256 | // Errorf formats the given message and args with fmt.Sprintf and logs the result with the Error level |
| 257 | func (log *BasicLogger) Errorf(message string, args ...interface{}) { |
| 258 | log.DefaultSub.Errorf(message, args...) |
| 259 | } |
| 260 | |
| 261 | // Errorfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Error level |
| 262 | func (log *BasicLogger) Errorfln(message string, args ...interface{}) { |
| 263 | log.DefaultSub.Errorfln(message, args...) |
| 264 | } |
| 265 | |
| 266 | // Fatal formats the given parts with fmt.Sprint and logs the result with the Fatal level |
| 267 | func (log *BasicLogger) Fatal(parts ...interface{}) { |
| 268 | log.DefaultSub.Fatal(parts...) |
| 269 | } |
| 270 | |
| 271 | // Fatalln formats the given parts with fmt.Sprintln and logs the result with the Fatal level |
| 272 | func (log *BasicLogger) Fatalln(parts ...interface{}) { |
| 273 | log.DefaultSub.Fatalln(parts...) |
| 274 | } |
| 275 | |
| 276 | // Fatalf formats the given message and args with fmt.Sprintf and logs the result with the Fatal level |
| 277 | func (log *BasicLogger) Fatalf(message string, args ...interface{}) { |
| 278 | log.DefaultSub.Fatalf(message, args...) |
| 279 | } |
| 280 | |
| 281 | // Fatalfln formats the given message and args with fmt.Sprintf, appends a newline and logs the result with the Fatal level |
| 282 | func (log *BasicLogger) Fatalfln(message string, args ...interface{}) { |
| 283 | log.DefaultSub.Fatalfln(message, args...) |
| 284 | } |