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 13 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 "BOOST" CACHE STRING "Logging library to use (BOOST, LOG4CXX)")
set_property(CACHE LOGGER_NAME PROPERTY STRINGS BOOST LOG4CXX)
if(LOGGER_NAME STREQUAL "")
set(LOGGER_NAME "BOOST")
iCollin marked this conversation as resolved.
Show resolved Hide resolved
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
9 changes: 5 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 @@ -221,7 +221,8 @@ else()
endif()

set(BOOST_ROOT ${3RD_PARTY_INSTALL_PREFIX})
find_package(Boost 1.66.0 COMPONENTS system thread date_time filesystem regex)
find_package(Boost 1.66.0 COMPONENTS system thread date_time filesystem regex log log_setup)
iCollin marked this conversation as resolved.
Show resolved Hide resolved

set(BOOST_LIB_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost_src)
set(BOOST_LIBS_DIRECTORY ${3RD_PARTY_INSTALL_PREFIX}/lib)
set(BOOST_INCLUDE_DIR ${3RD_PARTY_INSTALL_PREFIX}/include PARENT_SCOPE)
Expand All @@ -239,9 +240,9 @@ if (NOT ${Boost_FOUND})
URL_HASH SHA256=da3411ea45622579d419bfda66f45cd0f8c32a181d84adfa936f5688388995cf
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=system,thread,date_time,filesystem,regex,log --prefix=${3RD_PARTY_INSTALL_PREFIX}
BUILD_COMMAND ./b2
INSTALL_COMMAND ${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} --with-system --with-thread --with-date_time --with-filesystem --with-regex --with-log --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log
INSTALL_DIR ${3RD_PARTY_INSTALL_PREFIX}
BUILD_IN_SOURCE true
)
Expand Down
12 changes: 9 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,13 @@ 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})
endif()
if (${LOGGER_NAME} STREQUAL "BOOST")
iCollin marked this conversation as resolved.
Show resolved Hide resolved
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 +223,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/"
17 changes: 16 additions & 1 deletion 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,17 +149,25 @@ 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"));
#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");

#ifdef LOG4CXX_LOGGER
if (!utils::appenders_loader.Loaded()) {
SDL_LOG_ERROR("Appenders plugin not loaded, file logging disabled");
}
#endif // LOG4CXX_LOGGER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this section causes the build to fail if ENABLE_LOG=OFF, maybe move it into the ENABLE_LOG ifdef?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 770ef06


SDL_LOG_INFO("Application started!");
SDL_LOG_INFO("SDL version: " << profile_instance.sdl_version());
Expand Down
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 @@ -62,7 +62,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
46 changes: 46 additions & 0 deletions src/components/policy/policy_external/test/boostlogconfig.ini
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/components/policy/policy_regular/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading