Add config option to allow platform to specify the function/macro for logging (#1652)

This commit adds `OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION` as a new
configuration option (set by default as `otPlatLog()`). This allows the
user to specify the function/macro used for logging inside OpenThread.
This commit is contained in:
Abtin Keshavarzian
2017-04-26 10:46:18 -07:00
committed by Jonathan Hui
parent 76b3ef3d64
commit cda414805f
3 changed files with 27 additions and 10 deletions
+1 -1
View File
@@ -45,7 +45,7 @@
#ifndef WINDOWS_LOGGING
#define otLogDump(aFormat, ...) \
_otPlatLog(aInstance, aLogLevel, aLogRegion, aFormat OPENTHREAD_CONFIG_LOG_SUFFIX, ## __VA_ARGS__)
_otDynamicLog(aInstance, aLogLevel, aLogRegion, aFormat OPENTHREAD_CONFIG_LOG_SUFFIX, ## __VA_ARGS__)
#endif
#ifdef __cplusplus
+15 -8
View File
@@ -1244,7 +1244,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
* Local/private macro to format the log message
*/
#define _otLogFormatter(aInstance, aLogLevel, aRegion, aFormat, ...) \
_otPlatLog( \
_otDynamicLog( \
aInstance, \
aLogLevel, \
aRegion, \
@@ -1260,7 +1260,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
* Local/private macro to format the log message
*/
#define _otLogFormatter(aInstanc, aLogLevel, aRegion, aFormat, ...) \
_otPlatLog( \
_otDynamicLog( \
aInstance, \
aLogLevel, \
aRegion, \
@@ -1279,7 +1279,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
* Local/private macro to format the log message
*/
#define _otLogFormatter(aInstance, aLogLevel, aRegion, aFormat, ...) \
_otPlatLog( \
_otDynamicLog( \
aInstance, \
aLogLevel, \
aRegion, \
@@ -1294,7 +1294,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
* Local/private macro to format the log message
*/
#define _otLogFormatter(aInstace, aLogLevel, aRegion, aFormat, ...) \
_otPlatLog( \
_otDynamicLog( \
aInstance, \
aLogLevel, \
aRegion, \
@@ -1306,24 +1306,31 @@ const char *otLogRegionToString(otLogRegion aRegion);
#endif // OPENTHREAD_CONFIG_LOG_PREPEND_REGION
#if OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL == 1
/**
* Local/private macro to dynamically filter log level.
*/
#define _otPlatLog(aInstance, aLogLevel, aRegion, aFormat, ...) \
#define _otDynamicLog(aInstance, aLogLevel, aRegion, aFormat, ...) \
do { \
if (otGetDynamicLogLevel(aInstance) >= aLogLevel) \
otPlatLog(aLogLevel, aRegion, aFormat, ## __VA_ARGS__); \
_otPlatLog(aLogLevel, aRegion, aFormat, ## __VA_ARGS__); \
} while (false)
#else // OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
#define _otPlatLog(aInstance, aLogLevel, aRegion, aFormat, ...) otPlatLog(aLogLevel, aRegion, aFormat, ## __VA_ARGS__)
#define _otDynamicLog(aInstance, aLogLevel, aRegion, aFormat, ...) \
_otPlatLog(aLogLevel, aRegion, aFormat, ## __VA_ARGS__)
#endif // OPENTHREAD_CONFIG_ENABLE_DYNAMIC_LOG_LEVEL
/**
* `OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION` is a configuration parameter (see `openthread-core-default-config.h`) which
* specifies the function/macro to be used for logging in OpenThread. By default it is set to `otPlatLog()`.
*/
#define _otPlatLog(aLogLevel, aRegion, aFormat, ...) \
OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION(aLogLevel, aRegion, aFormat, ## __VA_ARGS__)
#ifdef __cplusplus
};
#endif
+11 -1
View File
@@ -566,9 +566,19 @@
*
*/
#ifndef OPENTHREAD_CONFIG_LOG_SUFFIX
#define OPENTHREAD_CONFIG_LOG_SUFFIX ""
#define OPENTHREAD_CONFIG_LOG_SUFFIX ""
#endif // OPENTHREAD_CONFIG_LOG_SUFFIX
/**
* @def OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION
*
* Defines the name of function/marco used for logging inside Openthread, by default is set to `otPlatLog()`.
*
*/
#ifndef OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION
#define OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION otPlatLog
#endif
/**
* @def OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES
*