Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
kcenon::logger::logger_config Struct Reference

Configuration structure for logger with validation. More...

#include <logger_config.h>

Collaboration diagram for kcenon::logger::logger_config:
Collaboration graph

Public Attributes

Basic settings
bool async = true
 Enable asynchronous logging.
 
std::size_t buffer_size = 8192
 Internal buffer size in bytes.
 
log_level min_level = log_level::info
 Minimum log level to process.
 
Performance settings
std::size_t batch_size = 100
 Number of messages per batch write.
 
std::chrono::milliseconds flush_interval {1000}
 Interval between automatic flushes.
 
bool use_lock_free = false
 Use lock-free queue implementation.
 
std::size_t max_writers = 10
 Maximum number of concurrent writers.
 
bool enable_batch_writing = false
 Enable batch writing mode.
 
Feature flags
bool enable_metrics = false
 Enable performance metrics collection.
 
bool enable_crash_handler = false
 Enable crash signal handler.
 
bool enable_structured_logging = false
 Enable structured (JSON) log output.
 
bool enable_color_output = true
 Enable ANSI color output.
 
bool enable_timestamp = true
 Include timestamp in log entries.
 
bool enable_source_location = false
 Include source file/line in log entries.
 
File output settings
std::size_t max_file_size = 100 * 1024 * 1024
 Maximum file size in bytes (default: 100MB).
 
std::size_t max_file_count = 5
 Maximum number of rotating log files.
 
std::string log_directory = "./logs"
 Directory for log file output.
 
std::string log_file_prefix = "app"
 Prefix for log file names.
 
Network settings
std::string remote_host = ""
 Remote log collector hostname.
 
uint16_t remote_port = 0
 Remote log collector port.
 
std::chrono::milliseconds network_timeout {5000}
 Network operation timeout.
 
std::size_t network_retry_count = 3
 Number of network retry attempts.
 

Queue settings

enum class  overflow_policy { drop_oldest , drop_newest , block , grow }
 Policy for handling queue overflow when max_queue_size is reached. More...
 
std::size_t max_queue_size = 10000
 Maximum number of queued messages.
 
overflow_policy queue_overflow_policy = overflow_policy::drop_newest
 Active overflow policy.
 

Performance tuning

std::size_t writer_thread_count = 1
 Number of dedicated writer threads.
 
bool enable_compression = false
 Enable log compression.
 
common::VoidResult validate () const
 Validate the configuration.
 
static logger_config default_config ()
 Create a default configuration.
 
static logger_config high_performance ()
 Create a high-performance configuration.
 
static logger_config low_latency ()
 Create a low-latency configuration.
 
static logger_config debug_config ()
 Create a debug configuration.
 
static logger_config production ()
 Create a production configuration.
 

Detailed Description

Configuration structure for logger with validation.

This structure holds all configuration parameters for the logger and provides validation to ensure configuration correctness.

Definition at line 35 of file logger_config.h.

Member Enumeration Documentation

◆ overflow_policy

Policy for handling queue overflow when max_queue_size is reached.

Enumerator
drop_oldest 

Drop oldest messages when queue is full.

drop_newest 

Drop new messages when queue is full (default).

block 

Block until space is available.

grow 

Dynamically grow the queue (use with caution).

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 69 of file logger_config.h.

69 {
72 block,
73 grow
74 };
@ drop_newest
Drop new messages when queue is full (default).
@ block
Block until space is available.
@ grow
Dynamically grow the queue (use with caution).
@ drop_oldest
Drop oldest messages when queue is full.

Member Function Documentation

◆ debug_config()

static logger_config kcenon::logger::logger_config::debug_config ( )
inlinestatic

Create a debug configuration.

Returns
Configuration optimized for debugging
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 264 of file logger_config.h.

264 {
265 logger_config config;
266 config.async = false; // Synchronous for immediate output
267 config.min_level = log_level::trace;
268 config.enable_metrics = true;
269 config.enable_crash_handler = true;
270 config.enable_color_output = true;
271 config.batch_size = 1;
272 config.flush_interval = std::chrono::milliseconds(0);
273 return config;
274 }

References async, batch_size, enable_color_output, enable_crash_handler, enable_metrics, flush_interval, and min_level.

Referenced by kcenon::logger::logger_config_builder::use_debug_defaults(), and kcenon::logger::logger_builder::use_template().

