From e0579f1ddc9bea483bb2d9cfe0d752db9e91ff7f Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Thu, 16 Feb 2017 13:39:59 +0900 Subject: [PATCH] enable LOG_LEVEL build option which can filter log in build time. Lite Device has always requirement to reduce memory size. Also LOGGING build option is not enough for the requirement. Thru, we need to provide to select log which can include in binary. ex) LOGGING=true -> about 2267kbyte (libconnectivity_abstraction, liboctbstack, libocsrm, libroutingmanager) LOGGING=true LOG_LEVEL=ERROR -> 2184kbyte => about 82kbyte saving Change-Id: I1158de8739b2cd8fa961ad6fc3ff8899c410cbce Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/17719 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai --- build_common/SConscript | 1 + resource/csdk/logger/SConscript | 14 +++++ resource/csdk/logger/include/logger.h | 111 ++++++++++++++++++++++++++-------- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/build_common/SConscript b/build_common/SConscript index 3186930..d204f8f 100644 --- a/build_common/SConscript +++ b/build_common/SConscript @@ -121,6 +121,7 @@ help_vars.Add(EnumVariable('MULTIPLE_OWNER', 'Enable multiple owner', '0', allow help_vars.Add(EnumVariable('EXC_PROV_SUPPORT', 'Except OCPMAPI library(libocpmapi.so)', '0', allowed_values=('0', '1'))) help_vars.Add(EnumVariable('TEST', 'Run unit tests', '0', allowed_values=('0', '1'))) help_vars.Add(BoolVariable('LOGGING', 'Enable stack logging', logging_default)) +help_vars.Add(EnumVariable('LOG_LEVEL', 'Enable stack logging level', 'DEBUG', allowed_values=('DEBUG', 'INFO', 'ERROR', 'WARNING', 'FATAL'))) help_vars.Add(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload)) help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP'))) help_vars.Add(EnumVariable('BUILD_SAMPLE', 'Build with sample', 'ON', allowed_values=('ON', 'OFF'))) diff --git a/resource/csdk/logger/SConscript b/resource/csdk/logger/SConscript index 5c04868..753e9a5 100644 --- a/resource/csdk/logger/SConscript +++ b/resource/csdk/logger/SConscript @@ -1,5 +1,6 @@ Import('env') import os +log_level = env.get('LOG_LEVEL') build_dir = env.get('BUILD_DIR') @@ -32,6 +33,19 @@ if env.get('TARGET_OS') in ['arduino']: else: logger_src = ['./src/logger.c', './src/trace.c'] +if log_level == 'INFO': + env.AppendUnique(CPPDEFINES = ['SET_LOG_INFO']) + print "SET_LOG_INFO" +if log_level == 'ERROR': + env.AppendUnique(CPPDEFINES = ['SET_LOG_ERROR']) + print "SET_LOG_ERROR" +if log_level == 'WARNING': + env.AppendUnique(CPPDEFINES = ['SET_LOG_WARNING']) + print "SET_LOG_WARNING" +if log_level == 'FATAL': + env.AppendUnique(CPPDEFINES = ['SET_LOG_FATAL']) + print "SET_LOG_FATAL" + loggerlib = local_env.StaticLibrary('logger', logger_src) local_env.InstallTarget(loggerlib, 'logger') diff --git a/resource/csdk/logger/include/logger.h b/resource/csdk/logger/include/logger.h index a009139..7215586 100644 --- a/resource/csdk/logger/include/logger.h +++ b/resource/csdk/logger/include/logger.h @@ -60,14 +60,14 @@ extern "C" // Log levels #ifdef __TIZEN__ typedef enum { - DEBUG = DLOG_DEBUG, + DEBUG = DLOG_INFO, // DLOG_INFO : 4 INFO = DLOG_INFO, - WARNING = DLOG_WARN, - ERROR = DLOG_ERROR, + WARNING = DLOG_WARN, // DLOG_WARN : 5 + ERROR = DLOG_ERROR, // DLOG_ERROR : 6 FATAL = DLOG_ERROR, - DEBUG_LITE = DLOG_DEBUG, + DEBUG_LITE = DLOG_INFO, INFO_LITE = DLOG_INFO, - INFO_PRIVATE = DLOG_INFO, + INFO_PRIVATE = 255, } LogLevel; #else @@ -87,6 +87,18 @@ typedef enum { INFO_PRIVATE, // The log contained private data } LogLevel; +#endif // __TIZEN__ + +#ifdef SET_LOG_INFO +#define IF_OC_PRINT_LOG_LEVEL(level) if (INFO <= (level) && INFO_PRIVATE != (level)) +#elif defined(SET_LOG_ERROR) +#define IF_OC_PRINT_LOG_LEVEL(level) if (ERROR <= (level) && INFO_PRIVATE != (level)) +#elif defined(SET_LOG_WARNING) +#define IF_OC_PRINT_LOG_LEVEL(level) if (WARNING <= (level) && INFO_PRIVATE != (level)) +#elif defined(SET_LOG_FATAL) +#define IF_OC_PRINT_LOG_LEVEL(level) if (FATAL <= (level) && INFO_PRIVATE != (level)) +#else +#define IF_OC_PRINT_LOG_LEVEL(level) if (DEBUG <= (level) && INFO_PRIVATE != (level)) #endif /** @@ -211,48 +223,97 @@ void OCLogBuffer(LogLevel level, const char* tag, const uint8_t* buffer, size_t #ifdef TB_LOG #ifdef __TIZEN__ - -#define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes) -#define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt, ##args) -#define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)\ - OCLogBuffer((level), (tag), (buffer), (bufferSize)) - -#else // These macros are defined for Linux, Android, Win32, and Arduino - +#define OIC_LOG(level,tag,mes) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + LOG_(LOG_ID_MAIN, (level), (tag), mes); \ + } while(0) + +#define OIC_LOG_V(level,tag,fmt,args...) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + LOG_(LOG_ID_MAIN, (level), (tag), fmt, ##args); \ + } while(0) + +#define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLogBuffer((level), (tag), (buffer), (bufferSize)); \ + } while(0) + +#define OIC_LOG_CA_BUFFER(level, tag, buffer, bufferSize, isHeader) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCPrintCALogBuffer((level), (tag), (buffer), (bufferSize), (isHeader)); \ + } while(0) + +#else // NO __TIZEN__ - These macros are defined for Linux, Android, Win32, and Arduino #define OIC_LOG_INIT() OCLogInit() #ifdef ARDUINO +#define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLogBuffer((level), PCF(tag), (buffer), (bufferSize)); \ + } while(0) -#define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), PCF(tag), (buffer), (bufferSize)) // Don't define variable argument log function for Arduino -#define OIC_LOG_V(level, tag, format, ...) OCLogv((level), PCF(tag), __LINE__, PCF(format),__VA_ARGS__) +#define OIC_LOG_V(level, tag, format, ...) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLogv((level), PCF(tag), __LINE__, PCF(format),__VA_ARGS__); \ + } while(0) #define OIC_LOG_CONFIG(ctx) #define OIC_LOG_SHUTDOWN() -#define OIC_LOG(level, tag, logStr) OCLog((level), PCF(tag), __LINE__, PCF(logStr)) +#define OIC_LOG(level, tag, logStr) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLog((level), PCF(tag), __LINE__, PCF(logStr)); \ + } while(0) + #define OIC_LOG_V(level, tag, ...) -#else +#else // NO ARDUINO +#define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLogBuffer((level), (tag), (buffer), (bufferSize)); \ + } while(0) + +#define OIC_LOG_CA_BUFFER(level, tag, buffer, bufferSize, isHeader) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCPrintCALogBuffer((level), (tag), (buffer), (bufferSize), (isHeader)); \ + } while(0) -#define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize)) #define OIC_LOG_CONFIG(ctx) OCLogConfig((ctx)) #define OIC_LOG_SHUTDOWN() OCLogShutdown() -#define OIC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr)) -// Define variable argument log function for Linux, Android, and Win32 -#define OIC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__) +#define OIC_LOG(level, tag, logStr) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLog((level), (tag), (logStr)); \ + } while(0) -#endif //ARDUINO -#endif //__TIZEN__ +// Define variable argument log function for Linux, Android, and Win32 +#define OIC_LOG_V(level, tag, ...) \ + do { \ + IF_OC_PRINT_LOG_LEVEL((level)) \ + OCLogv((level), (tag), __VA_ARGS__); \ + } while(0) -#else //TB_LOG +#endif // ARDUINO +#endif // __TIZEN__ +#else // TB_LOG #define OIC_LOG_CONFIG(ctx) #define OIC_LOG_SHUTDOWN() #define OIC_LOG(level, tag, logStr) #define OIC_LOG_V(level, tag, ...) #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) +#define OIC_LOG_CA_BUFFER(level, tag, buffer, bufferSize, isHeader) #define OIC_LOG_INIT() -#endif +#endif // TB_LOG #ifdef __cplusplus } -- 2.7.4