CESNET / UltraGrid

UltraGrid low-latency audio and video network transmission system
http://www.ultragrid.cz
Other
507 stars 53 forks source link

Update MSG macro and create MSG_ONCE macro #411

Open ATrivialAtomic opened 1 month ago

ATrivialAtomic commented 1 month ago

Hi there!

Would it be possible to update the #define MSG macro in debug.h to add a space after "%s"? Without the space, you have to add a space at the head of your fmt message to provide separation between MOD_NAME and that message.

Also, more of a personal/syntax question -- should a "\n" be included at the tail of the fmt line ("%s " fmt "\n") to automatically append a newline without having to manually do it with each message? Would that be better served with a new macro that specifies a newline will be added?

Current MSG implementation:

#define MSG(l, fmt, ...) \
        log_msg(LOG_LEVEL_##l, "%s" fmt, MOD_NAME, ##__VA_ARGS__)

Proposed change:

#define MSG(l, fmt, ...) \
        log_msg(LOG_LEVEL_##l, "%s " fmt "\n", MOD_NAME, ##__VA_ARGS__)

Also, in keeping with moving towards preference for MSG, would it be possible to create a similar macro for log_msg_once?

Proposed MSG_ONCE implementation:

#define MSG_ONCE(l, id, fmt, ...) \
        log_msg_once(LOG_LEVEL_##l, id, "%s " fmt "\n", MOD_NAME, ##__VA_ARGS__)
MartinPulec commented 3 weeks ago

Also, in keeping with moving towards preference for MSG, would it be possible to create a similar macro for log_msg_once?

Added. The current implementation isn't using id parameter explicitly but the key is constructed from MOD_NAME address and __COUNTER__. Also it doesn't include trailing '\n' - I am not convinced about this - the MSG()/log_msg() functions are intended to be printf-alike, notably utilizing printf-like format. And since printf doesn't append a newline, so doesn't these.