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

Move logging backend to spdlog #23

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
30dcacf
WIP: use spdlog instead of Boost.Log
hikinggrass Aug 7, 2024
182d3eb
Initialize line with 0
hikinggrass Aug 7, 2024
1dd6462
Replace EVLOG_AND_THROW and EVTHROW macros with constrexpr functions
hikinggrass Aug 7, 2024
bda0c19
Address some clang-tidy issues
hikinggrass Aug 7, 2024
bd39374
Add LogSource operator<< to control file name, line number and functi…
hikinggrass Aug 8, 2024
362be38
Update example to showcase more features
hikinggrass Aug 8, 2024
8365d5b
Fix gtest integration, add some first unit tests, fix coverage genera…
hikinggrass Aug 9, 2024
6bfd5ed
Change Filter in example logging.ini to show the %Process% contains s…
hikinggrass Aug 12, 2024
6846122
Small log fix
hikinggrass Aug 12, 2024
8bd88f8
Fix is_level with and without %Process% contains
hikinggrass Aug 12, 2024
37e5b9c
Implement a (hopefully) Boost.Log TextFile settings compatible rotati…
hikinggrass Aug 12, 2024
ee92a57
Implement a simple Syslog sink
hikinggrass Aug 12, 2024
2133f3c
Correctly limit maximum number of files in log rotation
hikinggrass Aug 13, 2024
47aa3da
Respect file name and extension set in FileName when using default fo…
hikinggrass Aug 13, 2024
78ab778
Convert EVEREST_INTERNAL_LOG_AND_THROW into constexpr template function
hikinggrass Aug 13, 2024
5729b5d
Throw EverestConfigError when no sinks are configured
hikinggrass Aug 13, 2024
989eb46
Add unit tests for Console and TextFile sinks
hikinggrass Aug 13, 2024
c65ff9d
Set LOG_INSTALL to OFF in edm mode
hikinggrass Aug 13, 2024
db29554
Prefix coverage targets with PROJECT_NAME
hikinggrass Aug 13, 2024
e221a54
Add syslog smoketests
hikinggrass Aug 13, 2024
a4d8c2c
Add console defaults smoketest
hikinggrass Aug 13, 2024
be05d33
Add unit test for trace functionality
hikinggrass Aug 15, 2024
4922edb
Generate code coverage and upload gcovr coverage report as artifact
hikinggrass Aug 15, 2024
5e1ddc3
clang-format
hikinggrass Aug 15, 2024
c2bb124
Only set cmake_policy CMP0167 (FindBoost handling) in cmake >= 3.30
hikinggrass Aug 15, 2024
e40185a
install gcovr 6
hikinggrass Aug 15, 2024
4e876bb
Copy ctest-report and gcovr-coverage after install_and_test.sh for up…
hikinggrass Aug 15, 2024
7e12452
Attempt to fix path of gcovr output dir
hikinggrass Aug 15, 2024
84ab5a7
path fix
hikinggrass Aug 15, 2024
68294cd
revert last commit
hikinggrass Aug 15, 2024
213f21b
fix trap
hikinggrass Aug 15, 2024
0abde84
Rewrite trap
hikinggrass Aug 15, 2024
18280b8
ls build
hikinggrass Aug 15, 2024
8e6227d
Fix gcovr-coverage path
hikinggrass Aug 15, 2024
e390203
Fix usage of current_process_name
hikinggrass Aug 16, 2024
3d07bb9
Make ctors with one argument explicit
hikinggrass Aug 16, 2024
b4e088c
Fix get_process_name()
hikinggrass Aug 19, 2024
0175b70
Add RotateOnOpen option to TextFile sink
hikinggrass Aug 19, 2024
cfba2e3
Add test for a broken format string in TextFile FileName
hikinggrass Aug 19, 2024
501a003
Update CI
andistorm Sep 2, 2024
6a15995
github.token -> secrets.GITHUB_TOKEN
andistorm Sep 2, 2024
ee04556
Add trailing slash
andistorm Sep 2, 2024
7246769
Fix build dir path
andistorm Sep 2, 2024
ffb6ef1
Add missing newline
hikinggrass Sep 3, 2024
7e93da5
Remove redundant enable_testing()
hikinggrass Sep 3, 2024
eb62bb2
Move coverage targt setup to tests subdir
hikinggrass Sep 3, 2024
608bb48
Add gcovr coverage xml target
hikinggrass Sep 9, 2024
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
13 changes: 13 additions & 0 deletions .ci/build-kit/install_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

