An open API service indexing awesome lists of open source software.

https://github.com/kdab/kdspdsetup

A small library in modern C++ to initialize spdlog loggers from a toml configuration file.
https://github.com/kdab/kdspdsetup

cmake config cpp cpp20 library spdlog toml-config

Last synced: 7 months ago
JSON representation

A small library in modern C++ to initialize spdlog loggers from a toml configuration file.

Awesome Lists containing this project

README

          

# KDSPDSetup

![MIT License](https://img.shields.io/badge/MIT_LICENSE-darkgreen?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEiIHdpZHRoPSIyNSIgaGVpZ2h0PSIyNSI+PHBhdGggZD0iTTEyLjc1IDIuNzVWNC41aDEuOTc1Yy4zNTEgMCAuNjk0LjEwNi45ODQuMzAzbDEuNjk3IDEuMTU0Yy4wNDEuMDI4LjA5LjA0My4xNC4wNDNoNC4xMDJhLjc1Ljc1IDAgMCAxIDAgMS41SDIwLjA3bDMuMzY2IDcuNjhhLjc0OS43NDkgMCAwIDEtLjIzLjg5NmMtLjEuMDc0LS4yMDMuMTQzLS4zMS4yMDZhNi4yOTYgNi4yOTYgMCAwIDEtLjc5LjM5OSA3LjM0OSA3LjM0OSAwIDAgMS0yLjg1Ni41NjkgNy4zNDMgNy4zNDMgMCAwIDEtMi44NTUtLjU2OCA2LjIwNSA2LjIwNSAwIDAgMS0uNzktLjQgMy4yMDUgMy4yMDUgMCAwIDEtLjMwNy0uMjAybC0uMDA1LS4wMDRhLjc0OS43NDkgMCAwIDEtLjIzLS44OTZsMy4zNjgtNy42OGgtLjg4NmMtLjM1MSAwLS42OTQtLjEwNi0uOTg0LS4zMDNsLTEuNjk3LTEuMTU0YS4yNDYuMjQ2IDAgMCAwLS4xNC0uMDQzSDEyLjc1djE0LjVoNC40ODdhLjc1Ljc1IDAgMCAxIDAgMS41SDYuNzYzYS43NS43NSAwIDAgMSAwLTEuNWg0LjQ4N1Y2SDkuMjc1YS4yNDkuMjQ5IDAgMCAwLS4xNC4wNDNMNy40MzkgNy4xOTdjLS4yOS4xOTctLjYzMy4zMDMtLjk4NC4zMDNoLS44ODZsMy4zNjggNy42OGEuNzUuNzUgMCAwIDEtLjIwOS44NzhjLS4wOC4wNjUtLjE2LjEyNi0uMzEuMjIzYTYuMDc3IDYuMDc3IDAgMCAxLS43OTIuNDMzIDYuOTI0IDYuOTI0IDAgMCAxLTIuODc2LjYyIDYuOTEzIDYuOTEzIDAgMCAxLTIuODc2LS42MiA2LjA3NyA2LjA3NyAwIDAgMS0uNzkyLS40MzMgMy40ODMgMy40ODMgMCAwIDEtLjMwOS0uMjIxLjc2Mi43NjIgMCAwIDEtLjIxLS44OEwzLjkzIDcuNUgyLjM1M2EuNzUuNzUgMCAwIDEgMC0xLjVoNC4xMDJjLjA1IDAgLjA5OS0uMDE1LjE0MS0uMDQzbDEuNjk1LTEuMTU0Yy4yOS0uMTk4LjYzNC0uMzAzLjk4NS0uMzAzaDEuOTc0VjIuNzVhLjc1Ljc1IDAgMCAxIDEuNSAwWk0yLjE5MyAxNS4xOThhNS40MTQgNS40MTQgMCAwIDAgMi41NTcuNjM1IDUuNDE0IDUuNDE0IDAgMCAwIDIuNTU3LS42MzVMNC43NSA5LjM2OFptMTQuNTEtLjAyNGMuMDgyLjA0LjE3NC4wODMuMjc1LjEyNi41My4yMjMgMS4zMDUuNDUgMi4yNzIuNDVhNS44NDcgNS44NDcgMCAwIDAgMi41NDctLjU3NkwxOS4yNSA5LjM2N1oiIGZpbGw9IiNmZmYiPjwvcGF0aD48L3N2Zz4=)![C++](https://img.shields.io/badge/c%2B%2B-red?style=for-the-badge&logo=c%2B%2B)![CMake](https://img.shields.io/badge/CMake-%23008FBA.svg?style=for-the-badge&logo=cmake&logoColor=white)![Git](https://img.shields.io/badge/git-%23F05033.svg?style=for-the-badge&logo=git&logoColor=white)![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0)

## Overview

KDSPDSetup is a minimal reimplementation of the unmaintained [spdlog_setup](https://github.com/guangie88/spdlog_setup) library for modern C++ projects.

Complete documentation is available [here](https://kdab.github.io/KDSPDSetup).

Given a TOML file containing configuration parameters, `spdlog` loggers for your project can be set up with a single call to `KDSPDSetup::setupFrom`, as shown below:

```cpp
#include

int main()
{
KDSPDSetup::setupFrom("example.toml");

auto logger = spdlog::get("root");
logger->debug("Hello spdlog!");
}

// [2023-10-30 14:35:19.244] [root] [debug] Hello spdlog!

```

The configuration file for this example, `example.toml`, might look like this:

```c
[[sink]]
name = "console_st"
type = "stdout_sink_st"

[[logger]]
name = "root"
sinks = ["console_st"]
level = "debug"
```

## Requirements

You will need a compiler that supports the C++20 standard.

Our CI has successfully built and tested on these environments:
|Platform|Kernel|Arch|Compiler|Compiler Version
|-|-|-|-|-
| Windows 10 | Microsoft Windows [Version 10.0.19044.1526] | x64 | MSVC | 19.34.31937.0
| Ubuntu GNU/Linux | 4.15.0-167-generic #175-Ubuntu SMP | x64 | GCC | 11.4.0
| MacOS | Darwin Kernel Version 22.6.0 xnu-8796.141.3.701.17 | arm64 | clang | 14.0.3.14030022

The following compiler versions should be sufficient, but this has not been fully tested:

| ![GNU Badge](https://img.shields.io/badge/gcc-A42E2B?logo=gnu&logoColor=fff&style=for-the-badge) | ![LLVM Badge](https://img.shields.io/badge/clang-262D3A?logo=llvm&logoColor=fff&style=for-the-badge) | ![Visual Studio Badge](https://img.shields.io/badge/msvc-5C2D91?logo=visualstudio&logoColor=fff&style=for-the-badge) | ![NVIDIA Badge](https://img.shields.io/badge/nvcc-76B900?logo=nvidia&logoColor=fff&style=for-the-badge) | ![Intel Badge](https://img.shields.io/badge/Intel%20C++-0071C5?logo=intel&logoColor=fff&style=for-the-badge)
|-|-|-|-|-
| GCC 10+ | Clang 8+ | MSVC 19.22+ | NVCC 12.0+ | Intel C++ 2021.1+

If any [dependencies](#dependencies) are not found, CMake's FetchContent will use [`git`](https://git-scm.com/) to retrieve them. Thus, `git` is also a requirement in this case.

## Dependencies

Aside from [spdlog](https://github.com/gabime/spdlog), there are three additional dependencies:

| Purpose | Lib | Needed
| ------------- | --------------------------------------------- | ----------
| TOML parsing | [toml11](https://github.com/ToruNiina/toml11) | Always
| Testing | [doctest](https://github.com/doctest/doctest) | Tests only
| Documentation | [doxygen](https://github.com/doxygen/doxygen) | Documentation only

These dependencies will be automatically downloaded with `git` if not found.

## Build & Install

### Build

You'll need at least CMake 3.11 to build this library.

You can skip to the [CMake Presets](#cmake-presets) section if you'd like to use a preset that will set the source and build directories for you, along with some flags.

To configure and build, use the following `cmake` commands:

```bash
$ cmake -S -B
$ cmake --build
```

where `` is the root directory of this project and `` is the desired build directory.

`` can be empty or contain one or more of the flags detailed in the [Tests](#tests), [Examples](#examples), and [Documentation](#documentation) sections below.

For example, from this directory one might run the following:

```bash
$ cmake -S . -B build
$ cmake --build build
```

which creates the directory `build` if it does not exist, configures CMake, and builds the project.

### CMake Presets

There are a number of CMake presets included. These will configure a build with specific flags set for either development or release.

`dev-*` configurations will add tests and documentation to the build targets. They also build in CMake's `Debug` mode, which will enable debug symbols and will NOT use compiler optimization flags.

`release-*` configurations will not build tests or documentation. They build in CMake's `Release` mode, which will use compiler optimization and will NOT build with debug symbols.

Examples will be built with both types of preset unless explicitly disabled with [`-DKDSPDSETUP_BUILD_EXAMPLES=OFF`](#examples).

Here are all the presets:

- `dev-gcc`
- `dev-clang`
- `dev-msvc`
- `release-gcc`
- `release-clang`
- `release-msvc`

To build from this directory with a preset (we'll use `dev-gcc` as an example), one would run the following:

```bash
$ cmake --preset dev-gcc
$ cmake --build build-dev-gcc
```

Note that for preset name `presetName` the build directory will be titled `build-presetName`.

### Install

To install the library on your system, after completing the steps in the [Build](#build) section above, run the following command:

```bash
$ sudo cmake --install
```

### Tests

You can build the unit tests by passing the flag `-DKDSPDSETUP_BUILD_TESTS=ON` to CMake:

```bash
$ cmake -S -B -DKDSPDSETUP_BUILD_TESTS
$ cmake --build
```

The dependency [doctest](https://github.com/doctest/doctest) will only be used when this flag is on.

### Examples

Building examples is on by default.

To disable the basic examples, pass the flag `-DKDSPDSETUP_BUILD_EXAMPLES=OFF` to CMake:

```bash
$ cmake -S -B -DKDSPDSETUP_BUILD_EXAMPLES=OFF
$ cmake --build
```

### Documentation

The documentation for this project [is available online](https://kdab.github.io/KDSPDSetup).

To build the documentation locally, pass the flag `-DKDSPDSETUP_BUILD_DOCS=ON` to CMake.

```bash
$ cmake -S -B -DKDSPDSETUP_BUILD_DOCS
$ cmake --build
```

The dependency [doxygen](https://github.com/doxygen/doxygen) will only be used when this flag is on.

## Usage

### Use With CMake Project

To use the library in a CMake project, make sure to [install](#install) the library.

Then, simply write the following line in your `CMakeLists.txt`:

```cmake
find_package(KDSpdSetup)
```

and after adding your target, let's call it `untitled`, link with this CMake command:

```cmake
target_link_libraries(untitled KDSpdSetup::KDSpdSetup)
```

### Configuration

Writing configuration files that can be used by KDSPDSetup is simple.

#### Sinks

To configure a sink, a name and sink type must be provided:

```c
[[sink]]
name = "some_name"
type = "stdout_sink_st"
```

Optionally, a level can also be specified:

```c
[[sink]]
name = "stdout_error"
type = "stdout_sink_mt"
level = "err"
```

Some sink types require additional fields, or allow additional optional fields.

The list below details the sink types which have additional required fields:

|`type`|required field|value type
|-|-|-
|`basic_file_sink_st`
`basic_file_sink_mt` |`filename`|`string`
|`rotating_file_sink_st`
`rotating_file_sink_mt`|`base_filename`
`max_size`
`max_files`|`string`
`string`
`int`
|`daily_file_sink_st`
`daily_file_sink_mt`|`base_filename`
`rotation_hour`
`rotation_minute`|`string`
`int`
`int`

All of the above sink types can also optionally specify the boolean `truncate`, which defaults to `false` if not specified.

The syslog sink types, `syslog_sink_st` and `syslog_sink_mt`, have four optional fields that generally do not need to be filled (but can be if needed):
|key name|value type|default value
|-|-|-
|`ident`|`string`|`""`
|`syslog_option`|`int`|`0`
|`syslog_facility`|`int`|`1`

Note that a `syslog_facility` value of `1` is the plain integer value for `LOG_USER`.

Here is a full list of currently supported sink types and the platforms on which they are available:

|Sink Type|Platform(s)
|-|-
|`stdout_sink_st`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tL2xpY2Vuc2UvZnJlZSBDb3B5cmlnaHQgMjAyMyBGb250aWNvbnMsIEluYy4tLT48cGF0aCBvcGFjaXR5PSIxIiBmaWxsPSJ3aGl0ZSIgZD0iTTQzOC42IDEwNS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`stdout_sink_mt`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIG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zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`color_stdout_sink_mt`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tL2xpY2Vuc2UvZnJlZSBDb3B5cmlnaHQgMjAyMyBGb250aWNvbnMsIEluYy4tLT48cGF0aCBvcGFjaXR5PSIxIiBmaWxsPSJ3aGl0ZSIgZD0iTTQzOC42IDEwNS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`basic_file_sink_st`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tL2xpY2Vuc2UvZnJlZSBDb3B5cmlnaHQgMjAyMyBGb250aWNvbnMsIEluYy4tLT48cGF0aCBvcGFjaXR5PSIxIiBmaWxsPSJ3aGl0ZSIgZD0iTTQzOC42IDEwNS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`basic_file_sink_mt`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tL2xpY2Vuc2UvZnJlZSBDb3B5cmlnaHQgMjAyMyBGb250aWNvbnMsIEluYy4tLT48cGF0aCBvcGFjaXR5PSIxIiBmaWxsPSJ3aGl0ZSIgZD0iTTQzOC42IDEwNS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`rotating_file_sink_st`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/sv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NS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`daily_file_sink_st`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tL2xpY2Vuc2UvZnJlZSBDb3B5cmlnaHQgMjAyMyBGb250aWNvbnMsIEluYy4tLT48cGF0aCBvcGFjaXR5PSIxIiBmaWxsPSJ3aGl0ZSIgZD0iTTQzOC42IDEwNS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`daily_file_sink_mt`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHd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1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`null_sink_mt`|![All](https://img.shields.io/badge/all-darkgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNCIgdmlld0JveD0iMCAwIDQ0OCA1MTIiPjwhLS0hRm9udCBBd2Vzb21lIEZyZWUgNi41LjEgYnkgQGZvbnRhd2Vzb21lIC0gaHR0cHM6Ly9mb250YXdlc29tZS5jb20gTGljZW5zZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tL2xpY2Vuc2UvZnJlZSBDb3B5cmlnaHQgMjAyMyBGb250aWNvbnMsIEluYy4tLT48cGF0aCBvcGFjaXR5PSIxIiBmaWxsPSJ3aGl0ZSIgZD0iTTQzOC42IDEwNS40YzEyLjUgMTIuNSAxMi41IDMyLjggMCA0NS4zbC0yNTYgMjU2Yy0xMi41IDEyLjUtMzIuOCAxMi41LTQ1LjMgMGwtMTI4LTEyOGMtMTIuNS0xMi41LTEyLjUtMzIuOCAwLTQ1LjNzMzIuOC0xMi41IDQ1LjMgMEwxNjAgMzM4LjcgMzkzLjQgMTA1LjRjMTIuNS0xMi41IDMyLjgtMTIuNSA0NS4zIDB6Ii8+PC9zdmc+&style=for-the-badge)
|`syslog_sink_st`|![Linux](https://img.shields.io/badge/Linux_Only-FCC624?style=for-the-badge&logo=linux&logoColor=black)
|`syslog_sink_mt`|![Linux](https://img.shields.io/badge/Linux_Only-FCC624?style=for-the-badge&logo=linux&logoColor=black)
|`msvc_sink_st`|![Windows](https://img.shields.io/badge/Windows_Only-0078D6?style=for-the-badge&logo=windows&logoColor=white)
|`msvc_sink_mt`|![Windows](https://img.shields.io/badge/Windows_Only-0078D6?style=for-the-badge&logo=windows&logoColor=white)

Please note that the suffix `_st` refers to single thread, and `_mt` to multiple threads.

#### Patterns

The global pattern is defined as a free-standing key-value pair (not under a `[[pattern]]` or any other table):

```c
global_pattern = "[%Y-%m-%dT%T%z] [%L] <%n>: %v"
```

If `global_pattern` is not specified, the spdlog uses the default pattern `“[%Y-%m-%d %H:%M:%S. %e] [%l] [%n] %v”`.

Additionally, named patterns can be defined and reused with several different loggers:

```c
[[pattern]]
name = "short_pattern"
value = "%c-%L: %v"
```

#### Thread Pools

An async logger takes a thread pool as an argument to its constructor. This can be either a global thread pool, or a manually constructed one.

The global thread pool is defined as a table with single brackets (`[global_thread_pool]`, **not** `[[global_thread_pool]]`) because it is one table, not an array of tables. Named thread pools are members of the array of tables `[[threadpool]]`.

Both require integers `queue_size` and `num_threads`, while non-global thread pools also require a name.

```c
[global_thread_pool]
queue_size = 8192
num_threads = 1

[[thread_pool]]
name = "tp"
queue_size = 4096
num_threads = 2
```

#### Loggers

Loggers require a name, and a list of sink names:

```c
[[logger]]
name = "my_logger"
sinks = ["console_sink_st", "console_sink_mt", "file_out", "file_err"]
```

Please keep in mind that each sink name must be a `name` from a `[[sink]]` defined somewhere in the configuration file. If the name is not found, `std::out_of_range` will be thrown.

Loggers can also optionally specify patterns and levels:

```c
[[logger]]
name = "root"
sinks = [
"console_st", "console_mt",
"color_console_st", "color_console_mt",
"daily_out", "daily_err",
"file_out", "file_err",
"rotate_out", "rotate_err",
"null_sink_st", "null_sink_mt",
"syslog_st", "syslog_mt"]
level = "trace"
pattern = "short_pattern"
```

The pattern name also must be defined somewhere in the configuration.

Asynchronous loggers can be defined by specifying `type = "async"`:

```c
[[logger]]
type = "async"
name = "my_async"
sinks = ["console_mt"]
```

Optionally, async loggers can have a specified thread pool and overflow policy:

```c
[[logger]]
type = "async"
name = "local_async"
sinks = ["console_mt"]
pattern = "succient"
thread_pool = "tp"
overflow_policy = "overrun_oldest"
```

If no thread pool is specified, the global thread pool is used.

The options for overflow policy are `"block"` and `"overrun_oldest"`. If not specified, `"block"` is used by default.

#### Example Files

This repository contains a few example configuration files:

- `examples/example.toml`
- `tests/full/full-linux.toml`
- `tests/full/full-linux.toml`
- `tests/pre/pre.toml`

Huge thanks to [guangie88](https://github.com/guangie88) for providing these examples in the original [spdlog_setup](https://github.com/guangie88/spdlog_setup) project. The files in that project are available under the terms of the [MIT](https://github.com/guangie88/spdlog_setup/blob/master/LICENSE) license.

## Licensing

KDSPDSetup is (C) 2023, Klarälvdalens Datakonsult AB, and is available under the terms of the [MIT](LICENSES/MIT.txt) license.

Contact KDAB at if you need different licensing options.

## About KDAB

KDSPDSetup is supported and maintained by Klarälvdalens Datakonsult AB (KDAB).

The KDAB Group is the global No.1 software consultancy for Qt, C++ and OpenGL applications across desktop, embedded and mobile platforms.

The KDAB Group provides consulting and mentoring for developing Qt applications from scratch and in porting from all popular and legacy frameworks to Qt. We continue to help develop parts of Qt and are one of the major contributors to the Qt Project. We can give advanced or standard trainings anywhere around the globe on Qt as well as C++, OpenGL, 3D and more.

Please visit to meet the people who write code like this.

Stay up-to-date with KDAB product announcements:

- [KDAB Newsletter](https://news.kdab.com)
- [KDAB Blogs](https://www.kdab.com/category/blogs)
- [KDAB on Twitter](https://twitter.com/KDABQt)