Merge pull request #212 from nfi/contrib/logging-custom-prefix
Extend the logging module to support custom module prefix
This commit is contained in:
commit
dbcb985457
|
@ -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 ******************/
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -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__); \
|
||||
|
|
Loading…
Reference in New Issue