-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add newline to logs #307
Add newline to logs #307
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,55 +17,57 @@ | |
|
||
#include <stdio.h> | ||
|
||
// Logging values | ||
#define _Z_LOG_LVL_ERROR 1 | ||
#define _Z_LOG_LVL_INFO 2 | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
#define _Z_LOG_LVL_DEBUG 3 | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
|
||
// Timestamp function | ||
static inline void __z_print_timestamp(void) { | ||
char ret[64]; | ||
printf("[%s ", z_time_now_as_str(ret, sizeof(ret))); | ||
} | ||
|
||
// Logging macros | ||
#define _Z_LOG_PREFIX(prefix) \ | ||
__z_print_timestamp(); \ | ||
printf(#prefix " ::%s] ", __func__); | ||
|
||
#if (ZENOH_DEBUG == 3) | ||
#define _Z_DEBUG(x, ...) \ | ||
_Z_LOG_PREFIX(DEBUG); \ | ||
printf(x, ##__VA_ARGS__); | ||
#define _Z_DEBUG_CONTINUE(x, ...) printf(x, ##__VA_ARGS__); | ||
#define _Z_INFO(x, ...) \ | ||
_Z_LOG_PREFIX(INFO); \ | ||
printf(x, ##__VA_ARGS__); | ||
#define _Z_INFO_CONTINUE(x, ...) printf(x, ##__VA_ARGS__); | ||
#define _Z_ERROR(x, ...) \ | ||
_Z_LOG_PREFIX(ERROR); \ | ||
printf(x, ##__VA_ARGS__); | ||
#define _Z_ERROR_CONTINUE(x, ...) printf(x, ##__VA_ARGS__); | ||
// Ignore print only if log deactivated and build is release | ||
#if ZENOH_DEBUG == 0 && !defined(Z_BUILD_DEBUG) | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2009 with no text in the supplied rule-texts-file Warning
misra violation 2009 with no text in the supplied rule-texts-file
|
||
|
||
#define _Z_DEBUG(...) (void)(0) | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
#define _Z_INFO(...) (void)(0) | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
#define _Z_ERROR(...) (void)(0) | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
|
||
#else // ZENOH_DEBUG != 0 || defined(Z_BUILD_DEBUG) | ||
|
||
#elif (ZENOH_DEBUG == 2) | ||
#define _Z_DEBUG(x, ...) (void)(0) | ||
#define _Z_DEBUG_CONTINUE(x, ...) (void)(0); | ||
#define _Z_INFO(x, ...) \ | ||
_Z_LOG_PREFIX(INFO); \ | ||
printf(x, ##__VA_ARGS__); | ||
#define _Z_INFO_CONTINUE(x, ...) printf(x, ##__VA_ARGS__); | ||
#define _Z_ERROR(x, ...) \ | ||
_Z_LOG_PREFIX(ERROR); \ | ||
printf(x, ##__VA_ARGS__); | ||
#define _Z_ERROR_CONTINUE(x, ...) printf(x, ##__VA_ARGS__); | ||
#define _Z_DEBUG(...) \ | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
do { \ | ||
if (ZENOH_DEBUG >= _Z_LOG_LVL_DEBUG) { \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why to do this check at runtime, instead of at compile time as before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it transitions from a pre-compiler thing to a compile time check, as the compiler realises this values won't change for the whole execution of the program, a bit like a C++ The problem with pre compiler stuff is that it doesn't check if the code is valid while the compiler do. So let's say in my log statement I print a variable, that is then changed (type or name), it will go unnoticed until the compiler sees it, so if I only compile without Debug it won't see it. Now it will always see this kind of issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if it is already in place, but having compilation tests for both debug and release seems a simpler option. |
||
_Z_LOG_PREFIX(DEBUG); \ | ||
printf(__VA_ARGS__); \ | ||
printf("\n"); \ | ||
} \ | ||
} while (false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns the block into a single statement and forces a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If MISRA-C is still followed for the codebase, this shall not be required. |
||
|
||
#elif (ZENOH_DEBUG == 1) | ||
#define _Z_DEBUG(x, ...) (void)(0) | ||
#define _Z_DEBUG_CONTINUE(x, ...) (void)(0); | ||
#define _Z_INFO(x, ...) (void)(0); | ||
#define _Z_INFO_CONTINUE(x, ...) (void)(0); | ||
#define _Z_ERROR(x, ...) \ | ||
_Z_LOG_PREFIX(ERROR); \ | ||
printf(x, ##__VA_ARGS__); | ||
#define _Z_ERROR_CONTINUE(x, ...) printf(x, ##__VA_ARGS__); | ||
#define _Z_INFO(...) \ | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
do { \ | ||
if (ZENOH_DEBUG >= _Z_LOG_LVL_INFO) { \ | ||
jean-roland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_Z_LOG_PREFIX(INFO); \ | ||
printf(__VA_ARGS__); \ | ||
printf("\n"); \ | ||
} \ | ||
} while (false) | ||
jean-roland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#elif (ZENOH_DEBUG == 0) | ||
#define _Z_DEBUG(x, ...) (void)(0) | ||
#define _Z_INFO(x, ...) (void)(0) | ||
#define _Z_ERROR(x, ...) (void)(0) | ||
#endif | ||
#define _Z_ERROR(...) \ | ||
Check warning Code scanning / Cppcheck (reported by Codacy) misra violation 2101 with no text in the supplied rule-texts-file Warning
misra violation 2101 with no text in the supplied rule-texts-file
|
||
do { \ | ||
if (ZENOH_DEBUG >= _Z_LOG_LVL_ERROR) { \ | ||
jean-roland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_Z_LOG_PREFIX(ERROR); \ | ||
printf(__VA_ARGS__); \ | ||
printf("\n"); \ | ||
} \ | ||
} while (false) | ||
jean-roland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif // ZENOH_DEBUG == 0 && !defined(Z_BUILD_DEBUG) | ||
|
||
#endif /* ZENOH_PICO_UTILS_LOGGING_H */ | ||
#endif // ZENOH_PICO_UTILS_LOGGING_H |
Check warning
Code scanning / Cppcheck (reported by Codacy)
misra violation 2101 with no text in the supplied rule-texts-file Warning