|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
doc_id: "LOG-GUID-018" doc_title: "Getting Started with logger_system" doc_version: "1.0.0" doc_date: "2026-04-05" doc_status: "Released" project: "logger_system"
A step-by-step guide from zero to production-ready logging in C++20.
| Requirement | Minimum Version |
|---|---|
| C++ standard | C++20 |
| GCC | 11+ |
| Clang | 14+ (Apple Clang 14+) |
| MSVC | 2022+ |
| CMake | 3.21+ |
Required dependency: kcenon-common-system (provides ILogger, Result<T>, concepts).
Optional dependencies:
| Dependency | Purpose |
|---|---|
| OpenSSL | AES-256-GCM encrypted logging |
| opentelemetry-cpp 1.14+ | OTLP export (HTTP/gRPC) |
| kcenon-thread-system | Thread pool for async I/O (standalone std::jthread used by default) |
Key CMake options:
| Option | Default | Description |
|---|---|---|
BUILD_TESTS | ON | Build unit tests |
BUILD_BENCHMARKS | OFF | Build performance benchmarks |
LOGGER_USE_ENCRYPTION | ON | AES-256 via OpenSSL |
LOGGER_ENABLE_OTLP | OFF | OpenTelemetry export |
LOGGER_USE_THREAD_SYSTEM | OFF | Use thread_system pool instead of std::jthread |
The smallest working example — create a logger, attach a console writer, log a message:
Async mode — pass true to the constructor to use a background thread:
See
examples/basic_usage.cppfor the full runnable version.
writer_builder is the recommended way to compose writers. Decorators stack from the inside out:
See
examples/decorator_usage.cppandexamples/writer_builder_example.cpp.
logger_system ships several writer backends:
| Writer | Header | Purpose |
|---|---|---|
console_writer | writers/console_writer.h | stdout/stderr with optional color |
file_writer | writers/file_writer.h | Single file output |
rotating_file_writer | writers/rotating_file_writer.h | Size-based rotation with backup count |
network_writer | writers/network_writer.h | TCP/UDP to a remote log server |
otlp_writer | writers/otlp_writer.h | OpenTelemetry OTLP export |
encrypted_writer | writers/encrypted_writer.h | AES-256-GCM encrypted output |
critical_writer | writers/critical_writer.h | Immediate flush for critical logs |
Decorator writers (wrap any backend):
| Decorator | Header | Purpose |
|---|---|---|
async_writer | writers/async_writer.h | Background thread processing |
buffered_writer | writers/buffered_writer.h | Batch entries before writing |
filtered_writer | writers/filtered_writer.h | Conditional write based on filter |
batch_writer | writers/batch_writer.h | Time or size-triggered batches |
Inherit from thread_safe_writer and implement write_entry_impl() and flush_impl(). The base class handles all locking:
See
examples/custom_writer_example.cppfor a full in-memory writer example.
Structured logging attaches typed key-value fields to each log entry, enabling machine-parseable output in JSON or logfmt:
Set logger-level context that automatically appears in every log entry:
Thread-local context that cleans up automatically:
| Formatter | Output style |
|---|---|
json_formatter | {"level":"info","message":"...","user_id":12345} |
logfmt_formatter | level=info msg="..." user_id=12345 |
template_formatter | Custom pattern: [{timestamp}] [{level}] {message} |
timestamp_formatter | Prepends ISO-8601 timestamp |
When built with LOGGER_ENABLE_OTLP=ON, the otlp_writer exports logs to any OTLP-compatible collector (Grafana, Jaeger, Datadog, etc.):
Trace context propagation is automatic when trace_id / span_id are set via logger_instance->context().
See the OTLP section in
docs/FEATURES.mdfor batch export, retry policies, and TLS configuration.
For comprehensive logger configuration use logger_config_builder:
Or construct a complete logger via logger_builder:
See
examples/logger_config_builder_example.cppandexamples/critical_logging_example.cpp.
| Topic | Resource |
|---|---|
| Full API surface | API_REFERENCE.md |
| Quick cheat sheet | API_QUICK_REFERENCE.md |
| Writer decorator deep-dive | WRITER_GUIDE.md |
| Configuration strategies | CONFIGURATION_STRATEGIES.md |
| Security (encryption, sanitization) | SECURITY_GUIDE.md |
| Architecture overview | ARCHITECTURE.md |
| Performance benchmarks | BENCHMARKS.md |
| Crash protection | LOG_SERVER_AND_CRASH_SAFETY.md |
| Custom writer creation | advanced/CUSTOM_WRITERS.md |
| All examples | ../examples/ (16 runnable programs) |