Skip to content

Commit f49cc3e

Browse files
authored
Feature: Integrate spdlog as logging backend for Trantor Logger (#294)
1 parent dd133c7 commit f49cc3e

File tree

16 files changed

+1543
-32
lines changed

16 files changed

+1543
-32
lines changed

.github/workflows/cmake.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
working-directory: ./build
4545
run: |
4646
[[ ${{ matrix.link }} == "SHARED" ]] && shared="ON" || shared="OFF"
47-
cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=on -DBUILD_SHARED_LIBS=$shared -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
47+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=on -DUSE_SPDLOG=ON -DBUILD_SHARED_LIBS=$shared -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
4848
4949
- name: Build
5050
working-directory: ${{env.GITHUB_WORKSPACE}}
@@ -82,20 +82,20 @@ jobs:
8282
- name: (macOS) Install dependencies
8383
if: runner.os == 'macOS'
8484
run: |
85-
brew install c-ares openssl
85+
brew install c-ares openssl spdlog
8686
8787
- name: (Linux) Install dependencies - OpenSSL
8888
if: matrix.buildname == 'ubuntu-20.04/gcc - OpenSSL'
8989
run: |
9090
# Installing packages might fail as the github image becomes outdated
9191
sudo apt update
92-
sudo apt install openssl libssl-dev dos2unix
92+
sudo apt install openssl libssl-dev dos2unix libspdlog-dev libfmt-dev
9393
- name: (Linux) Install dependencies
9494
if: matrix.buildname == 'ubuntu-20.04/gcc'
9595
run: |
9696
# Installing packages might fail as the github image becomes outdated
9797
sudo apt update
98-
sudo apt install dos2unix
98+
sudo apt install dos2unix libspdlog-dev libfmt-dev
9999
- name: install gtest
100100
run: |
101101
wget https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz
@@ -113,7 +113,7 @@ jobs:
113113
run: |
114114
mkdir build
115115
cd build
116-
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_TESTING=on
116+
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_TESTING=on -DUSE_SPDLOG=ON
117117
118118
- name: Build
119119
working-directory: ${{env.GITHUB_WORKSPACE}}

CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ project(trantor)
33

44
option(BUILD_DOC "Build Doxygen documentation" OFF)
55
option(BUILD_C-ARES "Build C-ARES" ON)
6+
option(BUILD_TESTING "Build tests" OFF)
67
option(BUILD_SHARED_LIBS "Build trantor as a shared lib" OFF)
78
option(TRANTOR_USE_TLS "TLS provider for trantor. Valid options are 'openssl', 'botan' or '' (let the build scripr decide)" "")
9+
option(USE_SPDLOG "Allow using the spdlog logging library" OFF)
810

911
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
1012

@@ -45,6 +47,13 @@ if(BUILD_SHARED_LIBS)
4547
endif()
4648
endif(BUILD_SHARED_LIBS)
4749

50+
# Tells Visual Studio 2017 (15.7+) and newer to correctly set the value of the standard __cplusplus macro,
51+
# instead of leaving it to 199711L and settings the effective c++ version in _MSVC_LANG
52+
# Dropping support for older versions of VS would allow to only rely on __cplusplus
53+
if(MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
54+
add_compile_options(/Zc:__cplusplus)
55+
endif(MSVC)
56+
4857
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND CMAKE_CXX_COMPILER_ID MATCHES Clang|GNU)
4958
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)
5059
endif()
@@ -188,6 +197,19 @@ endif()
188197
message(STATUS "Trantor using SSL library: ${TRANTOR_TLS_PROVIDER}")
189198
target_compile_definitions(${PROJECT_NAME} PRIVATE TRANTOR_TLS_PROVIDER=${TRANTOR_TLS_PROVIDER})
190199

