add OCSetLogLevel API in logger
authorjihwan.seo <jihwan.seo@samsung.com>
Fri, 10 Feb 2017 10:46:49 +0000 (19:46 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 15 Feb 2017 05:10:26 +0000 (05:10 +0000)
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 <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17197
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/logger/include/logger.h
resource/csdk/logger/src/logger.c

index 75456ac..548b37d 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #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.
index 51a4221..f34f434 100644 (file)
 #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