github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekalog/exported_finishers.go (about) 1 // Copyright © 2020. 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 Log(level Level, args ...any) (this *Logger) { 33 return baseLogger.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 Logf(level Level, format string, args ...any) (this *Logger) { 43 return baseLogger.log(level, fmt.Sprintf(format, args...), nil, nil, nil) 44 } 45 46 func Logw(level Level, msg string, fields ...ekaletter.LetterField) (this *Logger) { 47 return baseLogger.log(level, msg, nil, nil, fields) 48 } 49 func Logww(level Level, msg string, fields []ekaletter.LetterField) (this *Logger) { 50 return baseLogger.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 Debug(args ...any) (this *Logger) { 58 return baseLogger.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 Debugf(format string, args ...any) (this *Logger) { 64 return baseLogger.log(LEVEL_DEBUG, fmt.Sprintf(format, args...), nil, nil, nil) 65 } 66 67 func Debugw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 68 return baseLogger.log(LEVEL_DEBUG, msg, nil, nil, fields) 69 } 70 func Debugww(msg string, fields []ekaletter.LetterField) (this *Logger) { 71 return baseLogger.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 Info(args ...any) (this *Logger) { 79 return baseLogger.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 Infof(format string, args ...any) (this *Logger) { 85 return baseLogger.log(LEVEL_INFO, fmt.Sprintf(format, args...), nil, nil, nil) 86 } 87 88 func Infow(msg string, fields ...ekaletter.LetterField) (this *Logger) { 89 return baseLogger.log(LEVEL_INFO, msg, nil, nil, fields) 90 } 91 func Infoww(msg string, fields []ekaletter.LetterField) (this *Logger) { 92 return baseLogger.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 Notice(args ...any) (this *Logger) { 100 return baseLogger.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 Noticef(format string, args ...any) (this *Logger) { 106 return baseLogger.log(LEVEL_NOTICE, fmt.Sprintf(format, args...), nil, nil, nil) 107 } 108 109 func Noticew(msg string, fields ...ekaletter.LetterField) (this *Logger) { 110 return baseLogger.log(LEVEL_NOTICE, msg, nil, nil, fields) 111 } 112 func Noticeww(msg string, fields []ekaletter.LetterField) (this *Logger) { 113 return baseLogger.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 Warn(args ...any) (this *Logger) { 121 return baseLogger.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 Warnf(format string, args ...any) (this *Logger) { 127 return baseLogger.log(LEVEL_WARNING, fmt.Sprintf(format, args...), nil, nil, nil) 128 } 129 130 func Warnw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 131 return baseLogger.log(LEVEL_WARNING, msg, nil, nil, fields) 132 } 133 func Warnww(msg string, fields []ekaletter.LetterField) (this *Logger) { 134 return baseLogger.log(LEVEL_WARNING, msg, nil, nil, fields) 135 } 136 137 func Warne(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 138 return baseLogger.log(LEVEL_WARNING, msg, err, kvFields, nil) 139 } 140 func Warnew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 141 return baseLogger.log(LEVEL_WARNING, msg, err, nil, fields) 142 } 143 func Warneww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 144 return baseLogger.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 Error(args ...any) (this *Logger) { 152 return baseLogger.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 Errorf(format string, args ...any) (this *Logger) { 158 return baseLogger.log(LEVEL_ERROR, fmt.Sprintf(format, args...), nil, nil, nil) 159 } 160 161 func Errorw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 162 return baseLogger.log(LEVEL_ERROR, msg, nil, nil, fields) 163 } 164 func Errorww(msg string, fields []ekaletter.LetterField) (this *Logger) { 165 return baseLogger.log(LEVEL_ERROR, msg, nil, nil, fields) 166 } 167 168 func Errore(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 169 return baseLogger.log(LEVEL_ERROR, msg, err, kvFields, nil) 170 } 171 func Errorew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 172 return baseLogger.log(LEVEL_ERROR, msg, err, nil, fields) 173 } 174 func Erroreww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 175 return baseLogger.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 Crit(args ...any) (this *Logger) { 183 return baseLogger.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 Critf(format string, args ...any) (this *Logger) { 189 return baseLogger.log(LEVEL_CRITICAL, fmt.Sprintf(format, args...), nil, nil, nil) 190 } 191 192 func Critw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 193 return baseLogger.log(LEVEL_CRITICAL, msg, nil, nil, fields) 194 } 195 func Critww(msg string, fields []ekaletter.LetterField) (this *Logger) { 196 return baseLogger.log(LEVEL_CRITICAL, msg, nil, nil, fields) 197 } 198 199 func Crite(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 200 return baseLogger.log(LEVEL_CRITICAL, msg, err, kvFields, nil) 201 } 202 func Critew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 203 return baseLogger.log(LEVEL_CRITICAL, msg, err, nil, fields) 204 } 205 func Criteww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 206 return baseLogger.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 Alert(args ...any) (this *Logger) { 214 return baseLogger.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 Alertf(format string, args ...any) (this *Logger) { 220 return baseLogger.log(LEVEL_ALERT, fmt.Sprintf(format, args...), nil, nil, nil) 221 } 222 223 func Alertw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 224 return baseLogger.log(LEVEL_ALERT, msg, nil, nil, fields) 225 } 226 func Alertww(msg string, fields []ekaletter.LetterField) (this *Logger) { 227 return baseLogger.log(LEVEL_ALERT, msg, nil, nil, fields) 228 } 229 230 func Alerte(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 231 return baseLogger.log(LEVEL_ALERT, msg, err, kvFields, nil) 232 } 233 func Alertew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 234 return baseLogger.log(LEVEL_ALERT, msg, err, nil, fields) 235 } 236 func Alerteww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 237 return baseLogger.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 Emerg(args ...any) (this *Logger) { 246 return baseLogger.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 Emergf(format string, args ...any) (this *Logger) { 253 return baseLogger.log(LEVEL_EMERGENCY, fmt.Sprintf(format, args...), nil, nil, nil) 254 } 255 256 func Emergw(msg string, fields ...ekaletter.LetterField) (this *Logger) { 257 return baseLogger.log(LEVEL_EMERGENCY, msg, nil, nil, fields) 258 } 259 func Emergww(msg string, fields []ekaletter.LetterField) (this *Logger) { 260 return baseLogger.log(LEVEL_EMERGENCY, msg, nil, nil, fields) 261 } 262 263 func Emerge(msg string, err *ekaerr.Error, kvFields ...any) (this *Logger) { 264 return baseLogger.log(LEVEL_EMERGENCY, msg, err, kvFields, nil) 265 } 266 func Emergew(msg string, err *ekaerr.Error, fields ...ekaletter.LetterField) (this *Logger) { 267 return baseLogger.log(LEVEL_EMERGENCY, msg, err, nil, fields) 268 } 269 func Emergeww(msg string, err *ekaerr.Error, fields []ekaletter.LetterField) (this *Logger) { 270 return baseLogger.log(LEVEL_EMERGENCY, msg, err, nil, fields) 271 }