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

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 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
3 changes: 3 additions & 0 deletions .ci/build-kit/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# syntax=docker/dockerfile:1
ARG BASE_IMAGE_TAG=latest
FROM ghcr.io/everest/everest-ci/build-kit-base:${BASE_IMAGE_TAG}
15 changes: 0 additions & 15 deletions .ci/build-kit/install_and_test.sh

This file was deleted.

21 changes: 21 additions & 0 deletions .ci/build-kit/scripts/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

cmake \
-B "$EXT_MOUNT/build" \
-S "$EXT_MOUNT/source" \
-G Ninja \
-DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX="$EXT_MOUNT/dist"
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Configuring failed with return code $retVal"
exit $retVal
fi

ninja -C "$EXT_MOUNT/build"
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Compiling failed with return code $retVal"
exit $retVal
fi
9 changes: 9 additions & 0 deletions .ci/build-kit/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

ninja -C "$EXT_MOUNT/build" install
retVal=$?

if [ $retVal -ne 0 ]; then
echo "Installation failed with return code $retVal"
exit $retVal
fi
12 changes: 12 additions & 0 deletions .ci/build-kit/scripts/run_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

ninja -C "$EXT_MOUNT/build" everest-log_gcovr_coverage
retVal=$?

# Copy the generated coverage report to the mounted directory in any case
cp -R "$EXT_MOUNT/build/everest-log_gcovr_coverage" "$EXT_MOUNT/gcovr-coverage"

if [ $retVal -ne 0 ]; then
echo "Coverage failed with return code $retVal"
exit $retVal
fi
12 changes: 12 additions & 0 deletions .ci/build-kit/scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

ninja -C "$EXT_MOUNT/build" test
retVal=$?

# Copy the LastTest.log file to the mounted directory in any case
cp "$EXT_MOUNT/build/Testing/Temporary/LastTest.log" "$EXT_MOUNT/ctest-report"

if [ $retVal -ne 0 ]; then
echo "Unit tests failed with return code $retVal"
exit $retValUnitTests

Check warning on line 11 in .ci/build-kit/scripts/run_unit_tests.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.ci/build-kit/scripts/run_unit_tests.sh#L11

Double quote to prevent globbing and word splitting.
fi
110 changes: 93 additions & 17 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Please reference work here https://github.com/EVerest/everest-core/tree/main/.github/workflows
# TODO: modify to reuse the above workflow to DRY up CI.

name: Build and test liblog
name: Build, Lint and Test
on:
pull_request:
workflow_dispatch:
Expand All @@ -14,6 +11,13 @@ on:
options:
- 'ubuntu-22.04'
- 'large-ubuntu-22.04-xxl'
schedule:
- cron: '33 13,1 * * *'

env:
DOCKER_REGISTRY: ghcr.io
EVEREST_CI_VERSION: v1.3.1

jobs:
lint:
name: Lint
Expand All @@ -24,14 +28,53 @@ jobs:
with:
path: source
- name: Run clang-format
uses: everest/everest-ci/github-actions/run-clang-format@v1.1.0
uses: everest/everest-ci/github-actions/run-clang-format@v1.3.1
with:
source-dir: source
extensions: hpp,cpp
exclude: cache
install_and_test:
name: Install and test

# Since env variables can't be passed to reusable workflows, we need to pass them as outputs
setup-env:
name: Setup Environment
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
outputs:
docker_registry: ${{ env.DOCKER_REGISTRY }}
everest_ci_version: ${{ env.EVEREST_CI_VERSION }}
steps:
- id: check
run: |
echo "Setting up environment"

build-and-push-build-kit:
name: Build and Push Build Kit
uses: everest/everest-ci/.github/workflows/[email protected]
needs: setup-env
secrets:
SA_GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
SA_GITHUB_USERNAME: ${{ github.actor }}
permissions:
contents: read
packages: write
with:
image_name: ${{ github.event.repository.name }}/build-kit-${{ github.event.repository.name }}
directory: .ci/build-kit/docker
docker_registry: ${{ needs.setup-env.outputs.docker_registry }}
github_ref_before: ${{ github.event.before }}
github_ref_after: ${{ github.event.after }}
platforms: linux/amd64
depends_on_paths: |
.ci/build-kit
.github/workflows/build_and_test.yaml
build_args: |
BASE_IMAGE_TAG=${{ needs.setup-env.outputs.everest_ci_version }}

build:
name: Build and Unit Tests
needs: build-and-push-build-kit
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
env:
BUILD_KIT_IMAGE: ${{ needs.build-and-push-build-kit.outputs.one_image_tag_long }}
steps:
- name: Checkout liblog
uses: actions/checkout@v3
Expand All @@ -40,21 +83,54 @@ jobs:
- name: Setup run scripts
run: |
mkdir scripts
rsync -a source/.ci/build-kit/ scripts
rsync -a source/.ci/build-kit/scripts/ scripts
- name: Pull docker container
run: |
docker pull --platform=linux/x86_64 --quiet ghcr.io/everest/build-kit-alpine:latest
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
- name: Run install with tests
docker pull --platform=linux/x86_64 --quiet ${{ env.BUILD_KIT_IMAGE }}
docker image tag ${{ env.BUILD_KIT_IMAGE }} build-kit
- name: Compile
run: |
docker run \
--volume "${{ github.workspace }}:/ext" \
--name compile-container \
build-kit run-script compile
docker commit compile-container build-image
- name: Run unit tests
run: |
docker run \
--volume "$(pwd):/ext" \
--name test-container \
build-kit run-script install_and_test
--volume "${{ github.workspace }}:/ext" \
--name unit-test-container \
build-image run-script run_unit_tests
docker commit unit-test-container unit-test-image
- 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: Run coverage
run: |
docker run \
--volume "${{ github.workspace }}:/ext" \
--name coverage-container \
unit-test-image run-script run_coverage
- name: Archive coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: gcovr-coverage
path: ${{ github.workspace }}/gcovr-coverage
- name: Create dist
run: |
docker run \
--volume "${{ github.workspace }}:/ext" \
--name install-container \
build-image run-script install
- name: Tar dist dir and keep permissions
run: |
tar -czf dist.tar.gz dist
- name: Upload dist artifact
uses: actions/[email protected]
with:
path: dist.tar.gz
name: dist
44 changes: 23 additions & 21 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,27 +86,11 @@ 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()

setup_target_for_coverage_gcovr_html(
NAME gcovr_coverage_liblog
EXECUTABLE test_config
DEPENDENCIES test_config everest
)

setup_target_for_coverage_lcov(
NAME lcov_coverage_liblog
EXECUTABLE test_config
DEPENDENCIES test_config everest
)
include(CTest)
add_subdirectory(tests)
else()
message("Not running unit tests")
endif()
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"
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
Loading
Loading