Skip to content

Commit 6f6b855

Browse files
committed
update: documentation and examples
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent 4a2740a commit 6f6b855

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3326
-1117
lines changed

Diff for: README.md

+193-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,196 @@ All Rights Reserved
55
SPDX-License-Identifier: Apache-2.0
66
)
77

8-
# soralog
9-
Fast&amp;flex logger for Quadrivium
8+
# Soralog: High-Performance Logging Library
9+
10+
## Overview
11+
12+
Soralog is a high-performance, flexible logging library designed for C++ applications. It provides robust logging features, supports multiple logging backends, and allows extensive customization. The library is designed to be lightweight, efficient, and easy to integrate into various projects.
13+
14+
## Features
15+
16+
- Multiple log sinks: console, file, syslog, and more.
17+
- Efficient lock-free circular buffer for log messages.
18+
- Thread-safe logging with minimal overhead.
19+
- Hierarchical logging groups with inheritance.
20+
- Configurable log levels and formats.
21+
- Configurable via YAML or programmatically.
22+
- Macro-based or object-based logging interface (up to user).
23+
24+
## Installation
25+
26+
### Dependencies
27+
28+
Soralog requires:
29+
- `fmt` for formatting log messages.
30+
- `yaml-cpp` for convenient configuring.
31+
- `gtest` for unit tests (optional).
32+
33+
Soralog uses CMake as its build system and supports different configurations through CMake options.
34+
35+
### Build Options
36+
37+
- `BUILD_TESTS` (default: `OFF`) – Build unit tests.
38+
- `EXAMPLES` (default: `OFF`) – Build example programs.
39+
- `ASAN`, `LSAN`, `MSAN`, `TSAN`, `UBSAN` (default: `OFF`) – Enable sanitizers.
40+
41+
### Supported Package Managers
42+
43+
Soralog supports dependency management via `hunter` and `vcpkg`. By default, `hunter` is used unless a `vcpkg` toolchain file is detected.
44+
45+
```sh
46+
git clone https://github.com/xDimon/soralog.git
47+
cd soralog
48+
mkdir build && cd build
49+
cmake .. -DBUILD_TESTS=ON -DEXAMPLES=ON
50+
make
51+
```
52+
53+
To use `vcpkg`, specify the toolchain file:
54+
55+
```sh
56+
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake ..
57+
```
58+
59+
To include Soralog in your project, add the following to your CMakeLists.txt:
60+
61+
```cmake
62+
find_package(soralog REQUIRED)
63+
target_link_libraries(your_project PRIVATE soralog)
64+
```
65+
66+
## Basic Usage
67+
68+
### Creating a Logger
69+
70+
```cpp
71+
LoggingSystem logging_system(configurator); // See examples
72+
soralog::Logger logger = logging_system.getLogger("loggger", "main_group");
73+
}
74+
```
75+
76+
### Using logger methods
77+
78+
```cpp
79+
logger.debug("Hello, {}!", "world");
80+
logger.info("Hello, {}!", "world");
81+
```
82+
83+
### Using Logging Macros
84+
85+
```cpp
86+
SL_INFO(logger, "Hello, {}!", "world");
87+
SL_WARN(logger, "Hello, {}!", "world");
88+
```
89+
90+
## Configuration File
91+
92+
Soralog uses a YAML-based configuration file. Below is a detailed breakdown of all available parameters.
93+
94+
### Example YAML Configuration
95+
96+
```yaml
97+
sinks:
98+
- name: colored_stdout
99+
type: console
100+
stream: stdout
101+
color: true
102+
103+
- name: file
104+
type: file
105+
path: /tmp/soralog.log
106+
107+
groups:
108+
- name: main
109+
sink: colored_stdout
110+
level: trace
111+
is_fallback: true
112+
children:
113+
- name: example_group
114+
```
115+
116+
### Sink Configuration Options
117+
118+
#### Common Sink Parameters
119+
120+
| Parameter | Type | Required | Default | Description |
121+
|------------------|---------|----------|------------|--------------------------------------------------------------------------------------|
122+
| `name` | string | Yes | N/A | Unique identifier of the sink |
123+
| `type` | string | Yes | N/A | Sink type (`console`, `file`, `syslog`, `multisink`) |
124+
| `thread` | string | No | `none` | Thread info mode (`name`, `id`, `none`) |
125+
| `capacity` | int | No | `64` | Max lock-free buffered messages |
126+
| `buffer` | int | No | `131072` | Max buffer size in bytes |
127+
| `latency` | int | No | `100` | Max delay in milliseconds before flushing |
128+
| `level` | string | No | `trace` | Minimum log level (`trace`, `debug`, `verbose`, `info`, `warn`, `error`, `critical`) |
129+
130+
#### Console Sink (`type: console`)
131+
132+
| Parameter | Type | Required | Default | Description |
133+
|-----------|--------|----------|----------|------------------------------------|
134+
| `stream` | string | No | `stdout` | Output stream (`stdout`, `stderr`) |
135+
| `color` | bool | No | `false` | Enables colored output |
136+
137+
#### File Sink (`type: file`)
138+
139+
| Parameter | Type | Required | Default | Description |
140+
|------------|--------|----------|---------|---------------------------------------------------|
141+
| `path` | string | Yes | N/A | Path to the log file |
142+
| `at_fault` | string | No | `wait` | Action on failure (`terminate`, `wait`, `ignore`) |
143+
144+
#### Syslog Sink (`type: syslog`)
145+
146+
| Parameter | Type | Required | Default | Description |
147+
|-----------|--------|----------|---------|--------------------------------|
148+
| `ident` | string | No | N/A | Identifier for syslog messages |
149+
150+
#### Multisink (`type: multisink`)
151+
152+
| Parameter | Type | Required | Default | Description |
153+
|-----------|-------|----------|---------|---------------------------------------|
154+
| `sinks` | array | Yes | N/A | List of sink names to forward logs to |
155+
156+
### Group Configuration Options
157+
158+
| Parameter | Type | Required | Default | Description |
159+
|---------------|--------|-----------------------|---------|--------------------------------------------------------------------------------------|
160+
| `name` | string | Yes | N/A | Unique identifier of the group |
161+
| `sink` | string | Yes | N/A | Sink used for this group |
162+
| `level` | string | Yes (for root groups) | N/A | Minimum log level (`trace`, `debug`, `verbose`, `info`, `warn`, `error`, `critical`) |
163+
| `is_fallback` | bool | No | `false` | Marks this group as the default fallback |
164+
| `children` | array | No | `[]` | List of child groups |
165+
166+
## Examples
167+
168+
## Examples
169+
170+
Soralog provides various examples demonstrating different use cases and configurations. Below is a list of available examples:
171+
172+
1. **01-hello_world** – A minimal example that initializes a logger and writes a simple message.
173+
2. **02-manual** – Demonstrates programmatic configuration of logging without using a YAML config file.
174+
3. **03-with_config_file** – Shows how to configure Soralog using a YAML configuration file.
175+
4. **04-cascade_config** – Demonstrates hierarchical logging groups with inherited settings.
176+
5. **05-two_sinks** – Example of logging to two different sinks (e.g., console and file).
177+
6. **06-multisink** – Uses a multisink to send log messages to multiple destinations.
178+
7. **07-multisink_with_different_level** – Extends the multisink example by setting different log levels for different sinks.
179+
8. **99-most_features** – A comprehensive example showcasing most of Soralog’s features, including advanced configuration, multi-threading, and custom loggers.
180+
181+
### Example Source Code
182+
183+
The source code for these examples is available in the [example](https://github.com/xDimon/soralog/tree/main/example) directory.
184+
185+
## Projects Using Soralog
186+
187+
Soralog is utilized in several open-source projects, including:
188+
189+
- [cpp-libp2p](https://github.com/libp2p/cpp-libp2p)
190+
- [Kagome](https://github.com/qdrvm/kagome)
191+
- [cpp-jam](https://github.com/qdrvm/cpp-jam)
192+
193+
## Contributing
194+
195+
We welcome contributions! Feel free to submit issues and pull requests.
196+
197+
## License
198+
199+
Soralog is licensed under the Apache-2.0 license. See the LICENSE file for details.
200+

Diff for: example/01-hello_world/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright Soramitsu Co., 2021-2023
3+
# Copyright Quadrivium Co., 2023
4+
# All Rights Reserved
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
add_executable(example_01
9+
main.cpp
10+
)
11+
target_include_directories(example_01
12+
PRIVATE ${CMAKE_SOURCE_DIR}/include
13+
)
14+
target_link_libraries(example_01
15+
soralog::soralog
16+
soralog::yaml
17+
)

Diff for: example/01-hello_world/main.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright Soramitsu Co., 2021-2023
3+
* Copyright Quadrivium Co., 2023
4+
* All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <iostream>
9+
#include <soralog/impl/configurator_from_yaml.hpp>
10+
#include <soralog/logging_system.hpp>
11+
#include <soralog/logger.hpp>
12+
13+
int main() {
14+
// Use configurator with inline yaml content
15+
auto configurator =
16+
std::make_shared<soralog::ConfiguratorFromYAML>(std::string(R"(
17+
sinks: # List of available logging sinks (outputs)
18+
- name: console # Unique identifier for this sink
19+
type: console # Sink type: 'console' means output to stdout or stderr
20+
color: true # Enables colored output using ANSI escape codes
21+
22+
groups: # Log groups define hierarchical loggers
23+
- name: main # Root group handling logs
24+
sink: console # Default sink for this group
25+
level: trace # Minimum log level for this group
26+
is_fallback: true # This is the fallback group (only one allowed)
27+
)"));
28+
29+
// Initialize logging system
30+
soralog::LoggingSystem log_system(configurator);
31+
32+
// Configure logging system
33+
auto r = log_system.configure();
34+
35+
// Check the configuring result (useful for check-up config)
36+
if (not r.message.empty()) {
37+
(r.has_error ? std::cerr : std::cout) << r.message << '\n';
38+
}
39+
if (r.has_error) {
40+
exit(EXIT_FAILURE);
41+
}
42+
43+
// Obtain a logger
44+
auto logger = log_system.getLogger("Greeter", "main");
45+
46+
// Log message
47+
logger->info("Hello, world!");
48+
}

Diff for: example/01-simple/logger.yml

-58
This file was deleted.

Diff for: example/01-simple/logging_object.hpp

-32
This file was deleted.

Diff for: example/02-manual/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright Soramitsu Co., 2021-2023
3+
# Copyright Quadrivium Co., 2023
4+
# All Rights Reserved
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
add_executable(example_02
9+
main.cpp
10+
)
11+
target_include_directories(example_02
12+
PRIVATE ${CMAKE_SOURCE_DIR}/include
13+
)
14+
target_link_libraries(example_02
15+
soralog::soralog
16+
soralog::fallback
17+
)

0 commit comments

Comments
 (0)