refactor: Simplify the log hinter

Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
Kai Krakow
2018-10-09 00:05:47 +02:00
parent f4cd01f989
commit 5396370e5d
4 changed files with 77 additions and 60 deletions

View File

@@ -62,6 +62,13 @@ POSSIBILITY OF SUCH DAMAGE.
} \
} while (0)
#define LOG_ONCE(type, ...) \
do { \
static int __once = 0; \
if (!__once++) \
LOG_##type(__VA_ARGS__); \
} while (0)
/* Fatal warnings trigger an exit */
#define FATAL_ERRORNO(msg) \
do { \
@@ -74,6 +81,26 @@ POSSIBILITY OF SUCH DAMAGE.
exit(EXIT_FAILURE); \
} while (0)
/* Hinting helpers */
#define HINT_ONCE(name, hint) \
do { \
static int __once = 0; \
name = (!__once++ ? hint : ""); \
} while (0)
#define HINT_ONCE_ON(cond, ...) \
do { \
if (cond) \
HINT_ONCE(__VA_ARGS__); \
} while (0);
#define LOG_HINTED(type, msg, hint, ...) \
do { \
const char *__arg; \
HINT_ONCE(__arg, hint); \
LOG_##type(msg "%s", __VA_ARGS__, __arg); \
} while (0)
/**
* Control if and how how we use syslog
*/