Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
performance_strategy.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
20#include "../logger_config.h"
21
22namespace kcenon::logger {
23
34
45public:
51 : level_(level) {}
52
53 std::string get_name() const override {
54 return "performance:" + level_to_string(level_);
55 }
56
57 void apply(logger_config& config) const override {
58 switch (level_) {
60 apply_low_latency(config);
61 break;
63 apply_balanced(config);
64 break;
67 break;
70 break;
71 }
72 }
73
74 int priority() const override {
75 return 50; // Medium priority
76 }
77
78private:
80
81 static void apply_low_latency(logger_config& config) {
82 config.async = true;
83 config.buffer_size = 4096;
84 config.batch_size = 10;
85 config.flush_interval = std::chrono::milliseconds(10);
86 config.use_lock_free = true;
87 config.max_queue_size = 10000;
88 config.queue_overflow_policy = logger_config::overflow_policy::drop_oldest;
89 config.enable_batch_writing = false;
90 }
91
92 static void apply_balanced(logger_config& config) {
93 config.async = true;
94 config.buffer_size = 8192;
95 config.batch_size = 100;
96 config.flush_interval = std::chrono::milliseconds(1000);
97 config.use_lock_free = false;
98 config.max_queue_size = 10000;
99 config.queue_overflow_policy = logger_config::overflow_policy::drop_newest;
100 config.enable_batch_writing = true;
101 }
102
104 config.async = true;
105 config.buffer_size = 65536;
106 config.batch_size = 500;
107 config.flush_interval = std::chrono::milliseconds(5000);
108 config.use_lock_free = true;
109 config.max_queue_size = 100000;
110 config.queue_overflow_policy = logger_config::overflow_policy::drop_oldest;
111 config.writer_thread_count = 2;
112 config.enable_compression = true;
113 config.enable_batch_writing = true;
114 }
115
117 config.async = true;
118 config.buffer_size = 4096;
119 config.batch_size = 50;
120 config.flush_interval = std::chrono::milliseconds(2000);
121 config.enable_metrics = false;
122 config.enable_structured_logging = false;
123 config.enable_source_location = false;
124 config.enable_color_output = false;
125 config.enable_batch_writing = true;
126 }
127
128 static std::string level_to_string(performance_level level) {
129 switch (level) {
130 case performance_level::low_latency: return "low_latency";
131 case performance_level::balanced: return "balanced";
132 case performance_level::high_throughput: return "high_throughput";
133 case performance_level::minimal_overhead: return "minimal_overhead";
134 default: return "unknown";
135 }
136 }
137};
138
139} // namespace kcenon::logger
Abstract interface for logger configuration strategies.
Configuration strategy for performance tuning.
int priority() const override
Get the strategy priority.
performance_strategy(performance_level level)
Constructor with performance level.
static void apply_balanced(logger_config &config)
std::string get_name() const override
Get the strategy name.
static std::string level_to_string(performance_level level)
void apply(logger_config &config) const override
Apply this strategy to a logger configuration.
static void apply_low_latency(logger_config &config)
static void apply_minimal_overhead(logger_config &config)
static void apply_high_throughput(logger_config &config)
Interface for logger configuration strategies (Strategy Pattern)
Configuration structure for logger with validation.
performance_level
Performance tuning presets.
@ high_throughput
Maximize throughput (large buffers, batch processing)
@ minimal_overhead
Minimize resource usage (simple format, less features)
@ low_latency
Minimize latency (small buffers, immediate flush)
@ balanced
Balanced configuration (default)
Configuration structure for logger with validation.
std::size_t batch_size
Number of messages per batch write.
std::size_t writer_thread_count
Number of dedicated writer threads.
bool enable_batch_writing
Enable batch writing mode.
bool async
Enable asynchronous logging.
bool enable_color_output
Enable ANSI color output.
overflow_policy queue_overflow_policy
Active overflow policy.
bool enable_source_location
Include source file/line in log entries.
bool enable_compression
Enable log compression.
bool enable_metrics
Enable performance metrics collection.
std::chrono::milliseconds flush_interval
Interval between automatic flushes.
std::size_t buffer_size
Internal buffer size in bytes.
bool use_lock_free
Use lock-free queue implementation.
std::size_t max_queue_size
Maximum number of queued messages.
bool enable_structured_logging
Enable structured (JSON) log output.