Here is the caller graph for this function:

◆ default_config()

static logger_config kcenon::logger::logger_config::default_config ( )
inlinestatic

Create a default configuration.

Returns
Default logger configuration
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 222 of file logger_config.h.

222 {
223 return logger_config{};
224 }

Referenced by kcenon::logger::logger_config_builder::use_default_config(), and kcenon::logger::logger_builder::use_template().

Here is the caller graph for this function:

◆ high_performance()

static logger_config kcenon::logger::logger_config::high_performance ( )
inlinestatic

Create a high-performance configuration.

Returns
Configuration optimized for performance
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 230 of file logger_config.h.

230 {
231 logger_config config;
232 config.async = true;
233 config.buffer_size = 65536;
234 config.batch_size = 500;
235 config.flush_interval = std::chrono::milliseconds(5000);
236 config.use_lock_free = true;
237 config.max_queue_size = 100000;
238 config.writer_thread_count = 2;
239 config.enable_compression = true;
240 config.enable_batch_writing = true;
241 return config;
242 }

References async, batch_size, buffer_size, enable_batch_writing, enable_compression, flush_interval, max_queue_size, use_lock_free, and writer_thread_count.

Referenced by kcenon::logger::logger_config_builder::use_high_performance_defaults(), and kcenon::logger::logger_builder::use_template().

Here is the caller graph for this function:

◆ low_latency()

static logger_config kcenon::logger::logger_config::low_latency ( )
inlinestatic

Create a low-latency configuration.

Returns
Configuration optimized for low latency
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 248 of file logger_config.h.

248 {
249 logger_config config;
250 config.async = true;
251 config.buffer_size = 4096;
252 config.batch_size = 10;
253 config.flush_interval = std::chrono::milliseconds(10);
254 config.use_lock_free = true;
255 config.max_queue_size = 10000;
256 config.queue_overflow_policy = overflow_policy::drop_oldest;
257 return config;
258 }

References async, batch_size, buffer_size, flush_interval, max_queue_size, queue_overflow_policy, and use_lock_free.

Referenced by kcenon::logger::logger_config_builder::use_low_latency_defaults(), and kcenon::logger::logger_builder::use_template().

Here is the caller graph for this function:

◆ production()

static logger_config kcenon::logger::logger_config::production ( )
inlinestatic

Create a production configuration.

Returns
Configuration optimized for production use
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 280 of file logger_config.h.

280 {
281 logger_config config;
282 config.async = true;
283 config.buffer_size = 16384;
284 config.min_level = log_level::warning;
285 config.enable_metrics = true;
286 config.enable_crash_handler = true;
287 config.enable_color_output = false;
288 config.max_file_size = 500 * 1024 * 1024; // 500MB
289 config.max_file_count = 10;
290 config.enable_compression = true;
291 config.enable_batch_writing = true;
292 config.batch_size = 200;
293 return config;
294 }

References async, batch_size, buffer_size, enable_batch_writing, enable_color_output, enable_compression, enable_crash_handler, enable_metrics, max_file_count, max_file_size, and min_level.

Referenced by kcenon::logger::logger_config_builder::use_production_defaults(), and kcenon::logger::logger_builder::use_template().

Here is the caller graph for this function:

◆ validate()

common::VoidResult kcenon::logger::logger_config::validate ( ) const
inline

Validate the configuration.

Returns
common::VoidResult indicating success or specific validation error
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 103 of file logger_config.h.

