mirror of
https://github.com/FairRootGroup/FairLogger.git
synced 2025-10-13 08:41:12 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
71aac1199a | ||
|
2a4be75246 | ||
|
290070cbcf | ||
|
832376101d | ||
|
cd9e392ce0 | ||
|
27527ad87b | ||
|
f3d68fb4ba |
85
.github/workflows/ci.yml
vendored
Normal file
85
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, dev ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master, dev ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
fedora: [38, 39, 40]
|
||||||
|
include:
|
||||||
|
- fedora: 38
|
||||||
|
gcc: 13
|
||||||
|
- fedora: 39
|
||||||
|
gcc: 13
|
||||||
|
- fedora: 40
|
||||||
|
gcc: 14
|
||||||
|
|
||||||
|
container: ghcr.io/fairrootgroup/fairmq-dev/fedora-${{ matrix.fedora }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install additional dependencies
|
||||||
|
run: |
|
||||||
|
dnf install -y fmt-devel || true
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: |
|
||||||
|
cmake -B build -G Ninja \
|
||||||
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
|
-DDISABLE_COLOR=ON \
|
||||||
|
-DUSE_EXTERNAL_FMT=ON \
|
||||||
|
-DUSE_BOOST_PRETTY_FUNCTION=ON
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
cd build
|
||||||
|
ctest -V --output-on-failure
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [macos-13, macos-14, macos-15]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Cache Homebrew packages
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/Library/Caches/Homebrew
|
||||||
|
/usr/local/Homebrew/Library/Taps
|
||||||
|
key: ${{ runner.os }}-${{ matrix.os }}-brew-${{ hashFiles('.github/workflows/ci.yml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-${{ matrix.os }}-brew-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
brew install cmake ninja boost fmt
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: |
|
||||||
|
cmake -B build -G Ninja \
|
||||||
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
|
-DDISABLE_COLOR=ON \
|
||||||
|
-DUSE_EXTERNAL_FMT=ON \
|
||||||
|
-DUSE_BOOST_PRETTY_FUNCTION=ON
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
cd build
|
||||||
|
ctest -V --output-on-failure
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
build/
|
build/
|
||||||
.vscode
|
.vscode
|
||||||
|
install/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
# Copyright (C) 2018-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||||
# #
|
# #
|
||||||
# This software is distributed under the terms of the #
|
# This software is distributed under the terms of the #
|
||||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.9.4 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.9.4 FATAL_ERROR)
|
||||||
cmake_policy(VERSION 3.9...3.19)
|
cmake_policy(VERSION 3.9...3.30)
|
||||||
|
|
||||||
# Project ######################################################################
|
# Project ######################################################################
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||||
|
@ -16,7 +16,7 @@ include(FairFindPackage2)
|
||||||
|
|
||||||
get_git_version()
|
get_git_version()
|
||||||
|
|
||||||
project(FairLogger VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
|
project(FairLogger VERSION ${PROJECT_VERSION} LANGUAGES CXX)
|
||||||
message(STATUS "${BWhite}${PROJECT_NAME}${CR} ${PROJECT_GIT_VERSION} from ${PROJECT_DATE}")
|
message(STATUS "${BWhite}${PROJECT_NAME}${CR} ${PROJECT_GIT_VERSION} from ${PROJECT_DATE}")
|
||||||
|
|
||||||
set_fairlogger_defaults()
|
set_fairlogger_defaults()
|
||||||
|
|
|
@ -15,14 +15,10 @@ set(CTEST_USE_LAUNCHERS ON)
|
||||||
set(CTEST_CONFIGURATION_TYPE "RelWithDebInfo")
|
set(CTEST_CONFIGURATION_TYPE "RelWithDebInfo")
|
||||||
|
|
||||||
if(NOT NCPUS)
|
if(NOT NCPUS)
|
||||||
if(ENV{SLURM_CPUS_PER_TASK})
|
include(ProcessorCount)
|
||||||
set(NCPUS $ENV{SLURM_CPUS_PER_TASK})
|
ProcessorCount(NCPUS)
|
||||||
else()
|
if(NCPUS EQUAL 0)
|
||||||
include(ProcessorCount)
|
set(NCPUS 1)
|
||||||
ProcessorCount(NCPUS)
|
|
||||||
if(NCPUS EQUAL 0)
|
|
||||||
set(NCPUS 1)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -32,10 +28,10 @@ else()
|
||||||
set(CTEST_SITE $ENV{CTEST_SITE})
|
set(CTEST_SITE $ENV{CTEST_SITE})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if ("$ENV{LABEL}" STREQUAL "")
|
if ("$ENV{CTEST_BUILD_NAME}" STREQUAL "")
|
||||||
set(CTEST_BUILD_NAME "build")
|
set(CTEST_BUILD_NAME "build")
|
||||||
else()
|
else()
|
||||||
set(CTEST_BUILD_NAME $ENV{LABEL})
|
set(CTEST_BUILD_NAME $ENV{CTEST_BUILD_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
ctest_start(Continuous)
|
ctest_start(Continuous)
|
||||||
|
|
80
Jenkinsfile
vendored
80
Jenkinsfile
vendored
|
@ -1,80 +0,0 @@
|
||||||
#!groovy
|
|
||||||
|
|
||||||
def jobMatrix(String prefix, String type, List specs) {
|
|
||||||
def nodes = [:]
|
|
||||||
for (spec in specs) {
|
|
||||||
job = "${spec.os}-${spec.ver}-${spec.arch}-${spec.compiler}"
|
|
||||||
def label = "${type}/${job}"
|
|
||||||
def selector = "${spec.os}-${spec.ver}-${spec.arch}"
|
|
||||||
def os = spec.os
|
|
||||||
def ver = spec.ver
|
|
||||||
def check = spec.check
|
|
||||||
|
|
||||||
nodes[label] = {
|
|
||||||
node(selector) {
|
|
||||||
githubNotify(context: "${prefix}/${label}", description: 'Building ...', status: 'PENDING')
|
|
||||||
try {
|
|
||||||
deleteDir()
|
|
||||||
checkout scm
|
|
||||||
|
|
||||||
def jobscript = 'job.sh'
|
|
||||||
def ctestcmd = "ctest -S FairLoggerTest.cmake -V --output-on-failure"
|
|
||||||
sh "echo \"set -e\" >> ${jobscript}"
|
|
||||||
sh "echo \"export LABEL=\\\"\${JOB_BASE_NAME} ${label}\\\"\" >> ${jobscript}"
|
|
||||||
if (selector =~ /^macos/) {
|
|
||||||
sh "echo \"${ctestcmd}\" >> ${jobscript}"
|
|
||||||
sh "cat ${jobscript}"
|
|
||||||
sh "bash ${jobscript}"
|
|
||||||
} else {
|
|
||||||
def containercmd = "singularity exec -B/shared ${env.SINGULARITY_CONTAINER_ROOT}/fairlogger/${os}.${ver}.sif bash -l -c \\\"${ctestcmd}\\\""
|
|
||||||
sh """\
|
|
||||||
echo \"echo \\\"*** Job started at .......: \\\$(date -R)\\\"\" >> ${jobscript}
|
|
||||||
echo \"echo \\\"*** Job ID ...............: \\\${SLURM_JOB_ID}\\\"\" >> ${jobscript}
|
|
||||||
echo \"echo \\\"*** Compute node .........: \\\$(hostname -f)\\\"\" >> ${jobscript}
|
|
||||||
echo \"unset http_proxy\" >> ${jobscript}
|
|
||||||
echo \"unset HTTP_PROXY\" >> ${jobscript}
|
|
||||||
echo \"${containercmd}\" >> ${jobscript}
|
|
||||||
"""
|
|
||||||
sh "cat ${jobscript}"
|
|
||||||
sh "test/ci/slurm-submit.sh \"FairLogger \${JOB_BASE_NAME} ${label}\" ${jobscript}"
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteDir()
|
|
||||||
githubNotify(context: "${prefix}/${label}", description: 'Success', status: 'SUCCESS')
|
|
||||||
} catch (e) {
|
|
||||||
deleteDir()
|
|
||||||
githubNotify(context: "${prefix}/${label}", description: 'Error', status: 'ERROR')
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodes
|
|
||||||
}
|
|
||||||
|
|
||||||
pipeline{
|
|
||||||
agent none
|
|
||||||
stages {
|
|
||||||
stage("Run CI Matrix") {
|
|
||||||
steps{
|
|
||||||
script {
|
|
||||||
def builds = jobMatrix('alfa-ci', 'build', [
|
|
||||||
[os: 'fedora', ver: '32', arch: 'x86_64', compiler: 'gcc-10'],
|
|
||||||
[os: 'fedora', ver: '33', arch: 'x86_64', compiler: 'gcc-10'],
|
|
||||||
[os: 'fedora', ver: '34', arch: 'x86_64', compiler: 'gcc-11'],
|
|
||||||
[os: 'fedora', ver: '35', arch: 'x86_64', compiler: 'gcc-11'],
|
|
||||||
[os: 'fedora', ver: '36', arch: 'x86_64', compiler: 'gcc-12'],
|
|
||||||
[os: 'fedora', ver: '37', arch: 'x86_64', compiler: 'gcc-12'],
|
|
||||||
[os: 'fedora', ver: '38', arch: 'x86_64', compiler: 'gcc-13'],
|
|
||||||
[os: 'fedora', ver: '39', arch: 'x86_64', compiler: 'gcc-13'],
|
|
||||||
[os: 'macos', ver: '13', arch: 'x86_64', compiler: 'apple-clang-15'],
|
|
||||||
[os: 'macos', ver: '14', arch: 'x86_64', compiler: 'apple-clang-15'],
|
|
||||||
[os: 'macos', ver: '14', arch: 'arm64', compiler: 'apple-clang-15'],
|
|
||||||
])
|
|
||||||
|
|
||||||
parallel(builds)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -68,9 +68,11 @@ A number of additional logging macros are provided:
|
||||||
- `LOGV(severity, verbosity)` Log the line with the provided verbosity, e.g. `LOG(info, veryhigh) << "abcd";`
|
- `LOGV(severity, verbosity)` Log the line with the provided verbosity, e.g. `LOG(info, veryhigh) << "abcd";`
|
||||||
- `LOGF(severity, ...)` The arguments are given to `fmt::printf`, which formats the string using a [printf syntax](https://fmt.dev/dev/api.html#printf-formatting) and the result is logged, e.g. `LOGF(info, "Hello %s!", "world");`
|
- `LOGF(severity, ...)` The arguments are given to `fmt::printf`, which formats the string using a [printf syntax](https://fmt.dev/dev/api.html#printf-formatting) and the result is logged, e.g. `LOGF(info, "Hello %s!", "world");`
|
||||||
- `LOGP(severity, ...)` The arguments are given to `fmt::format`, which formats the string using a [Python-like syntax](https://fmt.dev/dev/syntax.html) and the result is logged, e.g. `LOGP(info, "Hello {}!", "world");`
|
- `LOGP(severity, ...)` The arguments are given to `fmt::format`, which formats the string using a [Python-like syntax](https://fmt.dev/dev/syntax.html) and the result is logged, e.g. `LOGP(info, "Hello {}!", "world");`
|
||||||
|
- `LOGPD(severity, ...)` Same as `LOGP`, but accepts dynamic severity (runtime variable), e.g. `LOGPD(dynamicSeverity, "Hello {}!", "world");`
|
||||||
|
- `LOGFD(severity, ...)` Same as `LOGF`, but accepts dynamic severity (runtime variable), e.g. `LOGFD(dynamicSeverity, "Hello %s!", "world");`
|
||||||
- `LOGN(severity)` Logs an empty line, e.g. `LOGN(info);`
|
- `LOGN(severity)` Logs an empty line, e.g. `LOGN(info);`
|
||||||
- `LOG_IF(severity, condition)` Logs the line if the provided condition if true
|
- `LOG_IF(severity, condition)` Logs the line if the provided condition if true
|
||||||
- `LOGD(severity, file, line, f)` Logs the line with the provided file, line and function parameters (only if the active verbosity allows it).
|
- `LOGD(severity, file, line, f)` Logs the line with the provided file, line and function parameters (accepts severity as a variable), e.g. `LOGD(dynamicSeverity, "main.cpp", "42", "main");`
|
||||||
|
|
||||||
## 3. Severity
|
## 3. Severity
|
||||||
|
|
||||||
|
@ -100,6 +102,7 @@ where severity level is one of the following:
|
||||||
"important",
|
"important",
|
||||||
"alarm",
|
"alarm",
|
||||||
"error",
|
"error",
|
||||||
|
"critical",
|
||||||
"fatal",
|
"fatal",
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -223,7 +226,7 @@ If only output from custom sinks is desirable, console/file sinks must be deacti
|
||||||
|
|
||||||
## Naming conflicts?
|
## Naming conflicts?
|
||||||
|
|
||||||
By default, `<fairlogger/Logger.h>` defines unprefixed macros: `LOG`, `LOGV`, `LOGF`, `LOGP`, `LOGN`, `LOGD`, `LOG_IF`.
|
By default, `<fairlogger/Logger.h>` defines unprefixed macros: `LOG`, `LOGV`, `LOGF`, `LOGP`, `LOGPD`, `LOGFD`, `LOGN`, `LOGD`, `LOG_IF`.
|
||||||
|
|
||||||
Define an option `FAIR_NO_LOG*` to prevent the above unprefixed macros to be defined, e.g.
|
Define an option `FAIR_NO_LOG*` to prevent the above unprefixed macros to be defined, e.g.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -69,6 +69,7 @@ const unordered_map<string_view, Severity> Logger::fSeverityMap =
|
||||||
{ {"NOLOG"}, Severity::nolog },
|
{ {"NOLOG"}, Severity::nolog },
|
||||||
{ {"fatal"}, Severity::fatal },
|
{ {"fatal"}, Severity::fatal },
|
||||||
{ {"FATAL"}, Severity::fatal },
|
{ {"FATAL"}, Severity::fatal },
|
||||||
|
{ {"critical"}, Severity::critical },
|
||||||
{ {"error"}, Severity::error },
|
{ {"error"}, Severity::error },
|
||||||
{ {"ERROR"}, Severity::error },
|
{ {"ERROR"}, Severity::error },
|
||||||
{ {"alarm"}, Severity::alarm },
|
{ {"alarm"}, Severity::alarm },
|
||||||
|
@ -96,7 +97,7 @@ const unordered_map<string_view, Severity> Logger::fSeverityMap =
|
||||||
{ {"TRACE"}, Severity::trace }
|
{ {"TRACE"}, Severity::trace }
|
||||||
};
|
};
|
||||||
|
|
||||||
const array<string_view, 15> Logger::fSeverityNames =
|
const array<string_view, 16> Logger::fSeverityNames =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"NOLOG",
|
"NOLOG",
|
||||||
|
@ -113,6 +114,7 @@ const array<string_view, 15> Logger::fSeverityNames =
|
||||||
"IMPORTANT",
|
"IMPORTANT",
|
||||||
"ALARM",
|
"ALARM",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
|
"CRITICAL",
|
||||||
"FATAL"
|
"FATAL"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -289,6 +291,7 @@ string Logger::GetColoredSeverityString(Severity severity)
|
||||||
switch (severity) {
|
switch (severity) {
|
||||||
case Severity::nolog: return "\033[01;39mNOLOG\033[0m"; break;
|
case Severity::nolog: return "\033[01;39mNOLOG\033[0m"; break;
|
||||||
case Severity::fatal: return "\033[01;31mFATAL\033[0m"; break;
|
case Severity::fatal: return "\033[01;31mFATAL\033[0m"; break;
|
||||||
|
case Severity::critical: return "\033[01;31mCRITICAL\033[0m"; break;
|
||||||
case Severity::error: return "\033[01;31mERROR\033[0m"; break;
|
case Severity::error: return "\033[01;31mERROR\033[0m"; break;
|
||||||
case Severity::alarm: return "\033[01;33mALARM\033[0m"; break;
|
case Severity::alarm: return "\033[01;33mALARM\033[0m"; break;
|
||||||
case Severity::important: return "\033[01;32mIMPORTANT\033[0m"; break;
|
case Severity::important: return "\033[01;32mIMPORTANT\033[0m"; break;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2014-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2014-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -67,7 +67,8 @@ enum class Severity : int
|
||||||
important = 11,
|
important = 11,
|
||||||
alarm = 12,
|
alarm = 12,
|
||||||
error = 13,
|
error = 13,
|
||||||
fatal = 14,
|
critical = 14,
|
||||||
|
fatal = 15,
|
||||||
// aliases
|
// aliases
|
||||||
warning = warn,
|
warning = warn,
|
||||||
// backwards-compatibility
|
// backwards-compatibility
|
||||||
|
@ -325,7 +326,7 @@ class Logger
|
||||||
|
|
||||||
static const std::unordered_map<std::string_view, Verbosity> fVerbosityMap;
|
static const std::unordered_map<std::string_view, Verbosity> fVerbosityMap;
|
||||||
static const std::unordered_map<std::string_view, Severity> fSeverityMap;
|
static const std::unordered_map<std::string_view, Severity> fSeverityMap;
|
||||||
static const std::array<std::string_view, 15> fSeverityNames;
|
static const std::array<std::string_view, 16> fSeverityNames;
|
||||||
static const std::array<std::string_view, 9> fVerbosityNames;
|
static const std::array<std::string_view, 9> fVerbosityNames;
|
||||||
|
|
||||||
// protection for use after static destruction took place
|
// protection for use after static destruction took place
|
||||||
|
@ -393,16 +394,16 @@ inline std::ostream& operator<<(std::ostream& os, const Verbosity& v) { return o
|
||||||
#undef LOGV
|
#undef LOGV
|
||||||
#define LOGV FAIR_LOGV
|
#define LOGV FAIR_LOGV
|
||||||
#endif
|
#endif
|
||||||
// allow user of this header file to prevent definition of the LOGF macro, by defining FAIR_NO_LOGF before including this header
|
|
||||||
#ifndef FAIR_NO_LOGF
|
|
||||||
#undef LOGF
|
|
||||||
#define LOGF FAIR_LOGF
|
|
||||||
#endif
|
|
||||||
// allow user of this header file to prevent definition of the LOGP macro, by defining FAIR_NO_LOGP before including this header
|
// allow user of this header file to prevent definition of the LOGP macro, by defining FAIR_NO_LOGP before including this header
|
||||||
#ifndef FAIR_NO_LOGP
|
#ifndef FAIR_NO_LOGP
|
||||||
#undef LOGP
|
#undef LOGP
|
||||||
#define LOGP FAIR_LOGP
|
#define LOGP FAIR_LOGP
|
||||||
#endif
|
#endif
|
||||||
|
// allow user of this header file to prevent definition of the LOGF macro, by defining FAIR_NO_LOGF before including this header
|
||||||
|
#ifndef FAIR_NO_LOGF
|
||||||
|
#undef LOGF
|
||||||
|
#define LOGF FAIR_LOGF
|
||||||
|
#endif
|
||||||
// allow user of this header file to prevent definition of the LOGN macro, by defining FAIR_NO_LOGN before including this header
|
// allow user of this header file to prevent definition of the LOGN macro, by defining FAIR_NO_LOGN before including this header
|
||||||
#ifndef FAIR_NO_LOGN
|
#ifndef FAIR_NO_LOGN
|
||||||
#undef LOGN
|
#undef LOGN
|
||||||
|
@ -418,6 +419,16 @@ inline std::ostream& operator<<(std::ostream& os, const Verbosity& v) { return o
|
||||||
#undef LOG_IF
|
#undef LOG_IF
|
||||||
#define LOG_IF FAIR_LOG_IF
|
#define LOG_IF FAIR_LOG_IF
|
||||||
#endif
|
#endif
|
||||||
|
// allow user of this header file to prevent definition of the LOGPD macro, by defining FAIR_NO_LOGPD before including this header
|
||||||
|
#ifndef FAIR_NO_LOGPD
|
||||||
|
#undef LOGPD
|
||||||
|
#define LOGPD FAIR_LOGPD
|
||||||
|
#endif
|
||||||
|
// allow user of this header file to prevent definition of the LOGFD macro, by defining FAIR_NO_LOGFD before including this header
|
||||||
|
#ifndef FAIR_NO_LOGFD
|
||||||
|
#undef LOGFD
|
||||||
|
#define LOGFD FAIR_LOGFD
|
||||||
|
#endif
|
||||||
|
|
||||||
// Log line if the provided severity is below or equals the configured one
|
// Log line if the provided severity is below or equals the configured one
|
||||||
#define FAIR_LOG(severity) \
|
#define FAIR_LOG(severity) \
|
||||||
|
@ -432,8 +443,19 @@ inline std::ostream& operator<<(std::ostream& os, const Verbosity& v) { return o
|
||||||
fair::Logger(fair::Severity::severity, fair::Verbosity::verbosity, MSG_ORIGIN)
|
fair::Logger(fair::Severity::severity, fair::Verbosity::verbosity, MSG_ORIGIN)
|
||||||
|
|
||||||
// Log with fmt- or printf-like formatting
|
// Log with fmt- or printf-like formatting
|
||||||
#define FAIR_LOGP(severity, ...) LOG(severity) << fmt::format(__VA_ARGS__)
|
#define FAIR_LOGP(severity, ...) FAIR_LOG(severity) << fmt::format(__VA_ARGS__)
|
||||||
#define FAIR_LOGF(severity, ...) LOG(severity) << fmt::sprintf(__VA_ARGS__)
|
#define FAIR_LOGF(severity, ...) FAIR_LOG(severity) << fmt::sprintf(__VA_ARGS__)
|
||||||
|
|
||||||
|
// Log with fmt- or printf-like formatting (dynamic severity)
|
||||||
|
#define FAIR_LOGPD(severity, ...) \
|
||||||
|
for (bool fairLOggerunLikelyvariable3 = false; !fair::Logger::SuppressSeverity(severity) && !fairLOggerunLikelyvariable3; fairLOggerunLikelyvariable3 = true) \
|
||||||
|
for (bool fairLOggerunLikelyvariable = false; fair::Logger::Logging(severity) && !fairLOggerunLikelyvariable; fairLOggerunLikelyvariable = true) \
|
||||||
|
fair::Logger(severity, MSG_ORIGIN) << fmt::format(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define FAIR_LOGFD(severity, ...) \
|
||||||
|
for (bool fairLOggerunLikelyvariable3 = false; !fair::Logger::SuppressSeverity(severity) && !fairLOggerunLikelyvariable3; fairLOggerunLikelyvariable3 = true) \
|
||||||
|
for (bool fairLOggerunLikelyvariable = false; fair::Logger::Logging(severity) && !fairLOggerunLikelyvariable; fairLOggerunLikelyvariable = true) \
|
||||||
|
fair::Logger(severity, MSG_ORIGIN) << fmt::sprintf(__VA_ARGS__)
|
||||||
|
|
||||||
// Log an empty line
|
// Log an empty line
|
||||||
#define FAIR_LOGN(severity) \
|
#define FAIR_LOGN(severity) \
|
||||||
|
@ -450,6 +472,6 @@ inline std::ostream& operator<<(std::ostream& os, const Verbosity& v) { return o
|
||||||
#define FAIR_LOG_IF(severity, condition) \
|
#define FAIR_LOG_IF(severity, condition) \
|
||||||
for (bool fairLOggerunLikelyvariable4 = false; !fair::Logger::SuppressSeverity(fair::Severity::severity) && !fairLOggerunLikelyvariable4; fairLOggerunLikelyvariable4 = true) \
|
for (bool fairLOggerunLikelyvariable4 = false; !fair::Logger::SuppressSeverity(fair::Severity::severity) && !fairLOggerunLikelyvariable4; fairLOggerunLikelyvariable4 = true) \
|
||||||
for (bool fairLOggerunLikelyvariable2 = false; condition && !fairLOggerunLikelyvariable2; fairLOggerunLikelyvariable2 = true) \
|
for (bool fairLOggerunLikelyvariable2 = false; condition && !fairLOggerunLikelyvariable2; fairLOggerunLikelyvariable2 = true) \
|
||||||
LOG(severity)
|
FAIR_LOG(severity)
|
||||||
|
|
||||||
#endif // FAIR_LOGGER_H
|
#endif // FAIR_LOGGER_H
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2015-2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2015-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -38,7 +38,7 @@ int main()
|
||||||
Logger::SetConsoleSeverity(Severity::fatal);
|
Logger::SetConsoleSeverity(Severity::fatal);
|
||||||
cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl;
|
cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl;
|
||||||
|
|
||||||
array<Severity, 15> severitiesUp{{ Severity::nolog, Severity::trace, Severity::debug4, Severity::debug3, Severity::debug2, Severity::debug1, Severity::debug, Severity::detail, Severity::info, Severity::state, Severity::warn, Severity::important, Severity::alarm, Severity::error, Severity::fatal }};
|
array<Severity, 16> severitiesUp{{ Severity::nolog, Severity::trace, Severity::debug4, Severity::debug3, Severity::debug2, Severity::debug1, Severity::debug, Severity::detail, Severity::info, Severity::state, Severity::warn, Severity::important, Severity::alarm, Severity::error, Severity::critical, Severity::fatal }};
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
#ifdef FAIR_MIN_SEVERITY
|
||||||
for (unsigned int i = static_cast<int>(Severity::FAIR_MIN_SEVERITY); i < severitiesUp.size(); ++i) {
|
for (unsigned int i = static_cast<int>(Severity::FAIR_MIN_SEVERITY); i < severitiesUp.size(); ++i) {
|
||||||
#else
|
#else
|
||||||
|
@ -57,7 +57,7 @@ int main()
|
||||||
Logger::SetConsoleSeverity(Severity::fatal);
|
Logger::SetConsoleSeverity(Severity::fatal);
|
||||||
cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl;
|
cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl;
|
||||||
|
|
||||||
array<Severity, 15> severitiesDown{{ Severity::error, Severity::alarm, Severity::important, Severity::warn, Severity::state, Severity::info, Severity::detail, Severity::debug, Severity::debug1, Severity::debug2, Severity::debug3, Severity::debug4, Severity::trace, Severity::nolog, Severity::fatal }};
|
array<Severity, 16> severitiesDown{{ Severity::critical, Severity::error, Severity::alarm, Severity::important, Severity::warn, Severity::state, Severity::info, Severity::detail, Severity::debug, Severity::debug1, Severity::debug2, Severity::debug3, Severity::debug4, Severity::trace, Severity::nolog, Severity::fatal }};
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
#ifdef FAIR_MIN_SEVERITY
|
||||||
for (unsigned int i = 0; i < severitiesDown.size() - static_cast<int>(Severity::FAIR_MIN_SEVERITY) - 1; ++i) {
|
for (unsigned int i = 0; i < severitiesDown.size() - static_cast<int>(Severity::FAIR_MIN_SEVERITY) - 1; ++i) {
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -31,6 +31,7 @@ void printEverySeverity()
|
||||||
LOG(important) << "important message, counter: " << i++;
|
LOG(important) << "important message, counter: " << i++;
|
||||||
LOG(alarm) << "alarm message, counter: " << i++;
|
LOG(alarm) << "alarm message, counter: " << i++;
|
||||||
LOG(error) << "error message, counter: " << i++;
|
LOG(error) << "error message, counter: " << i++;
|
||||||
|
LOG(critical) << "critical message, counter: " << i++;
|
||||||
LOG(fatal) << "fatal message, counter: " << i++;
|
LOG(fatal) << "fatal message, counter: " << i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,13 @@ int main()
|
||||||
CheckOutput(ToStr(R"(^\[.*\]\[\d{2}:\d{2}:\d{2}\.\d{6}\]\[FATAL\]\[a:4:b\])", " c\n$"), []() {
|
CheckOutput(ToStr(R"(^\[.*\]\[\d{2}:\d{2}:\d{2}\.\d{6}\]\[FATAL\]\[a:4:b\])", " c\n$"), []() {
|
||||||
LOGD(Severity::fatal, "a", "4", "b") << "c";
|
LOGD(Severity::fatal, "a", "4", "b") << "c";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test dynamic severity macros
|
||||||
|
Logger::SetVerbosity(Verbosity::verylow);
|
||||||
|
Severity dynamicSeverity = Severity::fatal;
|
||||||
|
|
||||||
|
CheckOutput("^Hello dynamic world :-\\)!\n$", [&]() { LOGPD(dynamicSeverity, "Hello {} {}!", "dynamic world", ":-)"); });
|
||||||
|
CheckOutput("^Hello dynamic world :-\\)!\n$", [&]() { LOGFD(dynamicSeverity, "Hello %s %s!", "dynamic world", ":-)"); });
|
||||||
} catch (runtime_error& rte) {
|
} catch (runtime_error& rte) {
|
||||||
cout << rte.what() << endl;
|
cout << rte.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -27,6 +27,7 @@ void printEverySeverity()
|
||||||
LOG(important) << "important message ";
|
LOG(important) << "important message ";
|
||||||
LOG(alarm) << "alarm message ";
|
LOG(alarm) << "alarm message ";
|
||||||
LOG(error) << "error message ";
|
LOG(error) << "error message ";
|
||||||
|
LOG(critical) << "critical message ";
|
||||||
}
|
}
|
||||||
|
|
||||||
void silentlyPrintAllVerbositiesWithSeverity(Severity sev)
|
void silentlyPrintAllVerbositiesWithSeverity(Severity sev)
|
||||||
|
|
|
@ -34,6 +34,7 @@ uint32_t printEverySeverity(uint32_t i)
|
||||||
LOG(important) << "important message, counter: " << i++;
|
LOG(important) << "important message, counter: " << i++;
|
||||||
LOG(alarm) << "alarm message, counter: " << i++;
|
LOG(alarm) << "alarm message, counter: " << i++;
|
||||||
LOG(error) << "error message, counter: " << i++;
|
LOG(error) << "error message, counter: " << i++;
|
||||||
|
LOG(critical) << "critical message, counter: " << i++;
|
||||||
LOG(fatal) << "fatal message, counter: " << i++;
|
LOG(fatal) << "fatal message, counter: " << i++;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user