diff --git a/CMakeLists.txt b/CMakeLists.txt index 764a050b91b..844319ed62a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,12 @@ option(USE_GOLD_LD "Use gold linker intead of GNU linker" ON) option(USE_CCACHE "Turn on ccache usage" ON) option(USE_DISTCC "Turn on distributed build_usage" OFF) +set(LOGGER_NAME "LOG4CXX" CACHE STRING "Logging library to use (BOOST, LOG4CXX)") +set_property(CACHE LOGGER_NAME PROPERTY STRINGS BOOST LOG4CXX) +if(LOGGER_NAME STREQUAL "") + set(LOGGER_NAME "LOG4CXX") +endif() + set (EXTENDED_POLICY "PROPRIETARY" CACHE STRING "Policy mode (PROPRIETARY, HTTP or EXTERNAL_PROPRIETARY)") set_property(CACHE EXTENDED_POLICY PROPERTY STRINGS PROPRIETARY HTTP EXTERNAL_PROPRIETARY) if(EXTENDED_POLICY STREQUAL "") @@ -186,6 +192,12 @@ get_property(cValue CACHE ENABLE_SECURITY PROPERTY VALUE) file(APPEND "${build_config_path}" "//${cHelpString}\n") file(APPEND "${build_config_path}" "ENABLE_SECURITY:${cType}=${cValue}\n\n") +get_property(cHelpString CACHE LOGGER_NAME PROPERTY HELPSTRING) +get_property(cType CACHE LOGGER_NAME PROPERTY TYPE) +get_property(cValue CACHE LOGGER_NAME PROPERTY VALUE) +file(APPEND "${build_config_path}" "//${cHelpString}\n") +file(APPEND "${build_config_path}" "LOGGER_NAME:${cType}=${cValue}\n\n") + get_property(cHelpString CACHE EXTENDED_MEDIA_MODE PROPERTY HELPSTRING) get_property(cType CACHE EXTENDED_MEDIA_MODE PROPERTY TYPE) get_property(cValue CACHE EXTENDED_MEDIA_MODE PROPERTY VALUE) @@ -376,6 +388,14 @@ else() set(POLICY_MOCK_INCLUDE_PATH ${COMPONENTS_DIR}/include/test/policy/policy_regular/) endif() +if(${LOGGER_NAME} STREQUAL "LOG4CXX") + add_definitions(-DLOG4CXX_LOGGER) + message(STATUS "Selected the apache log4cxx logging library") +else() + add_definitions(-DBOOST_LOGGER) + message(STATUS "Selected the boost logging library") +endif() + # TODO(AK): check current OS here add_definitions(-DOS_POSIX) @@ -419,7 +439,8 @@ include_directories( add_subdirectory(./src/3rd_party EXCLUDE_FROM_ALL) find_package(OpenSSL REQUIRED) -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") + message(STATUS "Including log4cxx") include_directories ( ${LOG4CXX_INCLUDE_DIRECTORY} ) endif() diff --git a/src/3rd_party/CMakeLists.txt b/src/3rd_party/CMakeLists.txt index 26baeca3ebc..10320e5afb4 100644 --- a/src/3rd_party/CMakeLists.txt +++ b/src/3rd_party/CMakeLists.txt @@ -47,7 +47,7 @@ if(FORCE_3RD_PARTY) endif() endif() -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") # --- libexpat add_subdirectory(expat-2.1.0) set(EXPAT_LIBS_DIRECTORY ${3RD_PARTY_INSTALL_PREFIX_ARCH}/lib PARENT_SCOPE) @@ -222,7 +222,11 @@ endif() set(BOOST_ROOT ${3RD_PARTY_INSTALL_PREFIX}) set(Boost_NO_BOOST_CMAKE ON) -find_package(Boost 1.72.0 COMPONENTS system thread date_time filesystem regex) +set(BOOST_COMPONENTS system thread date_time filesystem regex) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "BOOST") + list(APPEND BOOST_COMPONENTS log log_setup) +endif() +find_package(Boost 1.72.0 COMPONENTS ${BOOST_COMPONENTS}) if (NOT ${Boost_FOUND}) set(BOOST_LIB_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost_src) set(BOOST_LIBS_DIRECTORY ${3RD_PARTY_INSTALL_PREFIX}/lib) @@ -234,15 +238,23 @@ if (NOT ${Boost_FOUND}) set(BOOST_INSTALL_COMMAND sudo ./b2 install) endif() include(ExternalProject) + + set(boost_component_install_flags --with-system --with-thread --with-date_time --with-filesystem --with-regex) + set(boost_component_libraries system thread date_time filesystem regex) + if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "BOOST") + list(APPEND boost_component_install_flags --with-log) + list(APPEND boost_component_libraries log) + endif() + string (REPLACE ";" "," boost_component_libraries_str "${boost_component_libraries}") ExternalProject_Add( Boost URL https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz URL_HASH SHA256=c66e88d5786f2ca4dbebb14e06b566fb642a1a6947ad8cc9091f9f445134143f DOWNLOAD_DIR ${BOOST_LIB_SOURCE_DIRECTORY} SOURCE_DIR ${BOOST_LIB_SOURCE_DIRECTORY} - CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=system,thread,date_time,filesystem,regex --prefix=${3RD_PARTY_INSTALL_PREFIX} + CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=${boost_component_libraries_str} --prefix=${3RD_PARTY_INSTALL_PREFIX} BUILD_COMMAND ./b2 - INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} --clean --prefix=${3RD_PARTY_INSTALL_PREFIX} && ${BOOST_INSTALL_COMMAND} --with-system --with-thread --with-date_time --with-filesystem --with-regex --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log + INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} --clean --prefix=${3RD_PARTY_INSTALL_PREFIX} && ${BOOST_INSTALL_COMMAND} ${boost_component_install_flags} --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log INSTALL_DIR ${3RD_PARTY_INSTALL_PREFIX} BUILD_IN_SOURCE true ) diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index c2b7255eccc..cdd3760fa0b 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -138,7 +138,7 @@ if (BUILD_USB_SUPPORT) endif() endif() -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) @@ -160,7 +160,12 @@ target_link_libraries(${PROJECT} ${LIBRARIES}) add_dependencies(${PROJECT} Policy) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/build_config.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +if (${LOGGER_NAME} STREQUAL "LOG4CXX") + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +else() + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/boostlogconfig.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/audio.8bit.wav DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/smartDeviceLink.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -217,7 +222,7 @@ endif () # Install rules install(TARGETS ${PROJECT} DESTINATION bin) install( - FILES build_config.txt log4cxx.properties audio.8bit.wav test.txt + FILES build_config.txt log4cxx.properties boostlogconfig.ini audio.8bit.wav test.txt ${CMAKE_CURRENT_BINARY_DIR}/smartDeviceLink.ini hmi_capabilities.json sdl_preloaded_pt.json sample_policy_manager.py ${CMAKE_SOURCE_DIR}/mycert.pem ${CMAKE_SOURCE_DIR}/mykey.pem diff --git a/src/appMain/boostlogconfig.ini b/src/appMain/boostlogconfig.ini new file mode 100644 index 00000000000..a5d43a5bf01 --- /dev/null +++ b/src/appMain/boostlogconfig.ini @@ -0,0 +1,51 @@ +# Core settings +[Core] +DisableLogging=false + +# Console Logging +[Sinks.Console] +DisableLogging=true +Destination=Console +Filter="%Severity% >= debug" +Format="%Severity% [%TimeStamp%][%Component%] %Message%" +AutoFlush=true +Asynchronous=true + +# SDL log file +[Sinks.AllMessages] +DisableLogging=false +Destination=TextFile +FileName=SmartDeviceLinkCore.log +Append=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for all TransportManager messages +[Sinks.TransportManager] +DisableLogging=false +Destination=TextFile +FileName=TransportManager.log +Append=false +Filter="%Component% = TransportManager" +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for handling Ford protocol info (include ProtocolHandler, ConnectionHandler, SecurityManager) +[Sinks.ProtocolFordHandling] +DisableLogging=false +Destination=TextFile +FileName=ProtocolFordHandling.log +Append=false +Filter="%Component% = ConnectionHandler or %Component% = HeartBeatMonitor or %Component% = ProtocolHandler or %Component% = SecurityManager" +Format="%Severity% [%TimeStamp%][%Component%] %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +[Sinks.Telnet] +DisableLogging=true +Destination=Syslog +Asynchronous=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +LocalAddress="http://127.0.0.1:6676/" \ No newline at end of file diff --git a/src/appMain/main.cc b/src/appMain/main.cc index 34c5b4dbfa3..cedaf50497e 100644 --- a/src/appMain/main.cc +++ b/src/appMain/main.cc @@ -43,7 +43,15 @@ // ---------------------------------------------------------------------------- #ifdef ENABLE_LOG + +#ifdef LOG4CXX_LOGGER +#include "utils/appenders_loader.h" #include "utils/logger/log4cxxlogger.h" + +#else // LOG4CXX_LOGGER +#include "utils/logger/boostlogger.h" +#endif // LOG4CXX_LOGGER + #include "utils/logger/logger_impl.h" #endif // ENABLE_LOG @@ -53,7 +61,6 @@ #include "signal_handlers.h" #include "config_profile/profile.h" -#include "utils/appenders_loader.h" #include "utils/signals.h" #include "utils/system.h" @@ -142,18 +149,24 @@ int32_t main(int32_t argc, char** argv) { if (profile_instance.logs_enabled()) { // Logger initialization // Redefine for each paticular logger implementation +#ifdef LOG4CXX_LOGGER auto logger = std::unique_ptr( new logger::Log4CXXLogger("log4cxx.properties")); + + if (!utils::appenders_loader.Loaded()) { + SDL_LOG_ERROR("Appenders plugin not loaded, file logging disabled"); + } +#else // LOG4CXX_LOGGER + auto logger = std::unique_ptr( + new logger::BoostLogger("boostlogconfig.ini")); +#endif // LOG4CXX_LOGGER + logger_impl->Init(std::move(logger)); } #endif threads::Thread::SetNameForId(threads::Thread::CurrentId(), "SDLCore"); - if (!utils::appenders_loader.Loaded()) { - SDL_LOG_ERROR("Appenders plugin not loaded, file logging disabled"); - } - SDL_LOG_INFO("Application started!"); SDL_LOG_INFO("SDL version: " << profile_instance.sdl_version()); diff --git a/src/appMain/test/CMakeLists.txt b/src/appMain/test/CMakeLists.txt index 057e1e98694..c700c5dc570 100644 --- a/src/appMain/test/CMakeLists.txt +++ b/src/appMain/test/CMakeLists.txt @@ -41,6 +41,7 @@ set(testSources set(LIBRARIES gmock + SmartObjects ) create_test(low_voltage_signals_handler_test "${testSources}" "${LIBRARIES}") diff --git a/src/components/application_manager/CMakeLists.txt b/src/components/application_manager/CMakeLists.txt index c7f2aede9a8..6dde632a395 100644 --- a/src/components/application_manager/CMakeLists.txt +++ b/src/components/application_manager/CMakeLists.txt @@ -175,7 +175,7 @@ list(APPEND LIBRARIES AMPolicyLibrary ) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt index ef215cdd5a5..98de75d6d25 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/CMakeLists.txt @@ -62,7 +62,7 @@ set(LIBRARIES sdl_rpc_plugin_static ) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt index 8129e1240d4..f1cdab02c4b 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/CMakeLists.txt @@ -59,7 +59,7 @@ set(LIBRARIES Utils ) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt index 16e95bf5995..b438943eca9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt @@ -63,7 +63,7 @@ set(LIBRARIES gmock_main ) -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt index a22543ba09a..adc0cec1b35 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager/CMakeLists.txt @@ -71,7 +71,7 @@ set(LIBRARIES dl ) -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt index 67a178893c6..073359ce808 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/CMakeLists.txt @@ -65,7 +65,7 @@ set(LIBRARIES jsoncpp ) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt index 8c29cccfffd..a741c32129c 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/CMakeLists.txt @@ -54,7 +54,7 @@ set(LIBRARIES connectionHandler ) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index 7b1a262f1b8..cdaa770155f 100755 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -123,7 +123,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "QNX") list(REMOVE_ITEM LIBRARIES dl) endif() -if (ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) diff --git a/src/components/application_manager/test/app_launch/CMakeLists.txt b/src/components/application_manager/test/app_launch/CMakeLists.txt index 1c038020b98..89e1eef2b44 100644 --- a/src/components/application_manager/test/app_launch/CMakeLists.txt +++ b/src/components/application_manager/test/app_launch/CMakeLists.txt @@ -46,7 +46,7 @@ set(LIBRARIES ApplicationManager ) - if (ENABLE_LOG) + if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) list(APPEND LIBRARIES apr-1 -L${APR_LIBS_DIRECTORY}) list(APPEND LIBRARIES aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY}) diff --git a/src/components/hmi_message_handler/CMakeLists.txt b/src/components/hmi_message_handler/CMakeLists.txt index 8fafee1ac53..f66b19696d0 100644 --- a/src/components/hmi_message_handler/CMakeLists.txt +++ b/src/components/hmi_message_handler/CMakeLists.txt @@ -74,7 +74,7 @@ endif() target_link_libraries("HMIMessageHandler" ${LIBRARIES}) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries("HMIMessageHandler" log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/media_manager/CMakeLists.txt b/src/components/media_manager/CMakeLists.txt index 50c9fce20a2..f4da8ded480 100644 --- a/src/components/media_manager/CMakeLists.txt +++ b/src/components/media_manager/CMakeLists.txt @@ -102,7 +102,7 @@ collect_sources(SOURCES "${PATHS}" "${EXCLUDE_PATHS}") add_library("MediaManager" ${SOURCES}) target_link_libraries("MediaManager" ${LIBRARIES}) -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries("MediaManager" log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/media_manager/test/CMakeLists.txt b/src/components/media_manager/test/CMakeLists.txt index 265a62a0d87..1b74554fb19 100644 --- a/src/components/media_manager/test/CMakeLists.txt +++ b/src/components/media_manager/test/CMakeLists.txt @@ -69,6 +69,6 @@ endif() create_test("media_manager_test" "${SOURCES}" "${LIBRARIES}") -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries("media_manager_test" log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/policy/policy_external/CMakeLists.txt b/src/components/policy/policy_external/CMakeLists.txt index 361c48a598b..72f7dd7bdb4 100644 --- a/src/components/policy/policy_external/CMakeLists.txt +++ b/src/components/policy/policy_external/CMakeLists.txt @@ -128,7 +128,7 @@ target_link_libraries(PolicyStatic ${LIBRARIES}) add_library(Policy SHARED "src/policy_manager_impl.cc") target_link_libraries(Policy PolicyStatic) -if (ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries(Policy log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/policy/policy_external/test/boostlogconfig.ini b/src/components/policy/policy_external/test/boostlogconfig.ini new file mode 100644 index 00000000000..5cf35d0e7a5 --- /dev/null +++ b/src/components/policy/policy_external/test/boostlogconfig.ini @@ -0,0 +1,46 @@ +# Core settings +[Core] +DisableLogging=false + +# Console Logging (Only ERROR and FATAL messages are logged to console) +[Sinks.Console] +DisableLogging=false +Destination=Console +Filter="%Severity% >= error" +Format="%Severity% [%TimeStamp%][%Component%] %Message%" +AutoFlush=true +Asynchronous=true + +# SDL log file +[Sinks.AllMessages] +DisableLogging=false +Destination=TextFile +FileName=SmartDeviceLinkCore.log +Append=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for all SQLPTRepresentation messages +[Sinks.SQLPTRepresentation] +DisableLogging=false +Destination=TextFile +FileName="SQLRepresentation_%Y-%m-%d.log" +RotationTimePoint="00:00:00" +Append=false +Filter="%Trace% contains SQLPTRepresentation" +Format="%Severity% [%TimeStamp%] :%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for all PolicyManagerImpl messages +[Sinks.PolicyManagerImpl] +DisableLogging=false +Destination=TextFile +FileName="PolicyManagerImpl_%Y-%m-%d.log" +RotationTimePoint="00:00:00" +Append=false +Filter="%Trace% contains PolicyManagerImpl" +Format="%Severity% [%TimeStamp%] :%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true diff --git a/src/components/policy/policy_regular/CMakeLists.txt b/src/components/policy/policy_regular/CMakeLists.txt index e14057ec891..85ba86cfba5 100644 --- a/src/components/policy/policy_regular/CMakeLists.txt +++ b/src/components/policy/policy_regular/CMakeLists.txt @@ -150,7 +150,7 @@ target_link_libraries(PolicyStatic ${LIBRARIES}) add_library(Policy SHARED "src/policy_manager_impl.cc") target_link_libraries(Policy PolicyStatic) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries(Policy log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/policy/policy_regular/test/boostlogconfig.ini b/src/components/policy/policy_regular/test/boostlogconfig.ini new file mode 100644 index 00000000000..f33da81c930 --- /dev/null +++ b/src/components/policy/policy_regular/test/boostlogconfig.ini @@ -0,0 +1,51 @@ +# Core settings +[Core] +DisableLogging=false + +# Console Logging +[Sinks.Console] +DisableLogging=true +Destination=Console +Filter="%Severity% > trace" +Format="%Severity% [%TimeStamp%][%Component%] %Message%" +AutoFlush=true +Asynchronous=true + +# SDL log file +[Sinks.AllMessages] +DisableLogging=false +Destination=TextFile +FileName=SmartDeviceLinkCore.log +Append=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for all TransportManager messages +[Sinks.TransportManager] +DisableLogging=false +Destination=TextFile +FileName=TransportManager.log +Append=false +Filter="%Component% = TransportManager" +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for handling Ford protocol info (include ProtocolHandler, ConnectionHandler, SecurityManager) +[Sinks.ProtocolFordHandling] +DisableLogging=false +Destination=TextFile +FileName=ProtocolFordHandling.log +Append=false +Filter="%Component% = ConnectionHandler or %Component% = HeartBeatMonitor or %Component% = ProtocolHandler or %Component% = SecurityManager" +Format="%Severity% [%TimeStamp%][%Component%] %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +[Sinks.Telnet] +DisableLogging=true +Destination=Syslog +Asynchronous=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +LocalAddress="http://127.0.0.1:6676/" \ No newline at end of file diff --git a/src/components/smart_objects/CMakeLists.txt b/src/components/smart_objects/CMakeLists.txt index 6bc70f82261..bb8bb1cf073 100644 --- a/src/components/smart_objects/CMakeLists.txt +++ b/src/components/smart_objects/CMakeLists.txt @@ -48,7 +48,7 @@ add_library("SmartObjects" ${SOURCES}) target_link_libraries("SmartObjects" Utils) add_dependencies("SmartObjects" MOBILE_API) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries("SmartObjects" log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/telemetry_monitor/test/CMakeLists.txt b/src/components/telemetry_monitor/test/CMakeLists.txt index 960985e45ce..a66d3bdddcf 100644 --- a/src/components/telemetry_monitor/test/CMakeLists.txt +++ b/src/components/telemetry_monitor/test/CMakeLists.txt @@ -74,4 +74,10 @@ endif() create_test("telemetry_monitor_test" "${SOURCES}" "${LIBRARIES}") -file(COPY ${COMPONENTS_DIR}/telemetry_monitor/test/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +if (${LOGGER_NAME} STREQUAL "LOG4CXX") + file(COPY ${COMPONENTS_DIR}/telemetry_monitor/test/log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() + +if (${LOGGER_NAME} STREQUAL "BOOST") + file(COPY ${COMPONENTS_DIR}/telemetry_monitor/test/boostlogconfig.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() diff --git a/src/components/telemetry_monitor/test/boostlogconfig.ini b/src/components/telemetry_monitor/test/boostlogconfig.ini new file mode 100644 index 00000000000..4ab6b6e473c --- /dev/null +++ b/src/components/telemetry_monitor/test/boostlogconfig.ini @@ -0,0 +1,22 @@ +# Core settings +[Core] +DisableLogging=false + +# Console Logging (Only ERROR and FATAL messages are logged to console) +[Sinks.Console] +DisableLogging=false +Destination=Console +Filter="%Severity% >= error" +Format="%Severity% [%TimeStamp%][%Component%] %Message%" +AutoFlush=true +Asynchronous=true + +# SDL log file +[Sinks.AllMessages] +DisableLogging=false +Destination=TextFile +FileName=SmartDeviceLinkCore.log +Append=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true diff --git a/src/components/test_main.cc b/src/components/test_main.cc index 62442cb64ff..55b1f96aeb0 100644 --- a/src/components/test_main.cc +++ b/src/components/test_main.cc @@ -3,7 +3,6 @@ #include "utils/custom_string.h" #ifdef ENABLE_LOG -#include "utils/logger/log4cxxlogger.h" #include "utils/logger/logger_impl.h" #endif // ENABLE_LOG @@ -15,8 +14,6 @@ int main(int argc, char** argv) { // -------------------------------------------------------------------------- // Logger initialization // Redefine for each paticular logger implementation - auto logger = std::unique_ptr( - new logger::Log4CXXLogger("log4cxx.properties")); auto logger_impl = std::unique_ptr(new logger::LoggerImpl(false)); logger::Logger::instance(logger_impl.get()); diff --git a/src/components/transport_manager/CMakeLists.txt b/src/components/transport_manager/CMakeLists.txt index 2086b37b526..eea719088f7 100644 --- a/src/components/transport_manager/CMakeLists.txt +++ b/src/components/transport_manager/CMakeLists.txt @@ -146,7 +146,7 @@ list(APPEND SOURCES ${PLATFORM_DEPENDENT_SOURCES}) add_library("TransportManager" ${SOURCES}) target_link_libraries("TransportManager" ${LIBRARIES}) -if(ENABLE_LOG) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") target_link_libraries("TransportManager" log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() diff --git a/src/components/utils/CMakeLists.txt b/src/components/utils/CMakeLists.txt index b65b19253a3..414500382c0 100644 --- a/src/components/utils/CMakeLists.txt +++ b/src/components/utils/CMakeLists.txt @@ -69,13 +69,19 @@ if(NOT BUILD_BACKTRACE_SUPPORT) ) endif() -if(ENABLE_LOG) - list(APPEND LIBRARIES - log4cxx -L${LOG4CXX_LIBS_DIRECTORY} - apr-1 -L${APR_LIBS_DIRECTORY} - aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY} - ConfigProfile - ) +if (ENABLE_LOG) + if (${LOGGER_NAME} STREQUAL "LOG4CXX") + list(APPEND LIBRARIES + log4cxx -L${LOG4CXX_LIBS_DIRECTORY} + apr-1 -L${APR_LIBS_DIRECTORY} + aprutil-1 -L${APR_UTIL_LIBS_DIRECTORY} + ConfigProfile + ) + else() + list(APPEND EXCLUDE_PATHS + logger/log4cxxlogger.cc + ) + endif() else() list(APPEND EXCLUDE_PATHS auto_trace.cc @@ -121,12 +127,21 @@ list(APPEND LIBRARIES boost_system -L${BOOST_LIBS_DIRECTORY}) list(APPEND LIBRARIES boost_thread -L${BOOST_LIBS_DIRECTORY}) list(APPEND LIBRARIES boost_date_time -L${BOOST_LIBS_DIRECTORY}) list(APPEND LIBRARIES boost_filesystem -L${BOOST_LIBS_DIRECTORY}) +if (ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "BOOST") + list(APPEND LIBRARIES boost_log_setup -L${BOOST_LIBS_DIRECTORY}) + list(APPEND LIBRARIES boost_log -L${BOOST_LIBS_DIRECTORY}) +endif () +list(APPEND LIBRARIES boost_regex -L${BOOST_LIBS_DIRECTORY}) target_link_libraries("Utils" ${LIBRARIES}) add_dependencies("Utils" Boost) if(ENABLE_LOG) - add_dependencies("Utils" install-3rd_party_logger Boost) + if (${LOGGER_NAME} STREQUAL "LOG4CXX") + add_dependencies("Utils" install-3rd_party_logger Boost) + else() + add_dependencies("Utils" Boost) + endif() endif() if(BUILD_TESTS) diff --git a/src/components/utils/include/utils/logger/boostlogger.h b/src/components/utils/include/utils/logger/boostlogger.h new file mode 100644 index 00000000000..b7eeb7ab61a --- /dev/null +++ b/src/components/utils/include/utils/logger/boostlogger.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#define BOOST_LOG_DYN_LINK 1 +#include +#include "utils/ilogger.h" + +namespace logger { + +class BoostLogger : public ThirdPartyLoggerInterface { + public: + BoostLogger(const std::string& filename); + void Init() override; + void DeInit() override; + bool IsEnabledFor(const std::string& component, + LogLevel log_level) const override; + void PushLog(const LogMessage& log_message) override; + + private: + boost::posix_time::ptime GetLocalPosixTime( + const logger::TimePoint& timestamp); + + std::string GetFilteredFunctionTrace( + const std::string& full_function_signature); + + std::string filename_; +}; + +} // namespace logger diff --git a/src/components/utils/src/logger/boostlogger.cc b/src/components/utils/src/logger/boostlogger.cc new file mode 100644 index 00000000000..c8429e03c67 --- /dev/null +++ b/src/components/utils/src/logger/boostlogger.cc @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2020, Livio + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "utils/logger/boostlogger.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace logger { + +namespace logging = boost::log; +namespace src = boost::log::sources; +namespace sinks = boost::log::sinks; +namespace keywords = boost::log::keywords; +namespace expr = boost::log::expressions; +namespace attrs = boost::log::attributes; + +BoostLogger::BoostLogger(const std::string& filename) : filename_(filename) {} + +void BoostLogger::Init() { + // Add formatting parameters to INI file + // Allows %Severity% to be used in ini config file for property Format. + boost::log::register_simple_formatter_factory< + boost::log::trivial::severity_level, + char>("Severity"); + boost::log::register_simple_formatter_factory("Component"); + boost::log::register_simple_formatter_factory( + "TimeStamp"); + boost::log::register_simple_formatter_factory( + "ThreadId"); + boost::log::register_simple_formatter_factory("FileName"); + boost::log::register_simple_formatter_factory("LineNum"); + boost::log::register_simple_formatter_factory("Trace"); + + // Add filter parameters to INI file + // Allows %Severity% to be used in ini config file for property Filter. + boost::log:: + register_simple_filter_factory( + "Severity"); + boost::log::register_simple_filter_factory("Component"); + boost::log::register_simple_filter_factory("Trace"); + + std::ifstream file(filename_); + boost::log::settings settings = boost::log::parse_settings(file); + + // Custom Settings + + if (settings.has_section("Sinks")) { + auto& sinks = settings.property_tree().get_child("Sinks"); + + for (auto it = sinks.begin(); it != sinks.end();) { + bool to_be_removed = false; + std::string sink_name = "Sinks." + it->first; + + // Disable logging for particular sinks + if (boost::optional param = + settings[sink_name]["DisableLogging"]) { + to_be_removed = (param.get() == "true"); + } + + if (to_be_removed) { + it = sinks.erase(it); + } else { + it++; + } + } + } + + logging::init_from_settings(settings); +} + +void BoostLogger::DeInit() { + logging::core::get()->remove_all_sinks(); +} + +logging::trivial::severity_level getBoostLogLevel(LogLevel log_level) { + switch (log_level) { + case LogLevel::TRACE_LEVEL: + return logging::trivial::severity_level::trace; + case LogLevel::DEBUG_LEVEL: + return logging::trivial::severity_level::debug; + case LogLevel::INFO_LEVEL: + return logging::trivial::severity_level::info; + case LogLevel::WARNING_LEVEL: + return logging::trivial::severity_level::warning; + case LogLevel::ERROR_LEVEL: + return logging::trivial::severity_level::error; + case LogLevel::FATAL_LEVEL: + return logging::trivial::severity_level::fatal; + default: + assert(false); + } +} + +boost::posix_time::ptime BoostLogger::GetLocalPosixTime( + const logger::TimePoint& timestamp) { + auto time = std::chrono::duration_cast( + timestamp.time_since_epoch()) + .count(); + + boost::posix_time::ptime time_epoch(boost::gregorian::date(1970, 1, 1)); + boost::posix_time::ptime utc_time = + time_epoch + boost::posix_time::microseconds(time); + + typedef boost::date_time::c_local_adjustor + local_adj; + auto local_time = local_adj::utc_to_local(utc_time); + + return local_time; +} + +std::string BoostLogger::GetFilteredFunctionTrace( + const std::string& full_function_signature) { + boost::regex function_pattern("([^\\s]*)\\((.*)\\)"); + boost::smatch results; + + if (!boost::regex_search( + full_function_signature, results, function_pattern)) { + // Invalid pattern + return std::string(full_function_signature); + } + + // Get the function name(including namespaces) from the function signature + return std::string(results[1]); +} + +bool BoostLogger::IsEnabledFor(const std::string& component, + LogLevel log_level) const { + // Basic filtering based on component name and log level is currently handled + // using the Filter attribute. This function should be implemented if we add + // custom attributes for filtering or additional logic for filtering based on + // component name and log level. + return true; +} + +void BoostLogger::PushLog(const LogMessage& log_message) { + auto local_time = GetLocalPosixTime(log_message.timestamp_); + std::string func_name = + GetFilteredFunctionTrace(log_message.location_.function_name); + + src::severity_logger slg; + slg.add_attribute("TimeStamp", + attrs::constant(local_time)); + slg.add_attribute("ThreadId", + attrs::constant(log_message.thread_id_)); + slg.add_attribute("Component", + attrs::constant(log_message.component_)); + slg.add_attribute( + "FileName", + attrs::constant(log_message.location_.file_name)); + slg.add_attribute("LineNum", + attrs::constant(log_message.location_.line_number)); + slg.add_attribute("Trace", attrs::constant(func_name)); + + BOOST_LOG_SEV(slg, getBoostLogLevel(log_message.log_level_)) + << log_message.log_event_; +} + +} // namespace logger diff --git a/src/components/utils/test/CMakeLists.txt b/src/components/utils/test/CMakeLists.txt index 2db7d72d840..c09d2d7ce6a 100644 --- a/src/components/utils/test/CMakeLists.txt +++ b/src/components/utils/test/CMakeLists.txt @@ -93,7 +93,12 @@ set(LIBRARIES create_test(utils_test "${SOURCES}" "${LIBRARIES}") file(COPY testscript.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -file(COPY log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +if (${LOGGER_NAME} STREQUAL "LOG4CXX") + file(COPY log4cxx.properties DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +else() + file(COPY boostlogconfig.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() + file(COPY smartDeviceLink.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(test_generator) diff --git a/src/components/utils/test/boostlogconfig.ini b/src/components/utils/test/boostlogconfig.ini new file mode 100644 index 00000000000..f33da81c930 --- /dev/null +++ b/src/components/utils/test/boostlogconfig.ini @@ -0,0 +1,51 @@ +# Core settings +[Core] +DisableLogging=false + +# Console Logging +[Sinks.Console] +DisableLogging=true +Destination=Console +Filter="%Severity% > trace" +Format="%Severity% [%TimeStamp%][%Component%] %Message%" +AutoFlush=true +Asynchronous=true + +# SDL log file +[Sinks.AllMessages] +DisableLogging=false +Destination=TextFile +FileName=SmartDeviceLinkCore.log +Append=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for all TransportManager messages +[Sinks.TransportManager] +DisableLogging=false +Destination=TextFile +FileName=TransportManager.log +Append=false +Filter="%Component% = TransportManager" +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +# Log file for handling Ford protocol info (include ProtocolHandler, ConnectionHandler, SecurityManager) +[Sinks.ProtocolFordHandling] +DisableLogging=false +Destination=TextFile +FileName=ProtocolFordHandling.log +Append=false +Filter="%Component% = ConnectionHandler or %Component% = HeartBeatMonitor or %Component% = ProtocolHandler or %Component% = SecurityManager" +Format="%Severity% [%TimeStamp%][%Component%] %Trace%: %Message%" +AutoFlush=true +Asynchronous=true + +[Sinks.Telnet] +DisableLogging=true +Destination=Syslog +Asynchronous=true +Format="%Severity% [%TimeStamp%][%ThreadId%][%Component%] %FileName%:%LineNum% %Trace%: %Message%" +LocalAddress="http://127.0.0.1:6676/" \ No newline at end of file diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 4b6f6d8dfa6..4b6bf180467 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -28,6 +28,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -if(ENABLE_LOG) +if(ENABLE_LOG AND ${LOGGER_NAME} STREQUAL "LOG4CXX") add_subdirectory(appenders) endif() diff --git a/src/plugins/appenders/CMakeLists.txt b/src/plugins/appenders/CMakeLists.txt index 3d18e625039..7ec235bece9 100644 --- a/src/plugins/appenders/CMakeLists.txt +++ b/src/plugins/appenders/CMakeLists.txt @@ -30,15 +30,19 @@ include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) +if (${LOGGER_NAME} STREQUAL "LOG4CXX") include_directories( ${LOG4CXX_INCLUDE_DIRECTORY} ) +endif() collect_sources(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}") +if (${LOGGER_NAME} STREQUAL "LOG4CXX") set(LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY} ) +endif() add_library(appenders SHARED ${SOURCES}) target_link_libraries(appenders ${LIBRARIES}) diff --git a/tools/policy_table_validator/main.cpp b/tools/policy_table_validator/main.cpp index 7e099c7ae1a..cc1318d215e 100644 --- a/tools/policy_table_validator/main.cpp +++ b/tools/policy_table_validator/main.cpp @@ -6,8 +6,13 @@ #include "utils/file_system.h" #ifdef ENABLE_LOG -#include "utils/logger/logger_impl.h" +#ifdef LOG4CXX_LOGGER #include "utils/logger/log4cxxlogger.h" +#else // LOG4CXX_LOGGER +#include "utils/logger/boostlogger.h" +#endif // LOG4CXX_LOGGER + +#include "utils/logger/logger_impl.h" #endif // ENABLE_LOG #include "utils/logger.h" @@ -55,7 +60,13 @@ int main(int argc, char** argv) { // -------------------------------------------------------------------------- // Logger initialization // Redefine for each paticular logger implementation - auto logger = std::unique_ptr(new logger::Log4CXXLogger("log4cxx.properties")); +#ifdef LOG4CXX_LOGGER + auto logger = std::unique_ptr( + new logger::Log4CXXLogger("log4cxx.properties")); +#else // LOG4CXX_LOGGER + auto logger = std::unique_ptr( + new logger::BoostLogger("boostlogconfig.ini")); +#endif // LOG4CXX_LOGGER auto logger_impl = std::unique_ptr(new logger::LoggerImpl()); logger::Logger::instance(logger_impl.get()); logger_impl->Init(std::move(logger));