autotoc_md562
doc_id: "LOG-ARCH-007" doc_title: "Logger System Architecture" doc_version: "1.0.0" doc_date: "2026-04-04" doc_status: "Released" project: "logger_system"
category: "ARCH"
Language: English | 한국어
Logger System Architecture
SSOT: This document is the single source of truth for Logger System Architecture.
Version: 0.3.0.0 Last Updated: 2025-12-10
Table of Contents
- Overview
- Architecture Diagram
- Core Components
- 1. ILogger Interface Implementation
- 2. Dual API Design
- 3. Configuration Management
- 4. Builder Pattern with Validation
- 5. Backend Abstraction
- 6. Interface Segregation
- 7. Log Entry Structure
- Advanced Features
- 1. Asynchronous Pipeline
- 2. Error Handling with Result Pattern
- 3. C++20 Source Location
- 4. Performance Monitoring
- 5. Configuration Strategies
- Threading Model
- Memory Management
- Performance Characteristics
- Integration Patterns
- Extension Points
- Future Enhancements
- Best Practices
- Platform Notes
Overview
The Logger System (v3.0) is a high-performance, modular logging framework that implements common::interfaces::ILogger from common_system. It operates in standalone mode by default using std::jthread, with optional integration with thread_system for enhanced threading capabilities.
Key Features (v3.0)
- ILogger Implementation: Full implementation of
common::interfaces::ILogger
- Standalone Mode: No thread_system dependency required (uses
std::jthread)
- Dual API: Both
common::interfaces::log_level and native logger_system::log_level
- C++20 Support: Leverages Concepts and
source_location
- Comprehensive Error Handling: Result pattern throughout
Architecture Diagram
┌─────────────────────────────────────────────────────────────────┐
│ Client Application │
├─────────────────────────────────────────────────────────────────┤
│ common::interfaces::ILogger (API) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ ILogger Methods (Phase 2.0) │ │
│ │ • log(level, message) │ │
│ │ • log(level, message, source_location) ← C++20 │ │
│ │ • is_enabled(level) │ │
│ │ • set_level(level) / get_level() │ │
│ │ • flush() │ │
│ └─────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ kcenon::logger::logger │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Sync Mode │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌────────────┐ │ │
│ │ │ Format │→ │ Write │→ │ Flush │ │ │
│ │ └─────────────┘ └─────────────┘ └────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Async Mode (Default) │ │
│ │ ┌────────────┐ ┌──────────────┐ ┌────────────┐ │ │
│ │ │ Queue │→ │ async_worker │→ │ Batch │ │ │
│ │ │ │ │ (std::jthread│ │ Processor │ │ │
│ │ │ │ │ standalone) │ │ │ │ │
│ │ └────────────┘ └──────────────┘ └────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ Backend Abstraction Layer (v3.0) │
│ ┌──────────────────────┐ ┌─────────────────────────────────┐ │
│ │ standalone_backend │ │ thread_system_backend │ │
│ │ (Default) │ │ (Optional, requires linking) │ │
│ │ • std::jthread │ │ • thread_pool integration │ │
│ │ • No dependencies │ │ • Enhanced scheduling │ │
│ └──────────────────────┘ └─────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ Configuration & Builder Pattern Layer │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ logger_builder │ │ logger_config │ │ Config │ │
│ │ │ │ │ │ Strategies │ │
│ │ • Fluent API │ │ • Validation │ │ • deployment │ │
│ │ • Result Types │ │ • Defaults │ │ • performance │ │
│ │ • Backend Sel. │ │ • C++20 opts │ │ • environment │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ Interface Segregation Layer │
│ ┌────────────────┐ ┌─────────────────┐ ┌─────────────────────┐ │
│ │ log_writer_ │ │ log_filter_ │ │ log_formatter_ │ │
│ │ interface │ │ interface │ │ interface │ │
│ └────────────────┘ └─────────────────┘ └─────────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ Writers │
│ ┌────────────┐ ┌──────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ console_ │ │ file_ │ │ rotating_ │ │ network_ │ │
│ │ writer │ │ writer │ │ file_writer │ │ writer │ │
│ └────────────┘ └──────────┘ └──────────────┘ └──────────────┘ │
│ ┌────────────┐ ┌──────────┐ ┌──────────────┐ │
│ │ critical_ │ │ batch_ │ │ async_ │ │
│ │ writer │ │ writer │ │ writer │ │
│ └────────────┘ └──────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Core Components
1. ILogger Interface Implementation
Since v2.0, the logger implements common::interfaces::ILogger for ecosystem standardization:
class logger :
public common::interfaces::ILogger,
public security::critical_logger_interface {
public:
const std::string& message) override;
std::string_view message,
const common::source_location& loc =
common::source_location::current()) override;
bool is_enabled(common::interfaces::log_level level)
const override;
common::interfaces::log_level
get_level()
const override;
};
}
common::VoidResult set_level(common::interfaces::log_level level) override
Set the minimum log level (ILogger interface)
common::interfaces::log_level get_level() const override
Get the current minimum log level (ILogger interface)
bool is_enabled(common::interfaces::log_level level) const override
Check if logging is enabled for the specified level (ILogger interface)
common::VoidResult log(common::interfaces::log_level level, const std::string &message) override
Log a message with specified level (ILogger interface)
common::VoidResult flush() override
Flush any buffered log messages (ILogger interface)
2. Dual API Design
The logger supports both standardized and native APIs for flexibility and backward compatibility:
public:
const std::string& message);
std::string_view message,
const common::source_location& loc =
common::source_location::current());
void log(log_level level,
const std::string& message);
void log(log_level level,
const std::string& message,
const std::string& file, int line, const std::string& function);
void set_min_level(log_level level);
log_level get_min_level() const;
};
}
3. Configuration Management
Logger Configuration with Validation
struct logger_config {
logger_system::log_level
min_level = logger_system::log_level::info;
};
}
log_level min_level
Minimum log level to process.
std::size_t batch_size
Number of messages per batch write.
common::VoidResult validate() const
Validate the configuration.
bool async
Enable asynchronous logging.
overflow_policy queue_overflow_policy
Active overflow policy.
bool enable_source_location
Include source file/line in log entries.
bool enable_metrics
Enable performance metrics collection.
overflow_policy
Policy for handling queue overflow when max_queue_size is reached.
std::chrono::milliseconds flush_interval
Interval between automatic flushes.
std::size_t buffer_size
Internal buffer size in bytes.
bool enable_crash_handler
Enable crash signal handler.
bool enable_structured_logging
Enable structured (JSON) log output.
Configuration Templates
Predefined configurations for common scenarios:
| Template | Use Case | Async | Batch Size | Flush Interval |
default | General purpose | true | 100 | 1000ms |
production | Production environments | true | 200 | 500ms |
debug | Development | false | 1 | 0ms |
high_performance | Maximum throughput | true | 500 | 2000ms |
low_latency | Real-time systems | true | 10 | 50ms |
4. Builder Pattern with Validation
class logger_builder {
public:
std::unique_ptr<base_writer> writer);
result<std::unique_ptr<logger>>
build();
};
}
logger_builder & with_min_level(log_level level)
logger_builder & use_template(const std::string &name)
common::VoidResult validate() const
Validate current configuration without building.
logger_builder & with_standalone_backend()
Use standalone backend explicitly.
logger_builder & with_backend(std::unique_ptr< backends::integration_backend > backend)
Set integration backend explicitly.
logger_builder & with_async(bool async=true)
result< std::unique_ptr< logger > > build()
logger_builder & add_writer(const std::string &name, log_writer_ptr writer)
Add a writer to the logger.
logger_builder & with_buffer_size(std::size_t size)
Set buffer size.
@ size
Rotate based on file size only.
5. Backend Abstraction
The v3.0 architecture introduces a backend abstraction layer for flexible async processing:
class integration_backend {
public:
virtual common::interfaces::log_level to_common_level(
logger_system::log_level level) const = 0;
virtual logger_system::log_level from_common_level(
common::interfaces::log_level level) const = 0;
};
class standalone_backend : public integration_backend {
};
class thread_system_backend : public integration_backend {
};
}
virtual ~integration_backend()=default
Virtual destructor.
6. Interface Segregation
Clean separation of concerns through dedicated interfaces:
Writer Interface
class log_writer_interface {
public:
};
}
virtual bool is_healthy() const =0
Check if the writer is healthy.
virtual common::VoidResult flush()=0
Flush any buffered data.
virtual ~log_writer_interface()=default
virtual common::VoidResult write(const log_entry &entry)=0
Write a log entry.
Filter Interface
class log_filter_interface {
public:
virtual bool should_log(
const log_entry& entry)
const = 0;
};
}
virtual ~log_filter_interface()=default
virtual bool should_log(const log_entry &entry) const =0
Check if a log entry should be processed.
Formatter Interface
class log_formatter_interface {
public:
virtual std::string
format(
const log_entry& entry)
const = 0;
};
}
7. Log Entry Structure
Unified data structure for all logging operations:
struct log_entry {
logger_system::log_level
level;
std::string file;
int line;
std::string function;
std::chrono::system_clock::time_point
timestamp;
std::unordered_map<std::string, std::string> context;
};
}
std::optional< small_string_64 > thread_id
Optional thread identifier.
log_level level
Severity level of the log message.
small_string_256 message
The actual log message.
std::chrono::system_clock::time_point timestamp
Timestamp when the log entry was created.
Advanced Features
1. Asynchronous Pipeline
The async mode (default) uses a sophisticated pipeline:
┌──────────────┐ ┌──────────────────┐ ┌──────────────┐
│ Producer │ │ async_worker │ │ Writers │
│ (Caller) │───▶│ (std::jthread) │───▶│ │
│ │ │ │ │ │
│ Non-blocking │ │ • Lock-free │ │ • Console │
│ enqueue │ │ dequeue │ │ • File │
│ │ │ • Batch process │ │ • Network │
└──────────────┘ └──────────────────┘ └──────────────┘
Key Components:
- Producer Side: Non-blocking enqueue with overflow policies
- Consumer Side:
async_worker using std::jthread (standalone mode)
- Queue Management: Thread-safe queue with configurable overflow policies
- Batch Processing: Intelligent batching for I/O efficiency
2. Error Handling with Result Pattern
Uses common::Result<T> and common::VoidResult from common_system:
return common::make_error<void>(
common::ErrorCategory::Logger,
static_cast<int>(logger_error_code::queue_full),
"Queue is full"
);
auto result =
logger->log(level, message);
if (!result) {
std::cerr << "Error: " << result.error().message() << "\n";
}
3. C++20 Source Location
Automatic source location capture using common::source_location:
logger->log(common::interfaces::log_level::info,
"Debug message");
logger->log(common::interfaces::log_level::info,
"Message",
common::source_location::current());
4. Performance Monitoring
Built-in metrics collection:
class logger_performance_stats {
public:
uint64_t get_dropped_messages() const;
uint64_t get_total_messages() const;
uint64_t get_error_count() const;
};
}
5. Configuration Strategies
Flexible configuration management with strategy pattern:
logger_builder().for_environment(deployment_env::production);
logger_builder().with_performance_tuning(performance_level::high_throughput);
logger_builder().auto_configure();
logger_builder()
.for_environment(deployment_env::production)
.with_performance_tuning(performance_level::balanced)
.auto_configure();
Threading Model
Synchronous Mode
- Execution: Direct write to all registered writers
- Blocking: Waits for I/O completion
- Use Cases: Low-frequency logging, critical errors, simple applications
Asynchronous Mode (Default)
- Execution: Non-blocking enqueue, background processing via
std::jthread
- Throughput: High-volume logging capability (4.34M msg/s)
- Use Cases: High-frequency logging, performance-critical applications
Thread Safety Guarantees
- All public methods are thread-safe
- Writers are called sequentially (no concurrent writes to same writer)
- Internal state protected by atomic operations
- PIMPL idiom provides ABI stability
Memory Management
Buffer Management
- Configurable buffer sizes with validation
- Efficient memory usage with move semantics
- Pre-allocated buffers in async mode
- Smart overflow handling policies
Object Lifetime
- RAII principles throughout
- Unique ownership via
std::unique_ptr for writers
- Shared ownership via
std::shared_ptr where appropriate
- Clear ownership semantics
Performance Characteristics
Benchmarks (v3.0)
Platform: Apple M1 (8-core) @ 3.2GHz, 16GB RAM, macOS Sonoma
| Mode | Operation | Latency | Throughput | Memory |
| Async (standalone) | Enqueue | ~148ns | 4.34M msg/s | ~2MB base |
| Async (thread_sys) | Enqueue | ~140ns | 4.34M msg/s | ~2.5MB base |
| Sync | Direct write | ~100μs | I/O limited | Minimal |
Multi-threaded Performance
| Threads | Standalone | With thread_system |
| 1 | 4.34M msg/s | 4.34M msg/s |
| 4 | 1.07M msg/s | 1.15M msg/s |
| 8 | 412K msg/s | 450K msg/s |
| 16 | 390K msg/s | 420K msg/s |
Optimization Strategies
- String Operations: Minimized allocations, move semantics
- Batch Processing: Adaptive batching for I/O efficiency
- Lock Contention: Minimized through careful design
- Cache Performance: Data structure layout optimization
Integration Patterns
ILogger Interface Integration
.
add_writer(
"console", std::make_unique<console_writer>())
.value();
common::interfaces::ILogger* ilogger =
logger.get();
ilogger->log(common::interfaces::log_level::info, "Application started");
Builder pattern for logger construction with validation.
High-performance, thread-safe logging system with asynchronous capabilities.
Builder pattern implementation for flexible logger configuration kcenon.
Dependency Injection
class MyService {
public:
MyService(std::shared_ptr<common::interfaces::ILogger>
logger)
: logger_(std::move(
logger)) {}
void do_work() {
logger_->log(common::interfaces::log_level::debug, "Processing...");
}
private:
std::shared_ptr<common::interfaces::ILogger> logger_;
};
With Monitoring (Phase 2.2.4)
auto monitor = std::make_shared<monitoring::monitoring>();
.value();
logger_builder & with_monitoring(std::shared_ptr< common::interfaces::IMonitor > monitor)
Set monitoring interface (Phase 2.2.4)
logger_builder & with_health_check_interval(std::chrono::milliseconds interval)
Set health check interval.
Extension Points
Custom Writers
public:
}
}
};
.
add_writer(
"database", std::make_unique<database_writer>(connection))
Base interface for all log writers and decorators.
Represents a single log entry with all associated metadata.
Custom Filters
public:
: pattern_(pattern) {}
return std::regex_search(entry.
message, pattern_);
}
private:
std::regex pattern_;
};
Interface for log filters.
Filter logs by regex pattern.
Custom Formatters
public:
}
};
constexpr const char * to_string(writer_category cat) noexcept
Get string representation of writer category.
Future Enhancements
Performance Improvements
- Lock-free Queue: True lock-free MPMC queue implementation
- SIMD Optimizations: Vectorized string operations
- Memory Pool: Custom allocators for frequent allocations
Feature Additions
- Distributed Tracing: Trace ID propagation
- Log Aggregation: Built-in sampling and aggregation
- Compression: Compressed network and file writers
- Encryption: Secure audit logging
Platform Extensions
- Windows Event Log: Native Windows event log support
- syslog Integration: RFC 5424 compliant syslog
- Cloud Logging: AWS CloudWatch, GCP Logging adapters
Best Practices
For Library Users
- Use async mode (default) for production systems
- Leverage C++20 source_location for automatic location capture
- Use
is_enabled() check before expensive message construction
- Configure appropriate buffer sizes based on load
- Monitor metrics for performance tuning
- Use ILogger interface for dependency injection
For Contributors
- Maintain thread safety guarantees
- Follow RAII principles consistently
- Use move semantics for efficiency
- Document performance implications of changes
- Write comprehensive tests for new features
- Ensure backward compatibility with native API
Platform Notes
- Linux/macOS: Full support for all features
- Windows: Core features supported, network components require WinSock initialization
- Cross-platform: CMake build system with feature detection
- C++ Standard: Requires C++20 (for Concepts and source_location)
- Dependencies: common_system (required), thread_system (optional)
Last Updated: 2025-12-10