200+
set(HAVE_SPDLOG NO)
201+
if(USE_SPDLOG)
202+
find_package(spdlog CONFIG)
203+
if(spdlog_FOUND)
204+
message(STATUS "spdlog found!")
205+
set(HAVE_SPDLOG TRUE)
206+
endif(spdlog_FOUND)
207+
endif(USE_SPDLOG)
208+
if(HAVE_SPDLOG)
209+
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog_header_only)
210+
target_compile_definitions(${PROJECT_NAME} PUBLIC TRANTOR_SPDLOG_SUPPORT SPDLOG_FMT_EXTERNAL FMT_HEADER_ONLY)
211+
endif(HAVE_SPDLOG)
212+
191213
set(HAVE_C-ARES NO)
192214
if (BUILD_C-ARES)
193215
find_package(c-ares)
@@ -206,7 +228,9 @@ if(HAVE_C-ARES)
206228
${private_headers}
207229
trantor/net/inner/AresResolver.h)
208230
if(APPLE)
209-
target_link_libraries(${PROJECT_NAME} PRIVATE resolv)
231+
target_link_libraries(${PROJECT_NAME} PRIVATE resolv)
232+
elseif(WIN32)
233+
target_link_libraries(${PROJECT_NAME} PRIVATE Iphlpapi)
210234
endif()
211235
else()
212236
set(TRANTOR_SOURCES

ChangeLog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file.
2222

2323
- Fix an error when sending files.
2424

25-
- Include <memory> header in TcpConnectionImpl.cc.
25+
- Include &lt;memory&gt; header in TcpConnectionImpl.cc.
2626

2727
## [1.5.12] - 2023-08-20
2828

@@ -54,7 +54,7 @@ All notable changes to this project will be documented in this file.
5454

5555
- Fix override mark.
5656

57-
- Add missing <cstdint> header with GCC 13.
57+
- Add missing &lt;cstdint&gt; header with GCC 13.
5858

5959
- Fix AresResolver.
6060

cmake/templates/TrantorConfig.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ if(@c-ares_FOUND@)
2020
find_dependency(c-ares)
2121
endif()
2222
find_dependency(Threads)
23+
if(@spdlog_FOUND@)
24+
find_dependency(spdlog)
25+
endif()
2326
# Compute paths
2427

2528
# Our library dependencies (contains definitions for IMPORTED targets)

conanfile.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
gtest/1.10.0
33
openssl/1.1.1t
44
#c-ares/1.17.1
5+
spdlog/1.12.0
56

67
[generators]
78
CMakeToolchain

trantor/net/TcpClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class TRANTOR_EXPORT TcpClient : NonCopyable,
209209
* OpenSSL.
210210
* @param certPath The path of the certificate file.
211211
* @param keyPath The path of the private key file.
212+
* @param caPath The path of the certificate authority file.
212213
* @note It's well known that TLS 1.0 and 1.1 are not considered secure in
213214
* 2020. And it's a good practice to only use TLS 1.2 and above.
214215
*/

trantor/net/TcpConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class TRANTOR_EXPORT TcpConnection
125125
*/
126126
virtual bool disconnected() const = 0;
127127

128-
/**
128+
/* *
129129
* @brief Get the buffer in which the received data stored.
130130
*
131131
* @return MsgBuffer*

trantor/net/TcpServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class TRANTOR_EXPORT TcpServer : NonCopyable
240240
* server.
241241
* @param sslConfCmds The commands used to call the SSL_CONF_cmd function in
242242
* OpenSSL.
243+
* @param caPath The path of the certificate authority file.
243244
* @note It's well known that TLS 1.0 and 1.1 are not considered secure in
244245
* 2020. And it's a good practice to only use TLS 1.2 and above.
245246
*/

trantor/tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ set(targets_list
4848
delayed_ssl_server_test
4949
delayed_ssl_client_test)
5050

51+
if(HAVE_SPDLOG)
52+
add_executable(spdlogger_test SpdLoggerTest.cc)
53+
list(APPEND targets_list spdlogger_test)
54+
endif(HAVE_SPDLOG)
55+
5156
set_property(TARGET ${targets_list} PROPERTY CXX_STANDARD 14)
5257
set_property(TARGET ${targets_list} PROPERTY CXX_STANDARD_REQUIRED ON)
5358
set_property(TARGET ${targets_list} PROPERTY CXX_EXTENSIONS OFF)

0 commit comments

Comments
 (0)