copy_logs() {
cp build/Testing/Temporary/LastTest.log /ext/ctest-report
cp -R build/everest-log_gcovr_coverage /ext/gcovr-coverage
}

cmake \
-B build \
-S "$EXT_MOUNT/source" \
Expand All @@ -12,4 +17,12 @@ cmake \

ninja -j$(nproc) -C build install

trap "copy_logs" ERR

ninja -j$(nproc) -C build test

pip install gcovr==6
andistorm marked this conversation as resolved.
Show resolved Hide resolved

ninja -j$(nproc) -C build everest-log_gcovr_coverage

copy_logs
11 changes: 8 additions & 3 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ jobs:
build-kit run-script install_and_test
- name: Archive test results
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ctest-report
path: /workspace/build/tests/Testing/Temporary/LastTest.log

path: ${{ github.workspace }}/ctest-report
- name: Archive coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: gcovr-coverage
path: ${{ github.workspace }}/gcovr-coverage
48 changes: 33 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)

project(everest-log
VERSION 0.2.1
VERSION 0.3
DESCRIPTION "EVerest logging library"
LANGUAGES CXX C
)
Expand All @@ -18,9 +18,27 @@ option(BUILD_EXAMPLES "Build liblog example binaries." OFF)
option(LOG_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
option(CMAKE_RUN_CLANG_TIDY "Run clang-tidy" OFF)
option(LIBLOG_USE_BOOST_FILESYSTEM "Usage of boost/filesystem.hpp instead of std::filesystem" OFF)
option(LIBLOG_OMIT_FILE_AND_LINE_NUMBERS "Always omit file and line numbers in logs" OFF)

# library dependencies
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
set(LIBLOG_BUILD_TESTING ON)
evc_include(CodeCoverage)

append_coverage_compiler_flags()
endif()

if(NOT DISABLE_EDM)
evc_setup_edm()

# In EDM mode, we can't install exports (because the dependencies usually do not install their exports)
set(LOG_INSTALL OFF)
endif()

# library dependencies
# use cmakes FindBoost module until we require Boost 1.70+ which provides its own BoostConfig.cmake
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.30")
cmake_policy(SET CMP0167 OLD)
endif()
if (LIBLOG_USE_BOOST_FILESYSTEM)
message(STATUS "Using boost/filesystem instead of std::filesystem")
find_package(Boost COMPONENTS log_setup log filesystem REQUIRED)
Expand Down Expand Up @@ -68,26 +86,26 @@ endif()


# testing
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
include(CTest)
add_subdirectory(tests)

if(LIBLOG_BUILD_TESTING)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)

evc_include(CodeCoverage)

append_coverage_compiler_flags()
include(CTest)
enable_testing()
hikinggrass marked this conversation as resolved.
Show resolved Hide resolved
add_subdirectory(tests)

setup_target_for_coverage_gcovr_html(
NAME gcovr_coverage_liblog
EXECUTABLE test_config
DEPENDENCIES test_config everest
NAME ${PROJECT_NAME}_gcovr_coverage
EXECUTABLE ctest
DEPENDENCIES ${PROJECT_NAME}_tests
EXCLUDE "examples/*"
)

