From 802e6af17b8a6e35a512b2da8ffdc729e2c272be Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Tue, 5 Jan 2016 14:27:32 +0900 Subject: [PATCH] Fix log system based on dlog * 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 --- CMakeLists.txt | 5 ----- vcore/CMakeLists.txt | 1 + vcore/dpl/log/include/dpl/log/log.h | 4 ++-- vcore/dpl/log/src/log.cpp | 18 +++++++++++------- vcore/vcore/init-lib.cpp | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 vcore/vcore/init-lib.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8016ae3..2a827dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/vcore/CMakeLists.txt b/vcore/CMakeLists.txt index 00aa7be..51385a4 100644 --- a/vcore/CMakeLists.txt +++ b/vcore/CMakeLists.txt @@ -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 diff --git a/vcore/dpl/log/include/dpl/log/log.h b/vcore/dpl/log/include/dpl/log/log.h index cc4c8b5..a97bc49 100644 --- a/vcore/dpl/log/include/dpl/log/log.h +++ b/vcore/dpl/log/include/dpl/log/log.h @@ -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) diff --git a/vcore/dpl/log/src/log.cpp b/vcore/dpl/log/src/log.cpp index c2acbf1..c8905d7 100644 --- a/vcore/dpl/log/src/log.cpp +++ b/vcore/dpl/log/src/log.cpp @@ -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(new OldStyleLogProvider()); }}, #endif { DLOG, []{ return static_cast(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(std::stoi(level)); - } catch(const std::exception&) { + if (!level) { m_level = AbstractLogProvider::LogLevel::Debug; + } else { + try { + m_level = static_cast(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 index 0000000..4d3446b --- /dev/null +++ b/vcore/vcore/init-lib.cpp @@ -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 + +__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"); + } +} -- 2.7.4