diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d7b654..37fd9da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ link_directories( file(GLOB CAPI_SRCS "src/CommonAPI/*.cpp") list(SORT CAPI_SRCS) -add_library(CommonAPI SHARED ${CAPI_SRCS}) +add_library(CommonAPI ${CAPI_SRCS}) target_link_libraries(CommonAPI PRIVATE ${DL_LIBRARY} ${DLT_LIBRARIES}) set_target_properties(CommonAPI PROPERTIES VERSION ${LIBCOMMONAPI_MAJOR_VERSION}.${LIBCOMMONAPI_MINOR_VERSION}.${LIBCOMMONAPI_PATCH_VERSION} SOVERSION ${LIBCOMMONAPI_MAJOR_VERSION}.${LIBCOMMONAPI_MINOR_VERSION}.${LIBCOMMONAPI_PATCH_VERSION} LINKER_LANGUAGE C) set_target_properties (CommonAPI PROPERTIES INTERFACE_LINK_LIBRARY "") diff --git a/include/CommonAPI/Logger.hpp b/include/CommonAPI/Logger.hpp index 0658be8..fea391e 100644 --- a/include/CommonAPI/Logger.hpp +++ b/include/CommonAPI/Logger.hpp @@ -84,7 +84,7 @@ class Logger { private: class LoggerImpl; - static std::unique_ptr loggerImpl_; + static LoggerImpl &getInstance(); COMMONAPI_EXPORT static bool isLogged(Level _level); COMMONAPI_EXPORT static void doLog(Level _level, const std::string& _message); diff --git a/src/CommonAPI/Logger.cpp b/src/CommonAPI/Logger.cpp index f5804c8..b91d967 100644 --- a/src/CommonAPI/Logger.cpp +++ b/src/CommonAPI/Logger.cpp @@ -176,23 +176,26 @@ class Logger::LoggerImpl { #endif }; -std::unique_ptr Logger::loggerImpl_ = - std::unique_ptr(new Logger::LoggerImpl()); +Logger::LoggerImpl &Logger::getInstance() +{ + static LoggerImpl loggerImpl; + return loggerImpl; +} Logger::Logger() = default; Logger::~Logger() = default; void Logger::init(bool _useConsole, const std::string &_fileName, bool _useDlt, const std::string& _level) { - loggerImpl_->init(_useConsole, _fileName, _useDlt, _level); + getInstance().init(_useConsole, _fileName, _useDlt, _level); } bool Logger::isLogged(Level _level) { - return loggerImpl_->isLogged(_level); + return getInstance().isLogged(_level); } void Logger::doLog(Level _level, const std::string& _message) { - loggerImpl_->doLog(_level, _message); + getInstance().doLog(_level, _message); } } //namespace CommonAPI