diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-16 11:22:46 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-16 11:22:46 +0200 |
commit | cab7429706aa6fce9d217ba6c5e3b6e5557914d5 (patch) | |
tree | 5f718ffb09cabf720ea19fedccac9e3ba087f8e9 /main.h | |
parent | 18a5dcf9ef6f9bde77326bb363ec61bbf6b5e587 (diff) |
Cleanup debugging macros a bit
Diffstat (limited to 'main.h')
-rw-r--r-- | main.h | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -10,12 +10,30 @@ struct cfg; extern bool exiting; -extern int debuglvl; +extern unsigned debug_mask; -void debug(unsigned lvl, const char *fmt, ...); +enum debug_category { + DBG_ERROR = (0x1 << 1), + DBG_INFO = (0x1 << 2), + DBG_VERBOSE = (0x1 << 3), + DBG_CFG = (0x1 << 4), + DBG_REF = (0x1 << 5), + DBG_MALLOC = (0x1 << 6), +}; + +static inline bool +debug_enabled(enum debug_category category) +{ + return !!(category & debug_mask); +} + +void do_debug(enum debug_category category, const char *fmt, ...); -#define info(...) fprintf(stderr, __VA_ARGS__) -#define error(...) fprintf(stderr, __VA_ARGS__) +#define __debug(c, ...) do { if (debug_enabled((c))) do_debug((c), __VA_ARGS__); } while (0) +#define debug(c, fmt, ...) __debug(c, "%s:" fmt, __func__, __VA_ARGS__) +#define verbose(...) __debug(DBG_VERBOSE, __VA_ARGS__) +#define info(...) __debug(DBG_ERROR, __VA_ARGS__) +#define error(...) __debug(DBG_ERROR, __VA_ARGS__) void die(const char *fmt, ...); |