HaSLL - Hahn-Schickard Logging Library for Cpp is a logger front-end with some filesystem management utilities. Mainly, this library functions as a wrapper for SPD-Log with directory path creation.
HaSLL - Hahn-Schickard Logging Library for Cpp (pronounced hæs.əl) is a logger front-end with some filesystem management utilities.
This project provides a generic logging interface with a default SPD-Log based logger for users to use with an option to use custom logging mechanism implementations.
This project uses git submodules, please initialize them when creating a fresh repository clone. To initialize all of the submodule run the following command:
git submodule update --init --recursive
You need to have access to Hahn-Schickard's Artifactory server to leverage this functionality!
To use this package with standard configuration within your project add the following line to your conanfile.txt [requires] section:
hasll/[VERSION_TAG]@hahn-schickard/stable
If you desire to change some of the configuration options, please add the desired line to your conanfile.txt [options] section:
hasll:shared = [True||False]
hasll:fPIC = [True||False]
hasll:async_logging = [True||False]
These options have the following meaning:
shared- creates a dynamically linked library (.sofor Linux.dllfor Windows systems)fPIC- enables position-independent code generationasync_logging- enables multi-threaded logging
Various examples can be found under Examples directory. All of the Examples are built as a separate unit and can be run on its own by calling the run() method. All of the examples can be seen in action by running the Example executable.
LoggerManager::initialise("exampleConfig.json");
auto logger = LoggerManager::registerLogger("YOUR_NEW_LOGER_NAME");
logger->log(SeverityLevel::Trace, "Welcome to a frontend for spdlog!");
logger->log(SeverityLevel::Error, "Some error message with arg: {}", 1);
logger->log(SeverityLevel::Warning, "Easy padding in numbers like {:08d}", 12);
logger->log(SeverityLevel::Critical, "Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
logger->log(SeverityLevel::Info, "Support for floats {:03.2f}", 1.23456);
logger->log(SeverityLevel::Info, "Positional args are {1} {0}..", "too", "supported");
logger->log(SeverityLevel::Debug, "{:<30}", "left aligned");Logging pattern configuration is directly linked to spdlog implementation, for reference check Custom formatting, in spdlog wiki.
Our implementation only supports global pattern changing, and can only be set through LoggerManager:
LoggerManager::configurePattern("*** [%H:%M:%S %z] [thread %t] %v ***")Pattern flags are in the form of %flag and resembles the strftime function:
| flag | meaning | example |
|---|---|---|
%v |
The actual text to log | "some user text" |
%t |
Thread id | "1232" |
%P |
Process id | "3456" |
%n |
Logger's name | "some logger name" |
%l |
The log level of the message | "debug", "info", etc |
%L |
Short log level of the message | "D", "I", etc |
%a |
Abbreviated weekday name | "Thu" |
%A |
Full weekday name | "Thursday" |
%b |
Abbreviated month name | "Aug" |
%B |
Full month name | "August" |
%c |
Date and time representation | "Thu Aug 23 15:35:46 2014" |
%C |
Year in 2 digits | "14" |
%Y |
Year in 4 digits | "2014" |
%D or %x |
Short MM/DD/YY date | "08/23/14" |
%m |
Month 01-12 | "11" |
%d |
Day of month 01-31 | "29" |
%H |
Hours in 24 format 00-23 | "23" |
%I |
Hours in 12 format 01-12 | "11" |
%M |
Minutes 00-59 | "59" |
%S |
Seconds 00-59 | "58" |
%e |
Millisecond part of the current second 000-999 | "678" |
%f |
Microsecond part of the current second 000000-999999 | "056789" |
%F |
Nanosecond part of the current second 000000000-999999999 | "256789123" |
%p |
AM/PM | "AM" |
%r |
12 hour clock | "02:55:02 pm" |
%R |
24-hour HH:MM time, equivalent to %H:%M | "23:55" |
%T or %X |
ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S | "23:55:59" |
%z |
ISO 8601 offset from UTC in timezone ([+/-]HH:MM) | "+02:00" |
%E |
Seconds since the epoch | "1528834770" |
%i |
Message sequence number (disabled by default - edit 'tweakme.h' to enable) | "1154" |
%% |
The % sign | "%" |
%+ |
spdlog's default format | "[2014-10-31 23:46:59.678] [mylogger] [info] Some message" |
%^ |
start color range (can be used only once) | "[mylogger] [info(green)] Some message" |
%$ |
end color range (for example %^[+++]%$ %v) (can be used only once) | [+++] Some message |
%@ |
Source file and line (use SPDLOG_TRACE(..), SPDLOG_INFO(...) etc.) | my_file.cpp:123 |
%s |
Basename of the source file (use SPDLOG_TRACE(..), SPDLOG_INFO(...) etc.) | my_file.cpp |
%g |
Full path of the source file (use SPDLOG_TRACE(..), SPDLOG_INFO(...) etc.) | /some/dir/my_file.cpp |
%# |
Source line (use SPDLOG_TRACE(..), SPDLOG_INFO(...) etc.) | 123 |
%! |
Source function (use SPDLOG_TRACE(..), SPDLOG_INFO(...) etc. see tweakme for pretty-print) | my_func |
%o |
Elapsed time in milliseconds since previous message | 00456 |
%i |
Elapsed time in microseconds since previous message | 00456 |
%u |
Elapsed time in nanoseconds since previous message | 11456 |
%O |
Elapsed time in seconds since previous message | 00004 |
Each pattern flag can can be aligned by prepending a width number(upto 64).
Use-(left align) or = (center align) to control the align side:
| align | meaning | example | result |
|---|---|---|---|
%<width><flag> |
Align to the right | %8l |
" info" |
%-<width><flag> |
Align to the left | %-8l |
"info " |
%=<width><flag> |
Align to the center | %=8l |
" info " |
This library allows to set a custom log message sink by implementing the spdlog::base_sink interface and exposing it as a fully implemented class which takes in two function pointers which implement the sink_it_(const details::log_msg &msg) and flush_() methods from SPDLog library. An Example of this implementation can be found in our examples list, within CustomSink_Example.hpp example or at SPD Log Wiki.
If you want to have the latest documentation with your changes locally, you can generate it with Doxygen from sources by running the following:
doxygen DoxyfileThis will generate html like documentation at [PROJECT_ROOT]/docs/html. To use it open the [PROJECT_ROOT]/docs/html/index.html file with your browser.
- compiler with C++17 support
- cmake 3.24.0 >= - build system generator, used by package generator as well
- python3 - used by utilities and package generator
- conan 2.4.0 >= - dependency handler/package generator
- ninja - build system (alternative to
make) - clang-format >=15.0.7 - to use formatting tools
- clang-tidy >=15.0.7 - to use static code analysis
- lcov - to generate code coverage reports
- valgrind - to run memory analysis
- doxygen 1.9.8 >= - to generate documentation from code
- plantuml 1.2023.10 >= - to generate UML diagrams in doxygen
- C/C++ - provides linking to inellisense and code debuggers
- CMake Tools - provides CMake highlighting, configuring, building
- C++ TestMate - C++ Unit Test Explorer integration for Test Explorer UI
- Clang-Format - provides code formatting
- Doxygen Documentation Generator - provides autogenerated doxygen documentation stubs
- Code Spell Checker - provides english text spellchecker functionality
A CMake variant file is provided with this repository for easy cmake configuration setup. This functionality requires CMake Tools plugin to be installed. After Visual Code has been started Open Control Panel with Cntrl + Shift + P and type in CMake: Select Variant to start configuring your cmake project configuration.
To build the project CMake project makefile generation as well as integrated testing and linting tools.
We recommend to create a directory for project makefiles and binaries:
mkdir build && cd buildOnce in this new build directory, generate the project makefiles for Debug configuration (you can change Debug for Release if debugging information is not needed):
cmake .. -DCMAKE_BUILD_TYPE=DebugOnce makefiles have been generated, build the project either in Debug configuration:
cmake --build . --target all --config Debug --or Release configuration, if previous cmake configuration was set for Release:
cmake --build . --target all --config Release --Once the project is built, it is also possible to use the integrated tests runner to run the provided tests:
ctest --verboseTo create a custom local package first define VERSION, USER and CHANEL environmental variables. These variables will tell conan how to name the package.
VERSIONvariable specifies package version number in the following format${MAJOR}.${MINOR}.${PATCH}. For more information see Release versioning schemaUSERvariable specifies the name of release community (for examplehahn-schickard,bincrafters, etc.), it is used to showcase that this package is outside of conan-center-index repositoryCHANELvariable specifies the package type, i.e. if it is a stable, development or nightly release, defaults to empty
To create local conan packages run the following command in project root directory:
conan create . ${VERSION}@${USER}/${CHANEL} --build=missingTo create local conan packages run the following command in project root directory:
conan create . --version=${VERSION} --user=${USER} --channel=${CHANEL} --build=missingIn case you need to change default recipe options
conan create . --version=${VERSION} --user=${USER} --channel=${CHANEL} --build=missing -o ${OPTION_PAIR}Where ${OPTION_PAIR} is option_name=value. To add multiple options, continue to add -o ${OPTION_PAIR} as required.