|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
doc_id: "LOG-GUID-001a" doc_title: "Configuration Strategies - Basic" doc_version: "1.0.0" doc_date: "2026-04-04" doc_status: "Released" project: "logger_system"
Split from: CONFIGURATION_STRATEGIES.md
logger_system Configuration Strategies (include/kcenon/logger/core/strategies/)
The configuration strategies framework provides a flexible, composable approach to logger configuration using the Strategy Pattern. Strategies allow dynamic adaptation of logger behavior based on environment, performance requirements, or deployment context.
Configuration strategies are reusable, composable configuration profiles that encapsulate logger settings for specific contexts:
Evaluation flow:
| Benefit | Description |
|---|---|
| Separation of Concerns | Decouple configuration logic from logger implementation |
| Composability | Combine multiple strategies for complex requirements |
| Reusability | Share configurations across projects/services |
| Testability | Mock strategies for unit tests |
| Dynamic Configuration | Change behavior at runtime based on context |
Result: Same codebase, different behaviors without conditional logic.
Header: include/kcenon/logger/core/strategies/config_strategy_interface.h
get_name()Purpose: Identifies the strategy for debugging/logging.
Returns: Human-readable name (e.g., "deployment:production", "environment", "performance:high_throughput").
Example:
apply(logger_config& config)Purpose: Modifies the logger configuration according to the strategy's rules.
Parameters:
config – The configuration to modify (in-place modification)Behavior:
config fields (e.g., config.async = true)config)Example:
is_applicable()Purpose: Conditional strategy application based on runtime context.
Returns: true if the strategy should be applied, false to skip.
Default: Returns true (always applicable).
Override example:
Use case: Environment-dependent strategies (e.g., only apply cloud config if deployed to AWS).
priority()Purpose: Determines application order when multiple strategies are used.
Returns: Integer priority value (higher = applied first).
Default: Returns 0.
Built-in priorities:
environment_strategy: 100 (highest – environment variables override everything)deployment_strategy: 75performance_strategy: 50Conflict resolution: Later strategies (lower priority) override earlier ones (higher priority).
Header: include/kcenon/logger/core/strategies/deployment_strategy.h
Purpose: Pre-configured settings for different deployment environments.
deployment_env::development)Target: Local development, debugging
| Setting | Value | Rationale |
|---|---|---|
async | false | Synchronous for immediate console feedback |
min_level | log_level::trace | Verbose for debugging |
enable_color_output | true | Colorful console output |
enable_source_location | true | File:line for debugging |
enable_structured_logging | false | Human-readable text format |
batch_size | 1 | No batching (immediate output) |
flush_interval | 0ms | Immediate flush |
enable_metrics | true | Performance monitoring |
enable_crash_handler | true | Crash dump logs |
Example:
deployment_env::staging)Target: Pre-production testing, integration environment
| Setting | Value | Rationale |
|---|---|---|
async | true | Async for performance testing |
min_level | log_level::info | Moderate verbosity |
enable_color_output | false | No colors (file output) |
enable_structured_logging | true | JSON for log aggregation |
buffer_size | 16384 (16KB) | Moderate buffer |
batch_size | 100 | Batch processing |
flush_interval | 1000ms | 1-second flush |
max_file_size | 50MB | File rotation at 50MB |
max_file_count | 5 | Keep 5 rotated files |
enable_batch_writing | true | Batch writes for efficiency |
Example:
deployment_env::production)Target: Production deployment, high-performance
| Setting | Value | Rationale |
|---|---|---|
async | true | Non-blocking logging |
min_level | log_level::warn | Errors/warnings only |
enable_color_output | false | No colors |
enable_source_location | false | Reduce overhead |
enable_structured_logging | true | JSON for SIEM integration |
buffer_size | 32768 (32KB) | Large buffer |
batch_size | 200 | Large batches |
flush_interval | 2000ms | 2-second flush |
max_file_size | 100MB | Large files |
max_file_count | 10 | Keep 10 rotated files |
enable_compression | true | Compress logs (gzip) |
enable_batch_writing | true | Batch writes |
queue_overflow_policy | drop_oldest | Drop old logs on overflow |
Example:
deployment_env::testing)Target: Unit tests, integration tests
| Setting | Value | Rationale |
|---|---|---|
async | false | Synchronous (deterministic) |
min_level | log_level::trace | Capture everything |
enable_metrics | false | No overhead |
enable_crash_handler | false | No crash handling (let tests fail) |
enable_color_output | false | No colors (text assertions) |
enable_source_location | true | Debugging test failures |
batch_size | 1 | No batching (deterministic) |
flush_interval | 0ms | Immediate flush |
Example:
Constructor:
Priority: 75 (higher than performance, lower than environment)
Example Usage:
Header: include/kcenon/logger/core/strategies/environment_strategy.h
Purpose: Configure logger via environment variables (12-factor app pattern).
| Variable | Type | Description | Example |
|---|---|---|---|
LOG_LEVEL | string | Log level (trace, debug, info, warn, error, fatal) | LOG_LEVEL=warn |
LOG_ASYNC | bool | Async mode | LOG_ASYNC=true |
LOG_BUFFER_SIZE | size_t | Buffer size in bytes | LOG_BUFFER_SIZE=65536 |
LOG_BATCH_SIZE | size_t | Batch size for processing | LOG_BATCH_SIZE=200 |
LOG_FLUSH_INTERVAL | size_t | Flush interval in milliseconds | LOG_FLUSH_INTERVAL=1000 |
LOG_COLOR | bool | Enable color output | LOG_COLOR=false |
LOG_METRICS | bool | Enable metrics collection | LOG_METRICS=true |
LOG_STRUCTURED | bool | Enable structured logging (JSON) | LOG_STRUCTURED=true |
LOG_CRASH_HANDLER | bool | Enable crash handler | LOG_CRASH_HANDLER=true |
LOG_MAX_QUEUE_SIZE | size_t | Max queue size (async mode) | LOG_MAX_QUEUE_SIZE=50000 |
LOG_BATCH_WRITING | bool | Enable batch writing | LOG_BATCH_WRITING=true |
Boolean parsing: Accepts true/false, 1/0, yes/no, on/off (case-insensitive).
Constructor:
Priority: 100 (highest – environment variables override all other strategies)
Applicability: Only applicable if at least one environment variable is set.
Example Usage:
Dockerfile:
Kubernetes ConfigMap:
Deployment:
Result: Application automatically picks up configuration from environment without code changes.
Header: include/kcenon/logger/core/strategies/performance_strategy.h
Purpose: Pre-configured performance tuning profiles.
performance_level::low_latency)Target: Real-time systems, interactive applications
Goal: Minimize time from log call to output
| Setting | Value | Rationale |
|---|---|---|
async | true | Non-blocking log calls |
buffer_size | 4096 (4KB) | Small buffer (fast flush) |
batch_size | 10 | Small batches (low latency) |
flush_interval | 10ms | Very frequent flush |
use_lock_free | true | Lock-free queue (reduce contention) |
max_queue_size | 10000 | Moderate queue |
queue_overflow_policy | drop_oldest | Drop old logs (maintain throughput) |
enable_batch_writing | false | No batching (immediate write) |
Use case: Financial trading systems, real-time dashboards
Tradeoff: Higher CPU usage, lower throughput
performance_level::balanced)Target: General-purpose applications
Goal: Good performance without extreme tuning
| Setting | Value | Rationale |
|---|---|---|
async | true | Non-blocking |
buffer_size | 8192 (8KB) | Moderate buffer |
batch_size | 100 | Moderate batching |
flush_interval | 1000ms | 1-second flush |
use_lock_free | false | Standard mutex (simpler) |
max_queue_size | 10000 | Moderate queue |
queue_overflow_policy | drop_newest | Drop new logs (preserve history) |
enable_batch_writing | true | Batch writes |
Use case: Web servers, microservices, general applications
Tradeoff: Balanced latency and throughput
performance_level::high_throughput)Target: High-traffic systems, data pipelines
Goal: Maximize logs/second
| Setting | Value | Rationale |
|---|---|---|
async | true | Non-blocking |
buffer_size | 65536 (64KB) | Large buffer |
batch_size | 500 | Large batches |
flush_interval | 5000ms | 5-second flush |
use_lock_free | true | Lock-free queue |
max_queue_size | 100000 | Large queue |
queue_overflow_policy | drop_oldest | Drop old logs |
writer_thread_count | 2 | Multi-threaded writing |
enable_compression | true | Compress logs (reduce I/O) |
enable_batch_writing | true | Batch writes |
Use case: Log aggregation servers, big data pipelines, analytics platforms
Tradeoff: Higher latency (up to 5 seconds), high memory usage
performance_level::minimal_overhead)Target: Embedded systems, resource-constrained environments
Goal: Minimize CPU and memory usage
| Setting | Value | Rationale |
|---|---|---|
async | true | Non-blocking (offload work) |
buffer_size | 4096 (4KB) | Small buffer |
batch_size | 50 | Moderate batching |
flush_interval | 2000ms | 2-second flush |
enable_metrics | false | No metrics (reduce overhead) |
enable_structured_logging | false | Simple text format |
enable_source_location | false | No file:line info |
enable_color_output | false | No colors |
enable_batch_writing | true | Batch writes |
Use case: IoT devices, embedded systems, Raspberry Pi
Tradeoff: Fewer features, simpler logs
Constructor:
Priority: 50 (medium priority)
Example Usage:
Last updated: 2025-02-09 logger_system version: 2.x