github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekalog/logger_finishers.go (about) 1 // Copyright © 2018-2021. All rights reserved. 2 // Author: Ilya Stroy. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 package ekalog 7 8 import ( 9 "fmt" 10 11 "github.com/qioalice/ekago/v3/ekaerr" 12 "github.com/qioalice/ekago/v3/internal/ekaletter" 13 ) 14 15 // Log writes log message with desired 'level', 16 // analyzing 'args' in the most powerful and smart way: 17 // 18 // - args[0] could be printf-like format string, then next N args will be 19 // its printf values (N - num of format's printf verbs), 20 // and M-N (where M is total count of args) will be treated as 21 // explicit or implicit fields (depends on what kind of fields are allowed); 22 // 23 // - If only explicit fields are enabled (Options.OnlyExplicitFields(true)), 24 // all args except explicit fields will be form log's message using fmt.Sprint 25 // (the same way as LogStrict does), but you still can pass explicit fields also; 26 // 27 // - If both of explicit and implicit fields are enabled (by default), 28 // only first non-explicit field arg forms log's message using "%+v" printf verb. 29 // Others ones are treated as explicit and implicit (including unnamed) fields. 30 // 31 // Not bad, huh? 32 func (l *Logger) Log(level Level, args ...any) (this *Logger) { 33 return l.log(level, "", nil, args, nil) 34 } 35 36 // Logf writes log message with desired 'level', generating log message using 37 // fmt.Sprintf(format, args...) if 'format' != "" or fmt.Sprint(args...) otherwise. 38 // 39 // NOTICE! 40 // You can NOT add explicit/implicit fields using this method. And thus there is 41 // no reflections (usage of Golang 'reflect' package). 42 func (l *Logger) Logf(level Level, format string, args ...any) (this *Logger) { 43 return l.log(level, fmt.Sprintf(format, args...), nil, nil, nil) 44 } 45 46 func (l *Logger) Logw(level Level, msg string, fields ...ekaletter.LetterField) (this *Logger) { 47 return l.log(level, msg, nil, nil, fields) 48 } 49 func (l *Logger) Logww(level Level, msg string, fields []ekaletter.LetterField) (this *Logger) { 50 return l.log(level, msg, nil, nil, fields) 51 } 52 53 // ---------------------------------------------------------------------------- // 54 55 // Debug is the same as Log(LEVEL_DEBUG, args...). 56 // Read more: Logger.Log(). 57 func (l *Logger) Debug(args ...any) (this *Logger) { 58 return l.log(LEVEL_DEBUG, "", nil, args, nil) 59 } 60 61 // Debugf is the same as Logf(LEVEL_DEBUG, format, args...). 62 // Read more: Logger.Logf(). 63 func (l *Logger) Debugf(format string, args ...any) (this *Logger) { 64 return l.log(LEVEL_DEBUG, fmt.Sprintf(format, args...), nil, nil, nil) 65 } 66 67 func (l *Logger) Debugw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 68 return l.log(LEVEL_DEBUG, msg, nil, nil, fields) 69 } 70 func (l *Logger) Debugww(msg string, fields []ekaletter.LetterField) (this *Logger) { 71 return l.log(LEVEL_DEBUG, msg, nil, nil, fields) 72 } 73 74 // ---------------------------------------------------------------------------- // 75 76 // Info is the same as Log(LEVEL_INFO, args...). 77 // Read more: Logger.Log(). 78 func (l *Logger) Info(args ...any) (this *Logger) { 79 return l.log(LEVEL_INFO, "", nil, args, nil) 80 } 81 82 // Infof is the same as Logf(LEVEL_INFO, format, args...). 83 // Read more: Logger.Logf(). 84 func (l *Logger) Infof(format string, args ...any) (this *Logger) { 85 return l.log(LEVEL_INFO, fmt.Sprintf(format, args...), nil, nil, nil) 86 } 87 88 func (l *Logger) Infow(msg string, fields ...ekaletter.LetterField) (this *Logger) { 89 return l.log(LEVEL_INFO, msg, nil, nil, fields) 90 } 91 func (l *Logger) Infoww(msg string, fields []ekaletter.LetterField) (this *Logger) { 92 return l.log(LEVEL_INFO, msg, nil, nil, fields) 93 } 94 95 // ---------------------------------------------------------------------------- // 96 97 // Notice is the same as Log(LEVEL_NOTICE, args...). 98 // Read more: Logger.Log(). 99 func (l *Logger) Notice(args ...any) (this *Logger) { 100 return l.log(LEVEL_NOTICE, "", nil, args, nil) 101 } 102 103 // Noticef is the same as Logf(LEVEL_NOTICE, format, args...). 104 // Read more: Logger.Logf(). 105 func (l *Logger) Noticef(format string, args ...any) (this *Logger) { 106 return l.log(LEVEL_NOTICE, fmt.Sprintf(format, args...), nil, nil, nil) 107 } 108 109 func (l *Logger) Noticew(msg string, fields ...ekaletter.LetterField) (this *Logger) { 110 return l.log(LEVEL_NOTICE, msg, nil, nil, fields) 111 } 112 func (l *Logger) Noticeww(msg string, fields []ekaletter.LetterField) (this *Logger) { 113 return l.log(LEVEL_NOTICE, msg, nil, nil, fields) 114 } 115 116 // ---------------------------------------------------------------------------- // 117 118 // Warn is the same as Log(LEVEL_WARNING, args...). 119 // Read more: Logger.Log(). 120 func (l *Logger) Warn(args ...any) (this *Logger) { 121 return l.log(LEVEL_WARNING, "", nil, args, nil) 122 } 123 124 // Warnf is the same as Logf(LEVEL_WARNING, format, args...). 125 // Read more: Logger.Logf(). 126 func (l *Logger) Warnf(format string, args ...any) (this *Logger) { 127 return l.log(LEVEL_WARNING, fmt.Sprintf(format, args...), nil, nil, nil) 128 } 129 130 func (l *Logger) Warnw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 131 return l.log(LEVEL_WARNING, msg, nil, nil, fields) 132 } 133 func (l *Logger) Warnww(msg string, fields []ekaletter.LetterField) (this *Logger) { 134 return l.log(LEVEL_WARNING, msg, nil, nil, fields) 135 } 136 137 func (l *Logger) Warne(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 138 return l.log(LEVEL_WARNING, msg, err, kvFields, nil) 139 } 140 func (l *Logger) Warnew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 141 return l.log(LEVEL_WARNING, msg, err, nil, fields) 142 } 143 func (l *Logger) Warneww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 144 return l.log(LEVEL_WARNING, msg, err, nil, fields) 145 } 146 147 // ---------------------------------------------------------------------------- // 148 149 // Error is the same as Log(LEVEL_ERROR, args...). 150 // Read more: Logger.Log(). 151 func (l *Logger) Error(args ...any) (this *Logger) { 152 return l.log(LEVEL_ERROR, "", nil, args, nil) 153 } 154 155 // Errorf is the same as Logf(LEVEL_ERROR, format, args...). 156 // Read more: Logger.Logf(). 157 func (l *Logger) Errorf(format string, args ...any) (this *Logger) { 158 return l.log(LEVEL_ERROR, fmt.Sprintf(format, args...), nil, nil, nil) 159 } 160 161 func (l *Logger) Errorw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 162 return l.log(LEVEL_ERROR, msg, nil, nil, fields) 163 } 164 func (l *Logger) Errorww(msg string, fields []ekaletter.LetterField) (this *Logger) { 165 return l.log(LEVEL_ERROR, msg, nil, nil, fields) 166 } 167 168 func (l *Logger) Errore(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 169 return l.log(LEVEL_ERROR, msg, err, kvFields, nil) 170 } 171 func (l *Logger) Errorew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 172 return l.log(LEVEL_ERROR, msg, err, nil, fields) 173 } 174 func (l *Logger) Erroreww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 175 return l.log(LEVEL_ERROR, msg, err, nil, fields) 176 } 177 178 // ---------------------------------------------------------------------------- // 179 180 // Crit is the same as Log(LEVEL_CRITICAL, args...). 181 // Read more: Logger.Log(). 182 func (l *Logger) Crit(args ...any) (this *Logger) { 183 return l.log(LEVEL_CRITICAL, "", nil, args, nil) 184 } 185 186 // Critf is the same as Logf(LEVEL_CRITICAL, format, args...). 187 // Read more: Logger.Logf(). 188 func (l *Logger) Critf(format string, args ...any) (this *Logger) { 189 return l.log(LEVEL_CRITICAL, fmt.Sprintf(format, args...), nil, nil, nil) 190 } 191 192 func (l *Logger) Critw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 193 return l.log(LEVEL_CRITICAL, msg, nil, nil, fields) 194 } 195 func (l *Logger) Critww(msg string, fields []ekaletter.LetterField) (this *Logger) { 196 return l.log(LEVEL_CRITICAL, msg, nil, nil, fields) 197 } 198 199 func (l *Logger) Crite(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 200 return l.log(LEVEL_CRITICAL, msg, err, kvFields, nil) 201 } 202 func (l *Logger) Critew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 203 return l.log(LEVEL_CRITICAL, msg, err, nil, fields) 204 } 205 func (l *Logger) Criteww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 206 return l.log(LEVEL_CRITICAL, msg, err, nil, fields) 207 } 208 209 // ---------------------------------------------------------------------------- // 210 211 // Alert is the same as Log(LEVEL_ALERT, args...). 212 // Read more: Logger.Log(). 213 func (l *Logger) Alert(args ...any) (this *Logger) { 214 return l.log(LEVEL_ALERT, "", nil, args, nil) 215 } 216 217 // Alertf is the same as Logf(LEVEL_ALERT, format, args...). 218 // Read more: Logger.Logf(). 219 func (l *Logger) Alertf(format string, args ...any) (this *Logger) { 220 return l.log(LEVEL_ALERT, fmt.Sprintf(format, args...), nil, nil, nil) 221 } 222 223 func (l *Logger) Alertw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 224 return l.log(LEVEL_ALERT, msg, nil, nil, fields) 225 } 226 func (l *Logger) Alertww(msg string, fields []ekaletter.LetterField) (this *Logger) { 227 return l.log(LEVEL_ALERT, msg, nil, nil, fields) 228 } 229 230 func (l *Logger) Alerte(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 231 return l.log(LEVEL_ALERT, msg, err, kvFields, nil) 232 } 233 func (l *Logger) Alertew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 234 return l.log(LEVEL_ALERT, msg, err, nil, fields) 235 } 236 func (l *Logger) Alerteww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 237 return l.log(LEVEL_ALERT, msg, err, nil, fields) 238 } 239 240 // ---------------------------------------------------------------------------- // 241 242 // Emerg is the same as Log(LEVEL_EMERGENCY, args...), 243 // but also then calls ekadeath.Die(1). 244 // Read more: Logger.Log(). 245 func (l *Logger) Emerg(args ...any) (this *Logger) { 246 return l.log(LEVEL_EMERGENCY, "", nil, args, nil) 247 } 248 249 // Emergf is the same as Logf(LEVEL_EMERGENCY, format, args...), 250 // but also then calls death.Die(1). 251 // Read more: Logger.Logf(). 252 func (l *Logger) Emergf(format string, args ...any) (this *Logger) { 253 return l.log(LEVEL_EMERGENCY, fmt.Sprintf(format, args...), nil, nil, nil) 254 } 255 256 func (l *Logger) Emergw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 257 return l.log(LEVEL_EMERGENCY, msg, nil, nil, fields) 258 } 259 func (l *Logger) Emergww(msg string, fields []ekaletter.LetterField) (this *Logger) { 260 return l.log(LEVEL_EMERGENCY, msg, nil, nil, fields) 261 } 262 263 func (l *Logger) Emerge(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 264 return l.log(LEVEL_EMERGENCY, msg, err, kvFields, nil) 265 } 266 func (l *Logger) Emergew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 267 return l.log(LEVEL_EMERGENCY, msg, err, nil, fields) 268 } 269 func (l *Logger) Emergeww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 270 return l.log(LEVEL_EMERGENCY, msg, err, nil, fields) 271 }