setup_target_for_coverage_lcov(
NAME lcov_coverage_liblog
EXECUTABLE test_config
DEPENDENCIES test_config everest
NAME ${PROJECT_NAME}_lcov_coverage
EXECUTABLE ctest
DEPENDENCIES ${PROJECT_NAME}_tests
LCOV_ARGS "--ignore-errors=empty,missing"
EXCLUDE "examples/*"
)
hikinggrass marked this conversation as resolved.
Show resolved Hide resolved
else()
message("Not running unit tests")
Expand Down
14 changes: 14 additions & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
libfmt:
git: https://github.com/fmtlib/fmt.git
git_tag: 10.1.0
options:
["FMT_TEST OFF", "FMT_DOC OFF", "BUILD_SHARED_LIBS ON", "FMT_INSTALL ON"]
spdlog:
git: https://github.com/gabime/spdlog.git
git_tag: v1.14.1
options:
["SPDLOG_NO_TLS ON", "SPDLOG_FMT_EXTERNAL ON"]
gtest:
git: https://github.com/google/googletest.git
git_tag: release-1.12.1
cmake_condition: "LIBLOG_BUILD_TESTING"
hikinggrass marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 13 additions & 1 deletion examples/logging.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[Core]
DisableLogging=false
Filter="%Severity% >= DEBG"
Filter="(%Severity% >= VERB and %Process% contains EVerest)"

[Sinks.Console]
Destination=Console
Expand All @@ -16,3 +16,15 @@ SeverityStringColorInfo="\033[1;37m"
SeverityStringColorWarning="\033[1;33m"
SeverityStringColorError="\033[1;31m"
SeverityStringColorCritical="\033[1;35m"

[Sinks.TextFile]
Destination=TextFile
FileName="FileLog%5N.log"
Format = "%TimeStamp% [%Severity%] %Message%"
RotationSize = 500 # bytes
MaxFiles = 5

[Sinks.Syslog]
Destination=Syslog
Format="%TimeStamp% [%Severity%] %Message%"
EnableFormatting=false
44 changes: 42 additions & 2 deletions examples/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2021 Pionix GmbH and Contributors to EVerest
// Copyright Pionix GmbH and Contributors to EVerest
#include <everest/exceptions.hpp>
#include <everest/logging.hpp>

#include <iostream>
#include <thread>

#include <boost/exception/diagnostic_information.hpp>
#include <boost/program_options.hpp>

namespace po = boost::program_options;

struct TestStruct {
std::string hello;
int integer;
};

std::ostream& operator<<(std::ostream& os, const TestStruct& test) {
os << "TestStruct: hello " << test.hello << " " << test.integer;
return os;
}

int main(int argc, char* argv[]) {
po::options_description desc("EVerest::log example");
desc.add_options()("help,h", "produce help message");
Expand All @@ -28,7 +40,7 @@ int main(int argc, char* argv[]) {
if (vm.count("logconf") != 0) {
logging_config = vm["logconf"].as<std::string>();
}
Everest::Logging::init(logging_config, "hello there");
Everest::Logging::init(logging_config, "hello there. EVerest");

EVLOG_debug << "logging_config was set to " << logging_config;

Expand All @@ -39,5 +51,33 @@ int main(int argc, char* argv[]) {
EVLOG_error << "This is a ERROR message.";
EVLOG_critical << "This is a CRITICAL message.";

TestStruct test_struct{"there", 42};
EVLOG_info << "This logs a TestStruct using a operator<<: " << test_struct;
EVLOG_info << "Test logs with an additional std::endl at the end" << std::endl;
EVLOG_info << "Test logs with different types: " << 42 << " " << 12.34;

EVLOG_critical << Everest::Logging::LogSource("file.name", 42, "function_with_file_name_and_line_nr()")
<< "This is a CRITICAL message";
EVLOG_critical << Everest::Logging::LogSource("function_without_file_name_or_line_nr()")
<< "This is a CRITICAL message";

auto t = std::thread([]() { EVLOG_info << "From another thread"; });
t.join();

try {
EVTHROW(std::runtime_error("hello there"));

} catch (...) {
}
try {
EVLOG_AND_THROW(std::runtime_error("hello there"));

} catch (...) {
}
try {
EVTHROW(EVEXCEPTION(Everest::EverestInternalError, "Something", " with", " multiple", " args"));

} catch (...) {
}
return 0;
}
Loading
Loading