| ... | ... | @@ -200,3 +200,87 @@ pub fn debug( |
| 200 | 200 | ) void { |
| 201 | 201 | log(.debug, scope, format, args); |
| 202 | 202 | } |
| 203 | |
| 204 | pub fn scoped(comptime scope: @Type(.EnumLiteral)) type { |
| 205 | return struct { |
| 206 | /// Log an emergency message to stderr. This log level is intended to be used |
| 207 | /// for conditions that cannot be handled and is usually followed by a panic. |
| 208 | pub fn emerg( |
| 209 | comptime format: []const u8, |
| 210 | args: anytype, |
| 211 | ) void { |
| 212 | @setCold(true); |
| 213 | log(.emerg, scope, format, args); |
| 214 | } |
| 215 | |
| 216 | /// Log an alert message to stderr. This log level is intended to be used for |
| 217 | /// conditions that should be corrected immediately (e.g. database corruption). |
| 218 | pub fn alert( |
| 219 | comptime format: []const u8, |
| 220 | args: anytype, |
| 221 | ) void { |
| 222 | @setCold(true); |
| 223 | log(.alert, scope, format, args); |
| 224 | } |
| 225 | |
| 226 | /// Log a critical message to stderr. This log level is intended to be used |
| 227 | /// when a bug has been detected or something has gone wrong and it will have |
| 228 | /// an effect on the operation of the program. |
| 229 | pub fn crit( |
| 230 | comptime format: []const u8, |
| 231 | args: anytype, |
| 232 | ) void { |
| 233 | @setCold(true); |
| 234 | log(.crit, scope, format, args); |
| 235 | } |
| 236 | |
| 237 | /// Log an error message to stderr. This log level is intended to be used when |
| 238 | /// a bug has been detected or something has gone wrong but it is recoverable. |
| 239 | pub fn err( |
| 240 | comptime format: []const u8, |
| 241 | args: anytype, |
| 242 | ) void { |
| 243 | @setCold(true); |
| 244 | log(.err, scope, format, args); |
| 245 | } |
| 246 | |
| 247 | /// Log a warning message to stderr. This log level is intended to be used if |
| 248 | /// it is uncertain whether something has gone wrong or not, but the |
| 249 | /// circumstances would be worth investigating. |
| 250 | pub fn warn( |
| 251 | comptime format: []const u8, |
| 252 | args: anytype, |
| 253 | ) void { |
| 254 | log(.warn, scope, format, args); |
| 255 | } |
| 256 | |
| 257 | /// Log a notice message to stderr. This log level is intended to be used for |
| 258 | /// non-error but significant conditions. |
| 259 | pub fn notice( |
| 260 | comptime format: []const u8, |
| 261 | args: anytype, |
| 262 | ) void { |
| 263 | log(.notice, scope, format, args); |
| 264 | } |
| 265 | |
| 266 | /// Log an info message to stderr. This log level is intended to be used for |
| 267 | /// general messages about the state of the program. |
| 268 | pub fn info( |
| 269 | comptime format: []const u8, |
| 270 | args: anytype, |
| 271 | ) void { |
| 272 | log(.info, scope, format, args); |
| 273 | } |
| 274 | |
| 275 | /// Log a debug message to stderr. This log level is intended to be used for |
| 276 | /// messages which are only useful for debugging. |
| 277 | pub fn debug( |
| 278 | comptime format: []const u8, |
| 279 | args: anytype, |
| 280 | ) void { |
| 281 | log(.debug, scope, format, args); |
| 282 | } |
| 283 | }; |
| 284 | } |
| 285 | |
| 286 | pub const default = scoped(.default); |