Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion logging/api/logging_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#define LOGGING_MACROS_H
#include "logging.h"
#include <stdbool.h>
#include "tag.h"

/** Default log level. */
#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_LEVEL_INFO
#define LOG_LEVEL LOG_LEVEL_DEBUG
#endif

// To prevent warnings "conditional expression is constant", we define static booleans
Expand Down Expand Up @@ -76,6 +77,20 @@ static const bool _lf_log_level_is_debug = LOG_LEVEL >= LOG_LEVEL_DEBUG;
} \
} while (0)

/**
* @brief A macro used to print timestamped(physical time) debug information.
* @ingroup API
*
* @note This macro is functionally same as @ref LF_PRINT_DEBUG but with added timestamp for physical time.
* This is to check physical time of debug logs. It uses @ref lf_time_physical to get the physical time.
*/
#define LF_TIMESTAMP_PRINT_DEBUG(format, ...) \
do { \
if (_lf_log_level_is_debug) { \
lf_print_debug("[%ld] " format, lf_time_physical_elapsed(), ##__VA_ARGS__); \
} \
} while (0)

#if defined(NDEBUG)
#define LF_ASSERT(condition, format, ...) (void)(condition)
#define LF_ASSERTN(condition, format, ...) (void)(condition)
Expand Down
20 changes: 20 additions & 0 deletions test/general/logging_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "logging_macros.h"
#include <unistd.h>

#define TOTAL_LOOP_CASES 10

/**
* @brief test for testing LF_TIMESTAMP_PRINT_DEBUG macro
* must be in LOG_LEVEL LOG_LEVEL_DEBUG
*/
int main()
{
LF_PRINT_DEBUG("Start time: %ld", lf_time_start());
for(int i; i<TOTAL_LOOP_CASES; i++)
{
LF_TIMESTAMP_PRINT_DEBUG("[Test case: %d]testing timed debug prints", i);
sleep(1);
}

return 0;
}
Loading