Skip to content

Commit

Permalink
Add 'EXEC' option to LOG_MSG macros
Browse files Browse the repository at this point in the history
This option allows for provided code segments to be executed once it's
been decided to emit the log msg.  This aims to replace users of
DEBUG_BLOCK() which fully prevents msg evaluation and the registering of
the log line in the ctl-interface.
  • Loading branch information
00pauln00 committed Apr 22, 2024
1 parent eabab4f commit b4b78af
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ struct log_entry_info
do { thread_abort(); } while (0)
#endif

#define SIMPLE_LOG_MSG(level, message, ...) \
#define SIMPLE_LOG_MSG_EXEC(level, exec, message, ...) \
do { \
if ((level) <= log_level_get()) \
{ \
exec; \
struct timespec ts; \
niova_unstable_clock(&ts); \
fprintf(stderr, "<%ld.%09lu:%s:%s:%s@%d> " message "\n", \
Expand All @@ -164,6 +165,9 @@ do { \
} \
} while (0)

#define SIMPLE_LOG_MSG(level, message, ...) \
SIMPLE_LOG_MSG_EXEC(level, {}, message, ##__VA_ARGS__)

#define FUNC_ENTRY(level) \
LOG_MSG(level, "enter")

Expand All @@ -181,7 +185,7 @@ do { \
* registry entry's level, and next from the file's level. If neither are
* set, then use the level provided by the caller.
*/
#define _LOG_MSG(user_lvl, tag, message, ...) \
#define _LOG_MSG(user_lvl, tag, exec, message, ...) \
do { \
enum log_level lvl = user_lvl; \
\
Expand All @@ -197,14 +201,20 @@ do { \
else if (logEntryFileInfo.lei_level != LL_ANY) \
lvl = logEntryFileInfo.lei_level; \
} \
SIMPLE_LOG_MSG(lvl, message, ##__VA_ARGS__); \
SIMPLE_LOG_MSG_EXEC(lvl, exec, message, ##__VA_ARGS__); \
} while (0)

#define LOG_MSG_EXEC(user_lvl, exec, message, ...) \
_LOG_MSG(user_lvl, NULL, exec, message, ##__VA_ARGS__)

#define LOG_MSG_TAG_EXEC(user_lvl, tag, exec, message, ...) \
_LOG_MSG(user_lvl, tag, exec, message, ##__VA_ARGS__)

#define LOG_MSG(user_lvl, message, ...) \
_LOG_MSG(user_lvl, NULL, message, ##__VA_ARGS__)
_LOG_MSG(user_lvl, NULL, {}, message, ##__VA_ARGS__)

#define LOG_MSG_TAG(user_lvl, tag, message, ...) \
_LOG_MSG(user_lvl, tag, message, ##__VA_ARGS__)
_LOG_MSG(user_lvl, tag, {}, message, ##__VA_ARGS__)

#define FATAL_MSG(message, ...) \
SIMPLE_LOG_MSG(LL_FATAL, message, ##__VA_ARGS__)
Expand Down

0 comments on commit b4b78af

Please sign in to comment.