103 {
104 // Validate buffer size
105 if (buffer_size == 0) {
107 "Buffer size must be greater than 0");
108 }
109
110 if (buffer_size > std::numeric_limits<std::size_t>::max() / 2) {
112 "Buffer size is too large");
113 }
114
115 // Validate batch size
116 if (batch_size == 0) {
118 "Batch size must be greater than 0");
119 }
120
121 if (batch_size > buffer_size) {
123 "Batch size cannot exceed buffer size");
124 }
125
126 // Validate flush interval
127 if (flush_interval.count() < 0) {
129 "Flush interval must be non-negative");
130 }
131
132 if (flush_interval.count() > 3600000) { // 1 hour max
134 "Flush interval too large (max 1 hour)");
135 }
136
137 // Validate queue settings
138 if (max_queue_size == 0) {
140 "Max queue size must be greater than 0");
141 }
142
145 "Max queue size must be at least as large as batch size");
146 }
147
148 // Validate file settings
149 if (max_file_size < 1024) { // Minimum 1KB
151 "Max file size too small (minimum 1KB)");
152 }
153
154 if (max_file_count == 0) {
156 "Max file count must be greater than 0");
157 }
158
159 if (max_file_count > 1000) {
161 "Max file count too large (max 1000)");
162 }
163
164 // Validate network settings if configured
165 if (!remote_host.empty()) {
166 if (remote_port == 0) {
168 "Remote port must be specified when remote host is set");
169 }
170
171 if (network_timeout.count() <= 0) {
173 "Network timeout must be positive");
174 }
175
176 if (network_retry_count > 100) {
178 "Network retry count too large (max 100)");
179 }
180 }
181
182 // Validate writer settings
183 if (max_writers == 0) {
185 "Must allow at least one writer");
186 }
187
188 if (max_writers > 100) {
190 "Max writers too large (max 100)");
191 }
192
193 // Validate thread count
194 if (writer_thread_count == 0) {
196 "Writer thread count must be at least 1");
197 }
198
199 if (writer_thread_count > 32) {
201 "Writer thread count too large (max 32)");
202 }
203
204 // Validate feature combinations
205 if (use_lock_free && queue_overflow_policy == overflow_policy::grow) {
207 "Lock-free queue cannot use grow overflow policy");
208 }
209
210 if (!async && batch_size > 1) {
212 "Batch processing requires async mode");
213 }
214
215 return common::ok();
216 }
VoidResult ok()
common::VoidResult make_logger_void_result(logger_error_code code, const std::string &message="")
std::size_t batch_size
Number of messages per batch write.
std::size_t network_retry_count
Number of network retry attempts.
std::size_t writer_thread_count
Number of dedicated writer threads.
std::size_t max_file_size
Maximum file size in bytes (default: 100MB).
bool async
Enable asynchronous logging.
std::chrono::milliseconds network_timeout
Network operation timeout.
overflow_policy queue_overflow_policy
Active overflow policy.
std::string remote_host
Remote log collector hostname.
std::chrono::milliseconds flush_interval
Interval between automatic flushes.
std::size_t buffer_size
Internal buffer size in bytes.
uint16_t remote_port
Remote log collector port.
std::size_t max_writers
Maximum number of concurrent writers.
std::size_t max_file_count
Maximum number of rotating log files.
bool use_lock_free
Use lock-free queue implementation.
std::size_t max_queue_size
Maximum number of queued messages.

References async, batch_size, buffer_size, flush_interval, kcenon::logger::invalid_configuration, kcenon::logger::make_logger_void_result(), max_file_count, max_file_size, max_queue_size, max_writers, network_retry_count, network_timeout, kcenon::common::ok(), queue_overflow_policy, remote_host, remote_port, use_lock_free, and writer_thread_count.

Referenced by kcenon::logger::logger_builder::build(), kcenon::logger::logger_config_builder::build(), and kcenon::logger::logger_builder::validate().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ async

◆ batch_size

◆ buffer_size

◆ enable_batch_writing

◆ enable_color_output

◆ enable_compression

◆ enable_crash_handler

◆ enable_metrics

◆ enable_source_location

◆ enable_structured_logging

◆ enable_timestamp

bool kcenon::logger::logger_config::enable_timestamp = true

◆ flush_interval

◆ log_directory

std::string kcenon::logger::logger_config::log_directory = "./logs"

◆ log_file_prefix

std::string kcenon::logger::logger_config::log_file_prefix = "app"

◆ max_file_count

◆ max_file_size

◆ max_queue_size

◆ max_writers

std::size_t kcenon::logger::logger_config::max_writers = 10

◆ min_level

◆ network_retry_count

std::size_t kcenon::logger::logger_config::network_retry_count = 3

Number of network retry attempts.

Definition at line 91 of file logger_config.h.

Referenced by kcenon::logger::logger_config_builder::set_network_retry_count(), and validate().

◆ network_timeout

std::chrono::milliseconds kcenon::logger::logger_config::network_timeout {5000}

◆ queue_overflow_policy

◆ remote_host

std::string kcenon::logger::logger_config::remote_host = ""

◆ remote_port

◆ use_lock_free

◆ writer_thread_count

std::size_t kcenon::logger::logger_config::writer_thread_count = 1

The documentation for this struct was generated from the following file: