Language: English | νκ΅μ΄
A high-performance C++20 asynchronous logging framework designed for multithreaded applications. Built with a modular, interface-based architecture and seamless ecosystem integration.
Key Features:
- π Ultra-fast async logging: 4.34M messages/second, 148ns latency
- π Thread-safe by design: Zero data races, production-proven
- ποΈ Modular architecture: Interface-driven, pluggable components
- π‘οΈ Production-grade: Comprehensive CI/CD, sanitizers, benchmarks
- π Security-first: Path validation, secure storage, audit logging
- π Cross-platform: Windows, Linux, macOS with GCC, Clang, MSVC
#include <kcenon/logger/core/logger_builder.h>
#include <kcenon/logger/writers/console_writer.h>
#include <kcenon/logger/writers/file_writer.h>
int main() {
// Create logger using builder pattern with automatic validation
auto result = kcenon::logger::logger_builder()
.use_template("production") // Predefined configuration
.with_min_level(kcenon::logger::log_level::info)
.add_writer("console", std::make_unique<kcenon::logger::console_writer>())
.add_writer("file", std::make_unique<kcenon::logger::file_writer>("app.log"))
.build();
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Failed to create logger: " << err.message
<< " (code: " << err.code << ")\n";
return -1;
}
auto logger = std::move(result.value());
// Log messages with error handling
logger->log(kcenon::logger::log_level::info, "Application started");
logger->log(kcenon::logger::log_level::error, "Something went wrong");
return 0;
}Need a quick reminder later? See the Result Handling Cheatsheet for canonical snippets that can be reused across the ecosystem.
Using CMake:
mkdir build && cd build
cmake ..
cmake --build .
cmake --build . --target installUsing in Your Project:
find_package(LoggerSystem REQUIRED)
target_link_libraries(your_app PRIVATE LoggerSystem::logger)| Dependency | Version | Required | Description |
|---|---|---|---|
| C++20 Compiler | GCC 11+ / Clang 14+ / MSVC 2022+ / Apple Clang 14+ | Yes | C++20 features required |
| CMake | 3.20+ | Yes | Build system |
| common_system | latest | Yes | Common interfaces (ILogger, Result) |
| thread_system | latest | Optional | Async logging with thread pool support |
| vcpkg | latest | Optional | Package management |
| fmt | latest | Optional | Formatting library (header-only mode available) |
logger_system
βββ common_system (required)
βββ thread_system (optional, for async logging with thread pool)
βββ common_system (required)
# Clone dependencies
git clone https://github.com/kcenon/common_system.git
git clone https://github.com/kcenon/thread_system.git # Optional
# Clone and build logger_system
git clone https://github.com/kcenon/logger_system.git
cd logger_system
cmake -B build -DLOGGER_USE_THREAD_SYSTEM=ON # Enable thread_system integration
cmake --build build- Non-blocking operations: Background thread handles I/O without blocking
- Batched processing: Processes multiple log entries efficiently
- Adaptive batching: Intelligent optimization based on queue utilization
- Zero-copy design: Minimal allocations and overhead
- Console Writer: ANSI colored output for different log levels
- File Writer: Buffered file output with configurable settings
- Rotating File Writer: Size/time-based rotation with compression
- Network Writer: TCP/UDP remote logging
- Critical Writer: Synchronous logging for critical messages
- Hybrid Writer: Automatic async/sync switching based on log level
π Detailed Writer Documentation β
- Secure Key Storage: RAII-based encryption key management with automatic cleanup
- Path Validation: Protection against path traversal attacks
- Signal Handler Safety: Emergency flush for crash scenarios
- Security Audit Logging: Tamper-evident audit trail with HMAC-SHA256
- Compliance Support: GDPR, PCI DSS, ISO 27001, SOC 2
π Complete Security Guide β
Benchmarked on Apple M1 (8-core) @ 3.2GHz, 16GB, macOS Sonoma
| Configuration | Throughput | vs spdlog |
|---|---|---|
| Single thread (async) | 4.34M msg/s | -19% |
| 4 threads | 1.07M msg/s | +36% |
| 8 threads | 412K msg/s | +72% |
| 16 threads | 390K msg/s | +117% |
| Metric | Logger System | spdlog async | Advantage |
|---|---|---|---|
| Average | 148 ns | 2,325 ns | 15.7x faster |
| p99 | 312 ns | 4,850 ns | 15.5x faster |
| p99.9 | 487 ns | ~7,000 ns | 14.4x faster |
- Baseline: 1.8 MB (vs spdlog: 4.2 MB, 57% less)
- Peak: 2.4 MB
- Allocations/msg: 0.12
Key Insights:
- π Multi-threaded advantage: Adaptive batching provides superior scaling
- β±οΈ Ultra-low latency: Industry-leading 148ns average enqueue time
- πΎ Memory efficient: Minimal footprint with zero-copy design
β‘ Full Benchmarks & Methodology β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Logger Core β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Builder β β Async Queue β β Metrics β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β Writers β β Filters β β Formatters β
β β β β β β
β β’ Console β β β’ Level β β β’ Plain Text β
β β’ File β β β’ Regex β β β’ JSON β
β β’ Rotating β β β’ Function β β β’ Logfmt β
β β’ Network β β β’ Composite β β β’ Custom β
β β’ Critical β β β β β
β β’ Hybrid β β β β β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
- Logger Core: Main async processing engine with builder pattern
- Writers: Pluggable output destinations (file, console, network, etc.)
- Filters: Conditional logging based on level, pattern, or custom logic
- Formatters: Configurable output formats (plain, JSON, logfmt, custom)
- Security: Path validation, secure storage, audit logging
ποΈ Detailed Architecture Guide β
Part of a modular C++ ecosystem with clean interface boundaries:
Required:
- common_system: Core interfaces (ILogger, IMonitor, Result) with C++20 Concepts support
Optional:
- thread_system: Enhanced threading primitives (optional since v3.1.0)
- monitoring_system: Metrics and health monitoring
Note: Since v3.1.0,
thread_systemis optional. The logger system uses a standalone std::jthread implementation by default. For advanced async processing, enable thread_system integration with-DLOGGER_USE_THREAD_SYSTEM=ON(see Issue #224).
#include <kcenon/logger/core/logger.h>
#include <kcenon/logger/core/logger_builder.h>
#include <kcenon/logger/writers/console_writer.h>
int main() {
// Create logger using builder pattern (standalone mode, no thread_system required)
auto logger = kcenon::logger::logger_builder()
.use_template("production")
.add_writer("console", std::make_unique<kcenon::logger::console_writer>())
.build()
.value();
// Use logger anywhere in your application
logger->log(kcenon::logger::log_level::info, "System initialized");
return 0;
}Note: When
thread_systemis available andLOGGER_HAS_THREAD_SYSTEMis defined (via-DLOGGER_USE_THREAD_SYSTEM=ON), additional integration features are enabled including shared thread pool for async processing. See thread_system integration for details.
Benefits:
- Interface-only dependencies (no circular references)
- Independent compilation and deployment
- Runtime component injection via DI pattern
- Clean separation of concerns
π Ecosystem Integration Guide β
- π Getting Started Guide - Step-by-step setup and basic usage
- π Quick Start Examples - Hands-on examples
- π§ Build Guide - Detailed build instructions
- π Features - Comprehensive feature documentation
- π Benchmarks - Performance analysis and comparisons
- ποΈ Architecture - System design and internals
- π Project Structure - Directory organization and files
- π§ API Reference - Complete API documentation
- β‘ Performance Guide - Optimization tips and tuning
- π Security Guide - Security considerations and best practices
- β Production Quality - CI/CD, testing, quality metrics
- π¨ Custom Writers - Creating custom log writers
- π Integration Guide - Ecosystem integration patterns
- π€ Contributing Guide - How to contribute
- π FAQ - Frequently asked questions
- π Troubleshooting - Common issues and solutions
- π Changelog - Release history and changes
The logger system provides predefined templates for common scenarios:
// Production: Optimized for production environments
auto logger = kcenon::logger::logger_builder()
.use_template("production")
.build()
.value();
// Debug: Immediate output for development
auto logger = kcenon::logger::logger_builder()
.use_template("debug")
.build()
.value();
// High-performance: Maximized throughput
auto logger = kcenon::logger::logger_builder()
.use_template("high_performance")
.build()
.value();
// Low-latency: Minimized latency for real-time systems
auto logger = kcenon::logger::logger_builder()
.use_template("low_latency")
.build()
.value();auto logger = kcenon::logger::logger_builder()
// Core settings
.with_min_level(kcenon::logger::log_level::info)
.with_buffer_size(16384)
.with_batch_size(200)
.with_queue_size(20000)
// Add multiple writers
.add_writer("console", std::make_unique<kcenon::logger::console_writer>())
.add_writer("file", std::make_unique<kcenon::logger::rotating_file_writer>(
"app.log",
10 * 1024 * 1024, // 10MB per file
5 // Keep 5 files
))
// Build with validation
.build()
.value();π Complete Configuration Guide β
# Core Features
cmake -DLOGGER_USE_DI=ON # Dependency injection (default: ON)
cmake -DLOGGER_USE_MONITORING=ON # Monitoring support (default: ON)
cmake -DLOGGER_ENABLE_ASYNC=ON # Async logging (default: ON)
cmake -DLOGGER_ENABLE_CRASH_HANDLER=ON # Crash handler (default: ON)
# Advanced Features
cmake -DLOGGER_ENABLE_STRUCTURED_LOGGING=ON # JSON logging (default: OFF)
cmake -DLOGGER_ENABLE_NETWORK_WRITER=ON # Network writer (default: OFF)
cmake -DLOGGER_ENABLE_FILE_ROTATION=ON # File rotation (default: ON)
# Performance Tuning
cmake -DLOGGER_DEFAULT_BUFFER_SIZE=16384 # Buffer size in bytes
cmake -DLOGGER_DEFAULT_BATCH_SIZE=200 # Batch processing size
cmake -DLOGGER_DEFAULT_QUEUE_SIZE=20000 # Maximum queue size
# Quality Assurance
cmake -DLOGGER_ENABLE_SANITIZERS=ON # Enable sanitizers
cmake -DLOGGER_ENABLE_COVERAGE=ON # Code coverage
cmake -DLOGGER_WARNINGS_AS_ERRORS=ON # Treat warnings as errorsπ§ Complete Build Options β
| Platform | Architecture | Compilers | Status |
|---|---|---|---|
| Ubuntu 22.04+ | x86_64, ARM64 | GCC 11+, Clang 14+ | β Fully tested |
| macOS Sonoma+ | x86_64, ARM64 (M1/M2) | Apple Clang 14+ | β Fully tested |
| Windows 11 | x86_64 | MSVC 2022 | β Fully tested |
Minimum Requirements:
- C++20 compiler
- CMake 3.20+
- fmt library
The logger system includes comprehensive testing infrastructure:
- Unit Tests: 150+ test cases (GTest)
- Integration Tests: 30+ scenarios
- Benchmarks: 20+ performance tests
- Coverage: ~65% (growing)
# Build with tests
cmake -DBUILD_TESTS=ON ..
cmake --build .
# Run all tests
ctest --output-on-failure
# Run specific test suite
./build/bin/core_tests
./build/bin/writer_tests
# Run benchmarks
./build/bin/benchmarksAll pipelines green:
- β Multi-platform builds (Ubuntu, macOS, Windows)
- β Sanitizers (Thread, Address, UB)
- β Performance benchmarks
- β Code coverage
- β Static analysis (clang-tidy, cppcheck)
β Production Quality Metrics β
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow modern C++ best practices
- Use RAII and smart pointers
- Write comprehensive unit tests
- Maintain consistent formatting (clang-format)
- Document public APIs
π€ Contributing Guidelines β
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: kcenon@naver.com
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
- Inspired by modern logging frameworks (spdlog, Boost.Log, glog)
- Built with C++20 features (GCC 11+, Clang 14+, MSVC 2022+) for maximum performance and safety
- Maintained by kcenon@naver.com
Made with β€οΈ by πβππ₯ π