Skip to content

Hahn-Schickard/HaSLL

Repository files navigation

Hahn-Schickard Logging Library for Cpp

Description

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.

Fresh setup

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

Package usage

TAKE NOTE!

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 (.so for Linux .dll for Windows systems)
  • fPIC - enables position-independent code generation
  • async_logging - enables multi-threaded logging

Library Usage

Examples

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.

Standard calls

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 format - SPD Logger Repository

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

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

Text Alignment - SPD Logger Repository

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  "

Custom sinks - SPD Logger Repository

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.

Documentation

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 Doxyfile

This 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.

Dependencies

Required

  • 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

Optional

  • 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

Visual Studio Code Support

Recommended Plugins:

CMake Variant Integration

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.

Building the project

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 build

Once 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=Debug

Once 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 --verbose

Creating local conan package

To create a custom local package first define VERSION, USER and CHANEL environmental variables. These variables will tell conan how to name the package.

  • VERSION variable specifies package version number in the following format ${MAJOR}.${MINOR}.${PATCH}. For more information see Release versioning schema
  • USER variable specifies the name of release community (for example hahn-schickard, bincrafters, etc.), it is used to showcase that this package is outside of conan-center-index repository
  • CHANEL variable specifies the package type, i.e. if it is a stable, development or nightly release, defaults to empty

Conan v1

To create local conan packages run the following command in project root directory:

conan create . ${VERSION}@${USER}/${CHANEL} --build=missing

Conan v2

To create local conan packages run the following command in project root directory:

conan create . --version=${VERSION} --user=${USER} --channel=${CHANEL} --build=missing

In 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.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors