From f77cc7180365d65763d63f6806aca452a1af04ba Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Fri, 10 Feb 2017 19:46:49 +0900 Subject: [PATCH] add OCSetLogLevel API in logger we can filter log with level through setLogLevel API. it will be helpped to reduce unnecessary log without additional build option in some lite device. and also we can filter private information such as Device ID, Access Token, etc. Change-Id: I91bff24737cbc7f09985adc142fc5f3d37e8f577 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/17197 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai Reviewed-by: Ashok Babu Channa --- resource/csdk/logger/include/logger.h | 20 +++++++++++++-- resource/csdk/logger/src/logger.c | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/resource/csdk/logger/include/logger.h b/resource/csdk/logger/include/logger.h index 75456ac..548b37d 100644 --- a/resource/csdk/logger/include/logger.h +++ b/resource/csdk/logger/include/logger.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "logger_types.h" #ifdef __ANDROID__ @@ -64,7 +65,10 @@ typedef enum { INFO = DLOG_INFO, WARNING = DLOG_WARN, ERROR = DLOG_ERROR, - FATAL = DLOG_ERROR + FATAL = DLOG_ERROR, + DEBUG_LITE = DLOG_DEBUG, + INFO_LITE = DLOG_INFO, + INFO_PRIVATE = DLOG_INFO, } LogLevel; #else @@ -78,10 +82,22 @@ typedef enum { INFO, WARNING, ERROR, - FATAL + FATAL, + DEBUG_LITE, // The DEBUG log for Lite device + INFO_LITE, // The INFO log for Lite device + INFO_PRIVATE, // The log contained private data } LogLevel; + #endif +/** + * Set log level and privacy log to print. + * + * @param level - log level. + * @param hidePrivateLogEntries - Hide Private Log. + */ +void OCSetLogLevel(LogLevel level, bool hidePrivateLogEntries); + #ifdef __TIZEN__ /** * Output the contents of the specified buffer (in hex) with the specified priority level. diff --git a/resource/csdk/logger/src/logger.c b/resource/csdk/logger/src/logger.c index 51a4221..f34f434 100644 --- a/resource/csdk/logger/src/logger.c +++ b/resource/csdk/logger/src/logger.c @@ -55,6 +55,11 @@ #include "string.h" #include "logger_types.h" +// log level +LogLevel g_level = DEBUG; +// privacy log +bool g_hidePrivateLogEntries = false; + #ifndef __TIZEN__ static oc_log_ctx_t *logCtx = 0; #endif @@ -155,6 +160,13 @@ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, size_ OCLogv(level, tag, "%s", lineBuffer); } } + +void OCSetLogLevel(LogLevel level, bool hidePrivateLogEntries) +{ + g_level = level; + g_hidePrivateLogEntries = hidePrivateLogEntries; +} + #ifndef __TIZEN__ void OCLogConfig(oc_log_ctx_t *ctx) { @@ -189,6 +201,17 @@ void OCLogv(LogLevel level, const char * tag, const char * format, ...) if (!format || !tag) { return; } + + if (g_level > level && ERROR != level && WARNING != level && FATAL != level) + { + return; + } + + if (true == g_hidePrivateLogEntries && INFO_PRIVATE == level) + { + return; + } + char buffer[MAX_LOG_V_BUFFER_SIZE] = {0}; va_list args; va_start(args, format); @@ -212,6 +235,31 @@ void OCLog(LogLevel level, const char * tag, const char * logStr) return; } + if (g_level > level && ERROR != level && WARNING != level && FATAL != level) + { + return; + } + + if (true == g_hidePrivateLogEntries && INFO_PRIVATE == level) + { + return; + } + + switch(level) + { + case DEBUG_LITE: + level = DEBUG; + break; + case INFO_LITE: + level = INFO; + break; + case INFO_PRIVATE: + level = INFO; + break; + default: + break; + } + #ifdef __ANDROID__ #ifdef ADB_SHELL -- 2.7.4