Merge pull request #212 from nfi/contrib/logging-custom-prefix

Extend the logging module to support custom module prefix
This commit is contained in:
Joakim Eriksson 2017-12-01 08:26:06 +01:00 committed by GitHub
commit dbcb985457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -81,6 +81,22 @@
#define LOG_OUTPUT(...) printf(__VA_ARGS__)
#endif /* LOG_CONF_OUTPUT */
/*
* Custom output function to prefix logs with level and module.
*
* This will only be called when LOG_CONF_WITH_MODULE_PREFIX is enabled and
* all implementations should be based on LOG_OUTPUT.
*
* \param level The log level
* \param levelstr The log level as string
* \param module The module string descriptor
*/
#ifdef LOG_CONF_OUTPUT_PREFIX
#define LOG_OUTPUT_PREFIX(level, levelstr, module) LOG_CONF_OUTPUT_PREFIX(level, levelstr, module)
#else /* LOG_CONF_OUTPUT_PREFIX */
#define LOG_OUTPUT_PREFIX(level, levelstr, module) LOG_OUTPUT("[%-4s: %-10s] ", levelstr, module)
#endif /* LOG_CONF_OUTPUT_PREFIX */
/******************************************************************************/
/********************* A list of currently supported modules ******************/
/******************************************************************************/

View File

@ -101,7 +101,7 @@ extern struct log_module all_modules[];
if(level <= (LOG_LEVEL)) { \
if(newline) { \
if(LOG_WITH_MODULE_PREFIX) { \
LOG_OUTPUT("[%-4s: %-10s] ", levelstr, LOG_MODULE); \
LOG_OUTPUT_PREFIX(level, levelstr, LOG_MODULE); \
} \
if(LOG_WITH_LOC) { \
LOG_OUTPUT("[%s: %d] ", __FILE__, __LINE__); \