Fix log system based on dlog 63/56163/1
authorKyungwook Tak <k.tak@samsung.com>
Tue, 5 Jan 2016 05:27:32 +0000 (14:27 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Tue, 5 Jan 2016 05:38:23 +0000 (14:38 +0900)
 * set tag when library loaded by constructor
 * use dlog provider by default to filter log by LOG_TAG
 * use debug log related defined macro by TIZEN_ENGINEER_MODE

Change-Id: I8c2ac953170f53005c4062e2f76d195f387030f9
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
CMakeLists.txt
vcore/CMakeLists.txt
vcore/dpl/log/include/dpl/log/log.h
vcore/dpl/log/src/log.cpp
vcore/vcore/init-lib.cpp [new file with mode: 0644]

index 8016ae3..2a827dd 100644 (file)
@@ -19,11 +19,6 @@ SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
 SET(CMAKE_EXE_LINKER_FLAGS    "-Wl,--as-needed")
 SET(CMAKE_SKIP_RPATH          "TRUE")
 
-IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
-ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
-ADD_DEFINITIONS("-DDPL_LOGS_ENABLED")
-ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
-
 # compiler warning flags
 ADD_DEFINITIONS("-Wall")
 ADD_DEFINITIONS("-Wextra")
index 00aa7be..51385a4 100644 (file)
@@ -48,6 +48,7 @@ SET(VCORE_SOURCES
     ${VCORE_DIR}/vcore/Ocsp.cpp
     ${VCORE_DIR}/vcore/CryptoInit.cpp
     ${VCORE_DIR}/vcore/PluginHandler.cpp
+    ${VCORE_DIR}/vcore/init-lib.cpp
     )
 
 SET(VCORE_INCLUDES
index cc4c8b5..a97bc49 100644 (file)
@@ -146,13 +146,13 @@ do
 } while (0)
 
 
-#ifdef BUILD_TYPE_DEBUG
+#ifdef TIZEN_ENGINEER_MODE
     #define LogDebug(message)    DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Debug)
     #define LogPedantic(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Pedantic)
 #else
     #define LogDebug(message)    DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Debug)
     #define LogPedantic(message) DPL_MACRO_DUMMY_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Pedantic)
-#endif // BUILD_TYPE_DEBUG
+#endif // TIZEN_ENGINEER_MODE
 
 #define LogInfo(message)    DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Info)
 #define LogWarning(message) DPL_MACRO_FOR_LOGGING(message, VcoreDPL::Log::AbstractLogProvider::LogLevel::Warning)
index c2acbf1..c8905d7 100644 (file)
@@ -47,7 +47,7 @@ const char *const JOURNALD = "JOURNALD";
 
 LogSystem::LogSystem()
   : m_providerCtor({
-#ifdef BUILD_TYPE_DEBUG
+#ifdef TIZEN_ENGINEER_MODE
         { CONSOLE,  []{ return static_cast<AbstractLogProvider *>(new OldStyleLogProvider()); }},
 #endif
         { DLOG,     []{ return static_cast<AbstractLogProvider *>(new DLOGLogProvider());     }},
@@ -60,7 +60,7 @@ LogSystem::LogSystem()
     try {
         prv = m_providerCtor.at(getenv(CERTSVC_LOG_PROVIDER))();
     } catch (const std::exception &) {
-        prv = m_providerCtor[JOURNALD]();
+        prv = m_providerCtor[DLOG]();
     }
 
     AddProvider(prv);
@@ -97,10 +97,14 @@ void LogSystem::SelectProvider(const std::string &name)
 
 void LogSystem::SetLogLevel(const char *level)
 {
-    try {
-        m_level = static_cast<AbstractLogProvider::LogLevel>(std::stoi(level));
-    } catch(const std::exception&) {
+    if (!level) {
         m_level = AbstractLogProvider::LogLevel::Debug;
+    } else {
+        try {
+            m_level = static_cast<AbstractLogProvider::LogLevel>(std::stoi(level));
+        } catch(const std::exception&) {
+            m_level = AbstractLogProvider::LogLevel::Debug;
+        }
     }
 
     if (m_level < AbstractLogProvider::LogLevel::None)
@@ -108,10 +112,10 @@ void LogSystem::SetLogLevel(const char *level)
     else if (m_level > AbstractLogProvider::LogLevel::Pedantic)
         m_level = AbstractLogProvider::LogLevel::Pedantic;
 
-#ifndef BUILD_TYPE_DEBUG
+#ifndef TIZEN_ENGINEER_MODE
     if (m_level > AbstractLogProvider::LogLevel::Error)
         m_level = AbstractLogProvider::LogLevel::Error;
-#endif // BUILD_TYPE_DEBUG
+#endif
 }
 
 void LogSystem::Log(AbstractLogProvider::LogLevel level,
diff --git a/vcore/vcore/init-lib.cpp b/vcore/vcore/init-lib.cpp
new file mode 100644 (file)
index 0000000..4d3446b
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ *
+ * @file        init-lib.cpp
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       init/deinit global configuration for library
+ */
+
+#include <dpl/log/log.h>
+
+__attribute__((constructor))
+static void init_lib(void)
+{
+       try {
+               VcoreDPL::Log::LogSystemSingleton::Instance().SetTag("CERT_SVC");
+               VcoreDPL::Log::LogSystemSingleton::Instance().SetLogLevel(nullptr);
+       } catch (...) {
+               LogError("Failed to init lib for initialize log system");
+       }
+}