Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost Logger Implementation #3571

Merged
merged 21 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down
20 changes: 16 additions & 4 deletions src/3rd_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
)
Expand Down
11 changes: 8 additions & 3 deletions src/appMain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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})
Expand Down Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions src/appMain/boostlogconfig.ini
Original file line number Diff line number Diff line change
@@ -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)
iCollin marked this conversation as resolved.
Show resolved Hide resolved
[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/"
23 changes: 18 additions & 5 deletions src/appMain/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

Expand Down Expand Up @@ -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<logger::Log4CXXLogger>(
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<logger::BoostLogger>(
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());

Expand Down
1 change: 1 addition & 0 deletions src/appMain/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(testSources

set(LIBRARIES
gmock
SmartObjects
)

create_test(low_voltage_signals_handler_test "${testSources}" "${LIBRARIES}")
2 changes: 1 addition & 1 deletion src/components/application_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/components/application_manager/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion src/components/hmi_message_handler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/components/media_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/components/media_manager/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion src/components/policy/policy_external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading