Remove boost-log dependency 16/235316/2
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 17 Jun 2020 11:17:16 +0000 (13:17 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 17 Jun 2020 11:40:17 +0000 (13:40 +0200)
Change-Id: If78946c8eaaa79c3d1259c5b08fed0e24b655120

15 files changed:
cmake/CheckFrameworks.cmake
src/CMakeLists.txt
src/dummy-backend/CMakeLists.txt
src/dummy-backend/dummycryptobackend.cpp
src/dummy-backend/dummycryptobackendcontext.cpp
src/kse-backend/CMakeLists.txt
src/kse-backend/cert_utils.cpp
src/kse-backend/konaise.h
src/kse-backend/ksebackend.cpp
src/kse-backend/ksebackendcontext.cpp
src/kse-backend/soresolver.cpp
src/kse-backend/tools/CMakeLists.txt
src/log.cpp [new file with mode: 0644]
src/log.h [new file with mode: 0644]
src/logging.h [deleted file]

index c1e99b5..e6827e6 100644 (file)
@@ -4,14 +4,9 @@ INCLUDE(CheckLibraryExists)
 INCLUDE(CheckFunctionExists)
 INCLUDE(CheckIncludeFiles)
 
-FIND_PACKAGE(Boost 1.54
-       REQUIRED
-       COMPONENTS
-       log)
-
 FIND_PACKAGE(PkgConfig REQUIRED)
 
-PKG_CHECK_MODULES(DLOG dlog)
+PKG_CHECK_MODULES(DLOG REQUIRED dlog)
 
 #### Find mbedtls ####
 
index 29b6378..55b7557 100644 (file)
@@ -5,14 +5,8 @@
 
 ###### Setup include paths and library directories #######
 
-ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
-
-IF(DLOG_FOUND)
-       include_directories(${DLOG_INCLUDE_DIRS})
-       link_directories(${DLOG_LIBRARY_DIRS})
-       add_definitions(${DLOG_CFLAGS_OTHER})
-       add_definitions(-DUSE_DLOG_LOGGING=1)
-ENDIF(DLOG_FOUND)
+include_directories(${DLOG_INCLUDE_DIRS})
+link_directories(${DLOG_LIBRARY_DIRS})
 
 include_directories(${Boost_INCLUDE_DIRS})
 include_directories(device-certificate-manager)
index 2af82d3..403fa54 100644 (file)
@@ -61,11 +61,8 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c
 
 ###### Include and library directories ######
 
-IF(DLOG_FOUND)
-       include_directories(${DLOG_INCLUDE_DIRS})
-       link_directories(${DLOG_LIBRARY_DIRS})
-       add_definitions(-DUSE_DLOG_LOGGING=1)
-ENDIF()
+include_directories(${DLOG_INCLUDE_DIRS})
+link_directories(${DLOG_LIBRARY_DIRS})
 
 include_directories(${Boost_INCLUDE_DIRS})
 link_directories(${Boost_LIBRARY_DIRS})
@@ -81,6 +78,7 @@ add_library(${DCM_BACKEND_API}
        ../abstractcryptobackendcontext.cpp
        dummycryptobackend.cpp
        dummycryptobackendcontext.cpp
+       ../log.cpp
        ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c
        ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c
        ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_key.c
@@ -96,12 +94,9 @@ target_link_libraries(${DCM_BACKEND_API}
        ${CMAKE_THREAD_LIBS_INIT}
        ${MBEDTLS_LIB}
        ${MBEDCRYPTO_LIB}
+       ${DLOG_LIBRARIES}
 )
 
-IF(DLOG_FOUND)
-       target_link_libraries(${DCM_BACKEND_API} ${DLOG_LIBRARIES})
-ENDIF()
-
 ###### Properties of library ######
 
 set_property(TARGET ${DCM_BACKEND_API} PROPERTY DEFINE_SYMBOL DCM_BACKEND_API_DUMMY_EXPORT)
index 26656c6..6ba286d 100644 (file)
 
 #include "dummycryptobackend.h"
 #include "dummycryptobackendcontext.h"
-#include "logging.h"
+#include "log.h"
 
 dummy_crypto_backend::dummy_crypto_backend() {
-       BOOST_LOG_FUNCTION();
 }
 
 dummy_crypto_backend::~dummy_crypto_backend() {
-       BOOST_LOG_FUNCTION();
 }
index 5b8d9ed..bdca8d7 100644 (file)
@@ -22,7 +22,7 @@
 #include <mbedtls/pk.h>
 #include <mbedtls/ctr_drbg.h>
 #include <iostream>
-#include "logging.h"
+#include "log.h"
 
 extern "C" {
        extern size_t dummy_rootca_rsa_key_size;
@@ -36,7 +36,6 @@ extern "C" {
 }
 
 dummy_crypto_backend_context::dummy_crypto_backend_context(const std::string& keyType) {
-       BOOST_LOG_FUNCTION();
        if(keyType.empty() || keyType == "RSA") {
                fKey = CRYPTO_KEY_TYPE_RSA;
        } else if(keyType == "ECDSA") {
@@ -55,7 +54,7 @@ dummy_crypto_backend_context::dummy_crypto_backend_context(const std::string& ke
                        sizeof(dummy_crypto_backend_context) );
 
        if(!ret) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Can't seed entropy source";
+               LOGE("Can't seed entropy source");
                mbedtls_ctr_drbg_free( &fCtrDrbg );
                mbedtls_entropy_free( &fEntropy );
                throw std::runtime_error("seed failure");
@@ -63,14 +62,12 @@ dummy_crypto_backend_context::dummy_crypto_backend_context(const std::string& ke
 }
 
 dummy_crypto_backend_context::~dummy_crypto_backend_context() {
-       BOOST_LOG_FUNCTION();
        mbedtls_ctr_drbg_free( &fCtrDrbg );
        mbedtls_entropy_free( &fEntropy );
 }
 
 int dummy_crypto_backend_context::request_certificate_chain(std::string& mutable_chain)
 {
-       BOOST_LOG_FUNCTION();
        if(fKey == CRYPTO_KEY_TYPE_RSA) {
                mutable_chain.assign(dummy_rootca_rsa_cert, dummy_rootca_rsa_cert_size);
        } else {
@@ -84,7 +81,6 @@ int dummy_crypto_backend_context::sign_crypto_data(MessageDigestType digestType,
                const std::string& dataToSign,
                std::string& digestResult)
 {
-       BOOST_LOG_FUNCTION();
        int error;
 
        mbedtls_pk_context pk;
@@ -104,19 +100,19 @@ int dummy_crypto_backend_context::sign_crypto_data(MessageDigestType digestType,
        }
 
        if(error != 0) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Can't parse private key";
+               LOGE("Can't parse private key");
                mbedtls_pk_free(&pk);
                return error;
        }
 
        size_t sig_len = 0;
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Maximum digest size is " << MBEDTLS_MPI_MAX_SIZE;
+       LOGD("Maximum digest size is " << MBEDTLS_MPI_MAX_SIZE);
 
        char* output = (char*)malloc(MBEDTLS_MPI_MAX_SIZE);
 
        if (!output) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Can't allocate output buffer for signing";
+               LOGE("Can't allocate output buffer for signing");
                error = -1;
                mbedtls_pk_free(&pk);
                return error;
@@ -132,9 +128,9 @@ int dummy_crypto_backend_context::sign_crypto_data(MessageDigestType digestType,
                        &fCtrDrbg);
 
        if(error != 0) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Signature generation failed";
+               LOGE("Signature generation failed");
        } else {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Signature size is " << sig_len;
+               LOGD("Signature size is " << sig_len);
                digestResult = std::string(output, sig_len);
        }
 
@@ -151,7 +147,6 @@ CryptoKeyType dummy_crypto_backend_context::dummy_crypto_backend_context::key_ty
 
 unsigned int dummy_crypto_backend_context::key_length()
 {
-       BOOST_LOG_FUNCTION();
        size_t keyLength = 0;
 
        mbedtls_pk_context pk;
index 461d220..ca66a8d 100644 (file)
 
 ###### Include and library directories ######
 
-IF(DLOG_FOUND)
-       include_directories(${DLOG_INCLUDE_DIRS})
-       link_directories(${DLOG_LIBRARY_DIRS})
-       add_definitions(-DUSE_DLOG_LOGGING=1)
-ENDIF()
+include_directories(${DLOG_INCLUDE_DIRS})
+link_directories(${DLOG_LIBRARY_DIRS})
 
 include_directories(${Boost_INCLUDE_DIRS})
 link_directories(${Boost_LIBRARY_DIRS})
@@ -39,6 +36,7 @@ add_library(${DCM_BACKEND_API}
        ../abstractcryptobackendcontext.cpp
        ksebackend.cpp
        ksebackendcontext.cpp
+       ../log.cpp
 )
 
 ###### Linking ######
@@ -50,12 +48,9 @@ target_link_libraries(${DCM_BACKEND_API}
        ${CMAKE_THREAD_LIBS_INIT}
        ${MBEDTLS_LIB}
        ${MBEDCRYPTO_LIB}
+       ${DLOG_LIBRARIES}
 )
 
-IF(DLOG_FOUND)
-       target_link_libraries(${DCM_BACKEND_API} ${DLOG_LIBRARIES})
-ENDIF()
-
 ###### Properties of library ######
 
 set_property(TARGET ${DCM_BACKEND_API} PROPERTY DEFINE_SYMBOL DCM_BACKEND_API_SEE_EXPORT)
index 2714904..a238ecd 100644 (file)
 #include <cassert>
 #include <set>
 #include <list>
-#include "logging.h"
+#include "log.h"
 
 int x509_crt_rewriter::parse(const unsigned char * buffer, size_t length)
 {
-       BOOST_LOG_FUNCTION();
        return mbedtls_x509_crt_parse(fChain, buffer, length);
 }
 
@@ -136,8 +135,6 @@ static int x509_name_cmp( const mbedtls_x509_name *a, const mbedtls_x509_name *b
 
 void x509_crt_rewriter::sort_chain()
 {
-       BOOST_LOG_FUNCTION();
-
        // Only 1 certificate - don't bother
        if(!fChain->next) {
                fChainSize = fChain->raw.len;
@@ -222,7 +219,6 @@ void x509_crt_rewriter::sort_chain()
 
 std::string x509_crt_rewriter::emit_pem()
 {
-       BOOST_LOG_FUNCTION();
        std::string buffer;
 
        if(fChainSize == 0)
index baa7425..b13d13c 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <tizen.h>
-#include <dlog.h>
 
 #define _IN_
 #define _OUT_
index 7f9a70e..e7e47a9 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "ksebackend.h"
 #include "ksebackendcontext.h"
-#include "logging.h"
+#include "log.h"
 #include <mutex>
 
 #include "konaise.h"
@@ -31,27 +31,24 @@ kse_backend::kse_backend() :
        fKseInitOK(false),
        fSoResolver(std::string(KSE_LIB_NAME))
 {
-       BOOST_LOG_FUNCTION();
        initialize_kse();
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Constructed KSE backend";
+       LOGD("Constructed KSE backend");
 }
 
 kse_backend::~kse_backend() {
-       BOOST_LOG_FUNCTION();
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Destructed KSE backend";
+       LOGD("Destructed KSE backend");
 }
 
 void kse_backend::initialize_kse() {
        if(fKseInitOK)
                return;
 
-       BOOST_LOG_FUNCTION();
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Initializing KSE backend";
+       LOGD("Initializing KSE backend");
 
        std::unique_lock<std::mutex> locker(fKSEMutex);
 
        if(!fSoResolver.ensure_loaded()) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "KSE framework init failure: Fail to load KSE library";
+               LOGE("KSE framework init failure: Fail to load KSE library");
                fKseInitOK = false;
                return;
        }
index d95fe7f..1e538d6 100644 (file)
@@ -19,7 +19,7 @@
  ******************************************************************/
 
 #include "ksebackendcontext.h"
-#include "logging.h"
+#include "log.h"
 #include "konaise.h"
 #include "cert_utils.h"
 
@@ -39,9 +39,7 @@ static int kse_get_ecdsa_signature_key = 1;
 kse_backend_context::kse_backend_context(std::shared_ptr<kse_backend> backend, const std::string& keyType) :
        fBackendPtr(backend)
 {
-       BOOST_LOG_FUNCTION();
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Created new KSE with key " << keyType;
+       LOGD("Created new KSE with key " << keyType);
 
        if(keyType.empty() || keyType == "ECDSA") {
                fKeyType = CRYPTO_KEY_TYPE_ECDSA;
@@ -49,14 +47,12 @@ kse_backend_context::kse_backend_context(std::shared_ptr<kse_backend> backend, c
                throw std::invalid_argument("Unsupported key type");
        }
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Created new KSE context at " << this;
+       LOGD("Created new KSE context at " << this);
 }
 
 kse_backend_context::~kse_backend_context()
 {
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Deleting KSE context " << this;
+       LOGD("Deleting KSE context " << this);
 }
 
 int kse_backend_context::get_certificate(unsigned int index, std::string& outcert)
@@ -66,8 +62,7 @@ int kse_backend_context::get_certificate(unsigned int index, std::string& outcer
 
        auto backend = fBackendPtr.lock();
        if(!backend) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "Unable to acquire backend pointer";
+               LOGE("Unable to acquire backend pointer");
                return -EINVAL;
        }
 
@@ -77,27 +72,20 @@ int kse_backend_context::get_certificate(unsigned int index, std::string& outcer
                error = resolver.invoke<int, unsigned int, hal_data *>(&kse_get_certificate_key,
                                        method_name, index, &cert);
        } catch(...) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "KSE: Got exception when calling resolver.invoke";
+               LOGE("KSE: Got exception when calling resolver.invoke");
                throw;
        }
 
        if(error != 0) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "Failed to get certificate. error=" << error;
+               LOGE("Failed to get certificate. error=" << error);
                return -EINVAL;
        }
 
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "KSE: Got certificate with " << cert.data_len
-                                       << " bytes and index " << index;
-#endif
+       LOGD("KSE: Got certificate with " << cert.data_len << " bytes and index " << index);
        try {
                outcert.assign((const char *)cert.data, cert.data_len);
        } catch(...) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error)
-                                       << "KSE: Got exception when assigning data";
+               LOGE("KSE: Got exception when assigning data");
                free(cert.data);
                throw;
        }
@@ -108,11 +96,7 @@ int kse_backend_context::get_certificate(unsigned int index, std::string& outcer
 
 int kse_backend_context::request_certificate_chain(std::string& mutable_chain)
 {
-       BOOST_LOG_FUNCTION();
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "KSE : Request certificate chain";
-#endif
+       LOGD("KSE : Request certificate chain");
 
        std::string leaf_cert;
        std::string subca_cert;
@@ -137,10 +121,7 @@ int kse_backend_context::request_certificate_chain(std::string& mutable_chain)
 
        mutable_chain.append(cert_writer.emit_pem());
 
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug)
-                                       << "Requested certificate in " << this;
-#endif
+       LOGD("Requested certificate in " << this);
 
        return 0;
 }
@@ -164,34 +145,31 @@ hal_hash_type _get_hal_hash_type(MessageDigestType digestType) {
 int kse_backend_context::sign_crypto_data(MessageDigestType digestType, const std::string& dataToSign,
                std::string& digestResult)
 {
-       BOOST_LOG_FUNCTION();
        hal_data hashed_data = {NULL, 0, NULL};
        hal_data signed_data = {NULL, 0, NULL};
 
        hashed_data.data = (void *)dataToSign.c_str();
        hashed_data.data_len = dataToSign.size();
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "KSE: Sign " << hashed_data.data_len << " bytes";
+       LOGD("KSE: Sign " << hashed_data.data_len << " bytes");
 
        auto backend = fBackendPtr.lock();
 
        if(!backend) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Unable to acquire backend pointer";
+               LOGE("Unable to acquire backend pointer");
                return -EINVAL;
        }
 
        auto& resolver(backend->get_so_resolver());
 
-#ifdef ENABLE_DEBUG_LOGGING
        try {
                std::string hex;
                boost::algorithm::hex((const unsigned char *)hashed_data.data,
                                (const unsigned char *)hashed_data.data + hashed_data.data_len,
                                std::back_inserter(hex));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Hashed data is " << hex;
+               LOGD("Hashed data is " << hex);
        } catch(...) {
        }
-#endif
 
        const char *method_name = "hal_ecdsa_sign_md";
        hal_ecdsa_mode mode = {HAL_ECDSA_SEC_P256R1, _get_hal_hash_type(digestType)};
@@ -203,28 +181,22 @@ int kse_backend_context::sign_crypto_data(MessageDigestType digestType, const st
        if(error != 0) {
                char buffer[256];
                mbedtls_strerror(error, buffer, sizeof(buffer));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) <<
-                               "Unable to generate ECDSA signature in " <<
-                               this <<
-                               " (" << error << ") : " <<
-                               std::string(buffer);
+               LOGE("Unable to generate ECDSA signature in " << this << " (" << error << ") : " << std::string(buffer));
 
                return MBEDTLS_ERR_PK_BAD_INPUT_DATA;
        }
 
-#ifdef ENABLE_DEBUG_LOGGING
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Signature length is " << signed_data.data_len;
+       LOGD("Signature length is " << signed_data.data_len);
 
        try {
                std::string hex;
                boost::algorithm::hex((const unsigned char *)signed_data.data,
                                (const unsigned char *)signed_data.data + signed_data.data_len,
                                std::back_inserter(hex));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Hex signature is " << hex;
+               LOGD("Hex signature is " << hex);
        } catch(...) {
        }
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "KSE: Generated ECDSA signature";
-#endif
+       LOGD("KSE: Generated ECDSA signature");
 
        digestResult.assign((const char *)signed_data.data, signed_data.data_len);
 
index e3481cb..c236365 100644 (file)
@@ -19,7 +19,7 @@
  ******************************************************************/
 
 #include "soresolver.h"
-#include "logging.h"
+#include "log.h"
 #include <dlfcn.h>
 
 so_resolver::so_resolver(const std::string& libraryName) :
@@ -31,16 +31,14 @@ so_resolver::so_resolver(const std::string& libraryName) :
 so_resolver::~so_resolver()
 {
        if(fLibraryHandle.load(std::memory_order_relaxed)) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Unloading library " << fLibraryName;
+               LOGD("Unloading library " << fLibraryName);
                dlclose(fLibraryHandle.exchange(nullptr, std::memory_order_relaxed));
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Unloaded library " << fLibraryName;
+               LOGD("Unloaded library " << fLibraryName);
        }
 }
 
 void * so_resolver::resolve_function(const int * key_ptr, const char * name) noexcept
 {
-       BOOST_LOG_FUNCTION();
-
        std::unique_lock<std::mutex> locker(fCacheLock);
 
        if(key_ptr) {
@@ -53,33 +51,30 @@ void * so_resolver::resolve_function(const int * key_ptr, const char * name) noe
        void * handle = fLibraryHandle.load(std::memory_order_relaxed);
 
        if(handle) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Resolving symbol " << name << " from " << fLibraryName;
+               LOGD("Resolving symbol " << name << " from " << fLibraryName);
                void * sym = dlsym(handle, name);
                if(!sym) {
-                       BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) <<  "Unable to resolve symbol " << name << " from " <<
-                                       fLibraryName << ": Error is " << dlerror();
+                       LOGE("Unable to resolve symbol " << name << " from " << fLibraryName << ": Error is " << dlerror());
                } else {
                        try {
                                if(key_ptr) {
                                        fCache.emplace(key_ptr, sym);
                                }
                        } catch(...) {
-                               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) <<  "Problem with updating symbol cache!!";
+                               LOGE("Problem with updating symbol cache!!");
                                sym = nullptr;
                        }
                }
                return sym;
        }
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Trying to resolve symbol " << name << " from not loaded library " << fLibraryName;
+       LOGE("Trying to resolve symbol " << name << " from not loaded library " << fLibraryName);
 
        return nullptr;
 }
 
 bool so_resolver::ensure_loaded() noexcept
 {
-       BOOST_LOG_FUNCTION();
-
        std::unique_lock<std::mutex> locker(fCacheLock);
 
        void * handle = fLibraryHandle.load(std::memory_order_acquire);
@@ -87,16 +82,16 @@ bool so_resolver::ensure_loaded() noexcept
        if(handle)
                return true;
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Loading library " << fLibraryName;
+       LOGD("Loading library " << fLibraryName);
 
        handle = dlopen(fLibraryName.c_str(), RTLD_LAZY | RTLD_LOCAL);
 
        if(!handle) {
-               BOOST_LOG_SEV(dcm_logger::get(), log_severity::error) << "Unable to load library " << fLibraryName << ": " << dlerror();
+               LOGE("Unable to load library " << fLibraryName << ": " << dlerror());
                return false;
        }
 
-       BOOST_LOG_SEV(dcm_logger::get(), log_severity::debug) << "Library loaded " << fLibraryName;
+       LOGD("Library loaded " << fLibraryName);
 
        void * expectedValue = nullptr;
 
index 5753020..5f12f6e 100644 (file)
@@ -1,7 +1,6 @@
 #######################################################################################
 # For SE_KONAI
 
-ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
 include_directories(${Boost_INCLUDE_DIRS})
 link_directories(${Boost_LIBRARY_DIRS})
 
@@ -9,13 +8,14 @@ include_directories(../src ../src/kse-backend)
 
 add_executable(dcm_konaise_tool
        ../soresolver.cpp
+       ../../log.cpp
        konaise_tool.cpp)
 
 target_link_libraries(dcm_konaise_tool
-       ${Boost_LOG_LIBRARY}
        ${Boost_SYSTEM_LIBRARY}
        dl
        ${CMAKE_THREAD_LIBS_INIT}
+       ${DLOG_LIBRARIES}
 )
 
 install(TARGETS dcm_konaise_tool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/src/log.cpp b/src/log.cpp
new file mode 100644 (file)
index 0000000..baef423
--- /dev/null
@@ -0,0 +1,58 @@
+/******************************************************************
+ *
+ * Copyright 2020 Samsung Electronics 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.
+ *
+ ******************************************************************/
+
+#include <dlog.h>
+#include <syslog.h>
+
+#ifdef NDEBUG
+int __log_level = LOG_ERR;
+#else
+int __log_level = LOG_DEBUG;
+#endif
+
+#define DCM_LOG_TAG "DEVICE_CERTIFICATE_MANAGER_BACKEND"
+
+void dcm_print(int priority, char const *fmt, ...)
+{
+       log_priority dlog_prio;
+
+       switch (priority) {
+               case LOG_EMERG:
+                       dlog_prio = DLOG_FATAL;
+                       break;
+               case LOG_ERR:
+                       dlog_prio = DLOG_ERROR;
+                       break;
+               case LOG_WARNING:
+                       dlog_prio = DLOG_WARN;
+                       break;
+               case LOG_INFO:
+                       dlog_prio = DLOG_INFO;
+                       break;
+               case LOG_DEBUG:
+                       dlog_prio = DLOG_DEBUG;
+                       break;
+               default:
+                       dlog_prio = DLOG_DEFAULT;
+       }
+
+       va_list ap;
+       va_start(ap, fmt);
+       (void) vprint_system_log(dlog_prio, DCM_LOG_TAG, fmt, ap);
+       va_end(ap);
+}
diff --git a/src/log.h b/src/log.h
new file mode 100644 (file)
index 0000000..f479e31
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,70 @@
+/******************************************************************
+ *
+ * Copyright 2020 Samsung Electronics 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.
+ *
+ ******************************************************************/
+#ifndef SHARED_LOG_H_
+#define SHARED_LOG_H_
+
+#include <stdlib.h>
+#include <syslog.h>
+#include <sstream>
+
+#define UNUSED __attribute__((unused))
+
+extern int __log_level;
+extern void dcm_print(int priority, char const *fmt, ...);
+
+namespace {
+       template <typename ...Args>
+       void UNUSED __LOG_FUN(int level, const std::stringstream &format, Args&&... args) {
+               dcm_print(level, format.str().c_str(), std::forward<Args>(args)...);
+       }
+
+       template <>
+       void UNUSED __LOG_FUN(int level, const std::stringstream &format) {
+               dcm_print(level, "%s", format.str().c_str());
+       }
+
+       template <typename ...Args>
+       void UNUSED __LOG_FUN(int level, const char *format, Args&&... args) {
+               dcm_print(level, format, std::forward<Args>(args)...);
+       }
+
+       template <>
+       void UNUSED __LOG_FUN(int level, const char *format) {
+               dcm_print(level, "%s", format);
+       }
+
+} // namespace anonymous
+
+#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define __LOG(LEVEL, FORMAT, ...) \
+       do { \
+               if (LEVEL <= __log_level) { \
+                       std::stringstream __LOG_FORMAT; \
+                       __LOG_FORMAT << __FILENAME__ << ": " << __func__ << "(" << __LINE__ << ") > " << FORMAT; \
+                       __LOG_FUN(LEVEL, __LOG_FORMAT, ##__VA_ARGS__); \
+               } \
+       } while (0)
+
+#define LOGM(...)  __LOG(LOG_EMERG, __VA_ARGS__)   /* system is unusable */
+#define LOGE(...)  __LOG(LOG_ERR, __VA_ARGS__)     /* error conditions */
+#define LOGW(...)  __LOG(LOG_WARNING, __VA_ARGS__) /* warning conditions */
+#define LOGI(...)  __LOG(LOG_INFO, __VA_ARGS__)    /* informational */
+#define LOGD(...)  __LOG(LOG_DEBUG, __VA_ARGS__)   /* debug-level messages */
+
+#endif /* SHARED_LOG_H_ */
diff --git a/src/logging.h b/src/logging.h
deleted file mode 100644 (file)
index a2f72b8..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/******************************************************************
- *
- * Copyright 2017 - 2019 Samsung Electronics All Rights Reserved.
- *
- * Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
- *
- * 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.
- *
- ******************************************************************/
-
-#ifndef LOGGING_H_
-#define LOGGING_H_
-
-#include <boost/log/common.hpp>
-#include <boost/log/expressions.hpp>
-#include <boost/log/attributes.hpp>
-#include <boost/log/sinks/sync_frontend.hpp>
-#include <boost/log/sinks/syslog_backend.hpp>
-#include <boost/log/sources/logger.hpp>
-#include <boost/log/utility/setup/console.hpp>
-#include <boost/log/utility/setup/common_attributes.hpp>
-#include <boost/log/attributes/timer.hpp>
-#include <boost/log/attributes/named_scope.hpp>
-
-#ifdef USE_DLOG_LOGGING
-#define LOG_TAG                "DEVICE_CERTIFICATE_MANAGER_SERVER"
-#include <dlog.h>
-#endif
-
-enum class log_severity {
-       debug,
-       normal,
-       warning,
-       error
-};
-
-// Global logger declaration
-BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(dcm_logger, boost::log::sources::severity_logger_mt<log_severity>)
-
-#if defined(NDEBUG) && !defined(DEBUG)
-#else
-#define ENABLE_DEBUG_LOGGING           1
-#endif
-
-#endif /* LOGGING_H_ */