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

Namespaces

namespace  adapters
 
namespace  analysis
 
namespace  async
 
namespace  backends
 
namespace  core
 
namespace  detail
 
namespace  filters
 
namespace  formatters
 
namespace  integration
 
namespace  memory
 
namespace  metrics
 
namespace  monitoring
 
namespace  otlp
 
namespace  routing
 
namespace  safety
 
namespace  sampling
 
namespace  security
 
namespace  server
 
namespace  sinks
 
namespace  strategies
 
namespace  structured
 
namespace  utils
 

Classes

class  async_writer
 Asynchronous wrapper for log writers. More...
 
interface  async_writer_tag
 Tag interface for asynchronous writers. More...
 
class  base_formatter
 Base implementation for log formatters. More...
 
class  base_writer
 Abstract base class for all log output writers. More...
 
class  basic_monitor
 Basic monitoring implementation. More...
 
class  batch_writer
 Batch writer that accumulates log entries and writes them in batches. More...
 
class  buffered_writer
 Decorator that buffers log entries before writing to wrapped writer. More...
 
class  compact_formatter
 Compact formatter for minimal output. More...
 
class  composite_filter
 Combine multiple filters with AND/OR logic. More...
 
class  composite_strategy
 Combines multiple configuration strategies. More...
 
class  composite_writer
 Coordinates formatting and output through a pipeline. More...
 
interface  composite_writer_tag
 Tag interface for composite writers. More...
 
class  config_strategy_interface
 Abstract interface for logger configuration strategies. More...
 
class  console_sink
 Outputs log messages to console (stdout or stderr) More...
 
class  console_writer
 Core console writer for logging to stdout/stderr. More...
 
class  critical_writer
 Synchronous wrapper ensuring critical logs are never lost. More...
 
struct  critical_writer_config
 Configuration for critical log writer. More...
 
class  decorator_writer_base
 Abstract base class for decorator pattern log writers. More...
 
interface  decorator_writer_tag
 Tag interface for decorator writers. More...
 
class  deployment_strategy
 Configuration strategy based on deployment environment. More...
 
struct  encrypted_log_header
 Header prepended to each encrypted log entry. More...
 
class  encrypted_writer
 Decorator that encrypts log data before writing. More...
 
struct  encryption_config
 Configuration for encrypted_writer. More...
 
class  environment_strategy
 Configuration strategy based on environment variables. More...
 
class  file_sink
 Writes log messages to a file. More...
 
class  file_writer
 Core file writer for logging to files. More...
 
class  filter_factory
 Factory for creating log filter instances. More...
 
class  filtered_writer
 Decorator that applies a filter to a wrapped writer. More...
 
struct  format_options
 Configuration options for log formatting. More...
 
class  formatted_writer
 Decorator that applies a formatter to a wrapped writer. More...
 
class  formatter_factory
 Factory for creating log formatter instances. More...
 
class  function_filter
 Filter logs by custom function. More...
 
class  health_check_result
 Health check result. More...
 
class  hybrid_writer
 Combines async writer for normal logs with critical_writer for safety. More...
 
struct  is_async_writer
 Type trait to check if a writer is asynchronous. More...
 
struct  is_composite_writer
 Type trait to check if a writer is composite. More...
 
struct  is_decorator_writer
 Type trait to check if a writer is a decorator. More...
 
struct  is_sync_writer
 Type trait to check if a writer is synchronous. More...
 
class  json_formatter
 JSON formatter for structured logging. More...
 
class  level_filter
 Filter logs by minimum level. More...
 
class  log_collector
 Asynchronous log collector for high-performance logging. More...
 
class  log_collector_jthread_worker
 Worker thread for log processing with jthread compatibility. More...
 
struct  log_collector_shared_state
 Shared state for log processing - survives impl destruction. More...
 
class  log_context_scope
 RAII guard for structured logging context. More...
 
class  log_context_storage
 Thread-local storage for structured logging context fields. More...
 
class  log_decryptor
 Utility class for decrypting encrypted log files. More...
 
struct  log_entry
 Represents a single log entry with all associated metadata. More...
 
class  log_filter
 Base class for log filtering. More...
 
interface  log_filter_interface
 Interface for log filters. More...
 
class  log_formatter_interface
 Abstract interface for log message formatters. More...
 
interface  log_sink_interface
 Interface for log sinks. More...
 
interface  log_writer_interface
 Base interface for all log writers and decorators. More...
 
class  logfmt_formatter
 Formatter that outputs logfmt-structured log messages. More...
 
class  logger
 Main logger implementation providing high-performance logging facilities. More...
 
class  logger_builder
 Builder pattern for logger construction with validation. More...
 
struct  logger_config
 Configuration structure for logger with validation. More...
 
class  logger_config_builder
 Fluent builder for logger_config. More...
 
struct  metric_value
 Single metric value with metadata. More...
 
class  monitoring_data
 Collection of metrics. More...
 
class  monitoring_interface
 Abstract monitoring interface. More...
 
class  network_reconnect_jthread_worker
 Worker thread for reconnection attempts with jthread compatibility. More...
 
class  network_send_jthread_worker
 Worker thread for sending buffered logs with jthread compatibility. More...
 
class  network_writer
 Sends logs over network (TCP/UDP) More...
 
class  otlp_writer
 OTLP log exporter for OpenTelemetry integration. More...
 
class  output_sink_interface
 Abstract interface for log output destinations (I/O only) More...
 
class  performance_strategy
 Configuration strategy for performance tuning. More...
 
class  plain_formatter
 Simple plain text formatter. More...
 
class  queued_writer_base
 Abstract base class for queue-based log writers. More...
 
class  regex_filter
 Filter logs by regex pattern. More...
 
class  result
 
class  rotating_file_writer
 File writer with automatic log rotation support. More...
 
class  scoped_context
 Convenience class for setting a single context field with RAII. More...
 
class  scoped_context_guard
 RAII guard for automatic context management. More...
 
class  small_string
 Small String Optimization (SSO) implementation. More...
 
struct  source_location
 Source code location information for debugging. More...
 
class  structured_log_builder
 Fluent builder for creating structured log entries. More...
 
interface  sync_writer_tag
 Tag interface for synchronous writers. More...
 
class  template_formatter
 Customizable formatter using template strings with placeholders. More...
 
class  thread_safe_writer
 Base class providing automatic thread-safety for writer implementations. More...
 
class  thread_system_monitor_adapter
 Adapter to use thread_system's monitoring capabilities. More...
 
class  timestamp_formatter
 Default formatter with human-readable timestamp format. More...
 
class  unified_log_context
 Unified interface for managing all types of logging context. More...
 
class  writer_factory
 Factory for creating log writer instances. More...
 

Concepts

concept  SyncWriter
 Concept for synchronous writers.
 
concept  AsyncWriter
 Concept for asynchronous writers.
 
concept  DecoratorWriter
 Concept for decorator writers.
 
concept  CompositeWriter
 Concept for composite writers.
 

Typedefs

using error_code = logger_error_code
 
using health_status = logger_system::health_status
 
using kcenon::logger::overflow_policy = logger_system::overflow_policy
 
using logger_metrics = metrics::logger_performance_stats
 
using performance_metrics = metrics::logger_performance_stats
 
using small_string_64 = small_string<64>
 
using small_string_128 = small_string<128>
 
using small_string_256 = small_string<256>
 
using small_string_512 = small_string<512>
 
using config_strategy_factory_fn = std::function<std::unique_ptr<config_strategy_interface>()>
 Factory function type for creating configuration strategies.
 
using context_value = std::variant<std::monostate, bool, int64_t, double, std::string>
 Value type for unified context storage.
 
using log_value = std::variant<std::string, int64_t, double, bool>
 Value type for structured logging fields.
 
using log_fields = std::unordered_map<std::string, log_value>
 Type alias for structured fields map.
 
using formatter_factory = std::function<std::unique_ptr<log_formatter_interface>()>
 Factory function type for creating formatters.
 
using log_writer_ptr = std::unique_ptr<log_writer_interface>
 Type alias for writer unique pointer.
 
using output_sink_factory = std::function<std::unique_ptr<output_sink_interface>()>
 

Enumerations

enum class  logger_error_code {
  success = 0 , unknown_error = 1 , not_implemented = 2 , invalid_argument = 3 ,
  writer_not_found = 1000 , writer_initialization_failed = 1001 , writer_already_exists = 1002 , writer_not_healthy = 1003 ,
  file_open_failed = 1100 , file_write_failed = 1101 , file_rotation_failed = 1102 , file_permission_denied = 1103 ,
  network_connection_failed = 1200 , network_send_failed = 1201 , network_timeout = 1202 , buffer_overflow = 1300 ,
  queue_full = 1301 , queue_stopped = 1302 , queue_overflow_dropped = 1303 , queue_overflow_blocked = 1304 ,
  invalid_configuration = 1400 , configuration_missing = 1401 , configuration_conflict = 1402 , metrics_collection_failed = 1500 ,
  metrics_not_available = 1501 , flush_timeout = 1600 , processing_failed = 1601 , filter_error = 1602 ,
  formatter_error = 1603 , batch_processing_timeout = 1604 , batch_processing_failed = 1605 , encryption_failed = 1700 ,
  decryption_failed = 1701 , authentication_failed = 1702 , sanitization_failed = 1703 , file_read_failed = 1704 ,
  insecure_permissions = 1705 , path_traversal_detected = 1706 , invalid_key_size = 1707 , invalid_filename = 1708 ,
  di_not_available = 1800 , component_not_found = 1801 , registration_failed = 1802 , creation_failed = 1803 ,
  operation_failed = 1804 , async_operation_not_running = 1805 , async_operation_already_running = 1806 , writer_not_available = 1900 ,
  writer_configuration_error = 1901 , writer_operation_failed = 1902 , destructor_cleanup_failed = 1903
}
 Error codes specific to the logger system. More...
 
enum class  metric_type {
  gauge , counter , histogram , counter ,
  gauge , histogram , summary
}
 Types of metrics that can be recorded by the logger. More...
 
enum class  deployment_env { development , staging , production , testing }
 Deployment environment types. More...
 
enum class  performance_level { low_latency , balanced , high_throughput , minimal_overhead }
 Performance tuning presets. More...
 
enum class  context_category : uint8_t { custom = 0 , trace = 1 , request = 2 , otel = 3 }
 Categories for organizing context entries. More...
 
enum class  format_type {
  plain , json , logfmt , templated ,
  compact
}
 Pre-defined format types. More...
 
enum class  writer_category : std::uint8_t { synchronous , asynchronous , decorator , composite }
 Categories of log writers based on operational behavior. More...
 
enum class  encryption_algorithm { aes_256_gcm , aes_256_cbc , chacha20_poly1305 }
 Supported encryption algorithms for log encryption. More...
 
enum class  rotation_type { size , daily , hourly , size_and_time }
 Determines when log rotation should occur. More...
 
enum class  kcenon::logger::health_status { healthy , degraded , unhealthy , unknown }
 Health status levels. More...
 
enum class  metric_type {
  gauge , counter , histogram , counter ,
  gauge , histogram , summary
}
 Metric types for categorization. More...
 

Functions

std::string logger_error_to_string (logger_error_code code)
 Convert logger_error_code to string representation.
 
common::VoidResult make_logger_void_result (logger_error_code code, const std::string &message="")
 
common::VoidResult make_logger_void_success ()
 
logger_error_code get_logger_error_code (const common::VoidResult &result)
 
bool has_logger_error (const common::VoidResult &result)
 Check if a VoidResult contains an error.
 
std::string get_logger_error_message (const common::VoidResult &result)
 Get error message from a VoidResult.
 
template<typename T >
constexpr writer_category get_writer_category ()
 Get the primary category of a writer type.
 
constexpr const char * to_string (writer_category cat) noexcept
 Get string representation of writer category.
 
std::unique_ptr< batch_writermake_batch_writer (log_writer_ptr writer, size_t batch_size=100, std::chrono::milliseconds flush_interval=std::chrono::milliseconds{1000})
 Factory function to create a batch writer.
 
std::unique_ptr< buffered_writermake_buffered_writer (std::unique_ptr< log_writer_interface > writer, size_t max_entries=buffered_writer::DEFAULT_BUFFER_SIZE, std::chrono::milliseconds flush_interval=buffered_writer::DEFAULT_FLUSH_INTERVAL)
 Factory function to create a buffered writer.
 
std::unique_ptr< composite_writermake_composite_writer (std::unique_ptr< log_formatter_interface > formatter, std::unique_ptr< output_sink_interface > sink)
 
std::unique_ptr< filtered_writermake_filtered_writer (std::unique_ptr< log_writer_interface > writer, std::unique_ptr< log_filter_interface > filter)
 Factory function to create a filtered writer.
 
std::unique_ptr< formatted_writermake_formatted_writer (std::unique_ptr< log_writer_interface > writer, std::unique_ptr< log_formatter_interface > formatter)
 Factory function to create a formatted writer.
 
log_entry copy_log_entry (const log_entry &entry)
 Creates a copy of a log_entry for queue storage.
 
std::string health_status_to_string (health_status status)
 Convert health status to string.
 
std::string metric_type_to_string (metric_type type)
 Convert metric type to string.
 

Variables

template<typename T >
constexpr bool is_sync_writer_v = is_sync_writer<T>::value
 
template<typename T >
constexpr bool is_async_writer_v = is_async_writer<T>::value
 
template<typename T >
constexpr bool is_decorator_writer_v = is_decorator_writer<T>::value
 
template<typename T >
constexpr bool is_composite_writer_v = is_composite_writer<T>::value
 

Typedef Documentation

◆ config_strategy_factory_fn

using kcenon::logger::config_strategy_factory_fn = std::function<std::unique_ptr<config_strategy_interface>()>

Factory function type for creating configuration strategies.

Definition at line 77 of file config_strategy_interface.h.

◆ context_value

using kcenon::logger::context_value = std::variant<std::monostate, bool, int64_t, double, std::string>

Value type for unified context storage.

Supports common types used in logging context:

  • std::monostate for null/unset values
  • bool for boolean values
  • int64_t for integer values
  • double for floating-point values
  • std::string for text values
    Since
    3.3.0
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/unified_log_context.h.

Definition at line 60 of file unified_log_context.h.

◆ error_code

◆ formatter_factory

using kcenon::logger::formatter_factory = std::function<std::unique_ptr<log_formatter_interface>()>

Factory function type for creating formatters.

Can be used with dependency injection systems to create formatters dynamically.

Since
1.2.0

Definition at line 144 of file log_formatter_interface.h.

◆ health_status

◆ log_fields

◆ log_value

using kcenon::logger::log_value = std::variant<std::string, int64_t, double, bool>

Value type for structured logging fields.

Supports common types used in structured logging:

  • std::string for text values
  • int64_t for integer values (covers int, long, etc.)
  • double for floating-point values
  • bool for boolean values
    Since
    3.1.0
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/log_context_scope.h, /home/runner/work/logger_system/logger_system/include/kcenon/logger/core/structured_log_builder.h, /home/runner/work/logger_system/logger_system/include/kcenon/logger/formatters/template_formatter.h, and /home/runner/work/logger_system/logger_system/include/kcenon/logger/interfaces/log_entry.h.

Definition at line 69 of file log_entry.h.

◆ log_writer_ptr

Type alias for writer unique pointer.

Convenience alias for managing writer lifetime and ownership

Since
4.0.0
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h, and /home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/critical_writer.h.

Definition at line 151 of file log_writer_interface.h.

◆ logger_metrics

◆ output_sink_factory

using kcenon::logger::output_sink_factory = std::function<std::unique_ptr<output_sink_interface>()>

Definition at line 78 of file output_sink_interface.h.

◆ overflow_policy

◆ performance_metrics

◆ small_string_128

◆ small_string_256

◆ small_string_512

Definition at line 421 of file small_string.h.

◆ small_string_64

Definition at line 418 of file small_string.h.

Enumeration Type Documentation

◆ context_category

enum class kcenon::logger::context_category : uint8_t
strong

Categories for organizing context entries.

Context entries are categorized to enable selective clearing and querying. Each category represents a different source or purpose for the context data.

Since
3.3.0
Enumerator
custom 

User-defined custom fields.

trace 

Distributed tracing (trace_id, span_id, parent_span_id)

request 

Request metadata (request_id, correlation_id)

otel 

OpenTelemetry specific fields.

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

Definition at line 72 of file unified_log_context.h.

72 : uint8_t {
73 custom = 0,
74 trace = 1,
75 request = 2,
76 otel = 3
77};
@ trace
Distributed tracing (trace_id, span_id, parent_span_id)
@ request
Request metadata (request_id, correlation_id)
@ otel
OpenTelemetry specific fields.
@ custom
User-defined custom fields.

◆ deployment_env

enum class kcenon::logger::deployment_env
strong

Deployment environment types.

Enumerator
development 

Development environment (verbose, colorful)

staging 

Staging environment (JSON, file + console)

production 

Production environment (optimized, safe)

testing 

Testing environment (memory buffer, sync)

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

Definition at line 29 of file deployment_strategy.h.

29 {
31 staging,
33 testing
34};
@ development
Development environment (verbose, colorful)
@ staging
Staging environment (JSON, file + console)
@ testing
Testing environment (memory buffer, sync)
@ production
Production environment (optimized, safe)

◆ encryption_algorithm

Supported encryption algorithms for log encryption.

Note
AES-256-GCM is recommended as it provides both confidentiality and authenticity (AEAD - Authenticated Encryption with Associated Data).
Enumerator
aes_256_gcm 

AES-256 in GCM mode (recommended)

aes_256_cbc 

AES-256 in CBC mode (legacy support)

chacha20_poly1305 

ChaCha20-Poly1305 (modern alternative)

Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/encrypted_writer.h.

Definition at line 76 of file encrypted_writer.h.

76 {
80};
@ aes_256_gcm
AES-256 in GCM mode (recommended)
@ aes_256_cbc
AES-256 in CBC mode (legacy support)
@ chacha20_poly1305
ChaCha20-Poly1305 (modern alternative)

◆ format_type

enum class kcenon::logger::format_type
strong

Pre-defined format types.

Enumerator
plain 

Plain text with timestamps.

json 

JSON structured format.

logfmt 

Logfmt key=value format.

templated 

Template-based custom format.

compact 

Compact single-line format.

Definition at line 33 of file formatter_factory.h.

33 {
34 plain,
35 json,
36 logfmt,
37 templated,
38 compact
39};
@ logfmt
Logfmt key=value format.
@ json
JSON structured format.
@ templated
Template-based custom format.
@ compact
Compact single-line format.
@ plain
Plain text with timestamps.

◆ health_status

Health status levels.

Enumerator
healthy 

Everything is working normally.

degraded 

Some issues but still operational.

unhealthy 

Major issues, may not be operational.

unknown 

Status cannot be determined.

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

Definition at line 27 of file monitoring_interface.h.

27 {
28 healthy,
29 degraded,
30 unhealthy,
31 unknown
32};
@ unknown
Status cannot be determined.

◆ logger_error_code

Error codes specific to the logger system.

These error codes extend the thread_module error codes with logger-specific error conditions.

Enumerator
success 
unknown_error 
not_implemented 
invalid_argument 
writer_not_found 
writer_initialization_failed 
writer_already_exists 
writer_not_healthy 
file_open_failed 
file_write_failed 
file_rotation_failed 
file_permission_denied 
network_connection_failed 
network_send_failed 
network_timeout 
buffer_overflow 
queue_full 
queue_stopped 
queue_overflow_dropped 
queue_overflow_blocked 
invalid_configuration 
configuration_missing 
configuration_conflict 
metrics_collection_failed 
metrics_not_available 
flush_timeout 
processing_failed 
filter_error 
formatter_error 
batch_processing_timeout 
batch_processing_failed 
encryption_failed 
decryption_failed 
authentication_failed 
sanitization_failed 
file_read_failed 
insecure_permissions 
path_traversal_detected 
invalid_key_size 
invalid_filename 
di_not_available 
component_not_found 
registration_failed 
creation_failed 
operation_failed 
async_operation_not_running 
async_operation_already_running 
writer_not_available 
writer_configuration_error 
writer_operation_failed 
destructor_cleanup_failed 
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h, and /home/runner/work/logger_system/logger_system/include/kcenon/logger/core/logger_builder.h.

Definition at line 224 of file error_codes.h.

224 {
225 // General errors (0-999)
226 success = 0,
227 unknown_error = 1,
228 not_implemented = 2,
230
231 // Writer errors (1000-1099)
232 writer_not_found = 1000,
235 writer_not_healthy = 1003,
236
237 // File errors (1100-1199)
238 file_open_failed = 1100,
239 file_write_failed = 1101,
242
243 // Network errors (1200-1299)
245 network_send_failed = 1201,
246 network_timeout = 1202,
247
248 // Buffer/Queue errors (1300-1399)
249 buffer_overflow = 1300,
250 queue_full = 1301,
251 queue_stopped = 1302,
254
255 // Configuration errors (1400-1499)
259
260 // Metrics errors (1500-1599)
263
264 // Processing errors (1600-1699)
265 flush_timeout = 1600,
266 processing_failed = 1601,
267 filter_error = 1602,
268 formatter_error = 1603,
271
272 // Security errors (1700-1799)
273 encryption_failed = 1700,
274 decryption_failed = 1701,
276 sanitization_failed = 1703,
277 file_read_failed = 1704,
280 invalid_key_size = 1707,
281 invalid_filename = 1708,
282
283 // DI Container errors (1800-1899)
284 di_not_available = 1800,
285 component_not_found = 1801,
286 registration_failed = 1802,
287 creation_failed = 1803,
288 operation_failed = 1804,
291
292 // Writer errors (1900-1999)
297};

◆ metric_type [1/2]

enum class kcenon::logger::metric_type
strong

Types of metrics that can be recorded by the logger.

Enumerator
gauge 

A metric that can go up or down (e.g., queue depth).

counter 

A monotonically increasing metric (e.g., total messages).

histogram 

A distribution of values (e.g., processing latency).

counter 

Monotonically increasing value.

gauge 

Value that can go up or down.

histogram 

Distribution of values.

summary 

Statistical summary.

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

Definition at line 98 of file logger.h.

98 {
99 gauge,
100 counter,
101 histogram
102};
@ gauge
A metric that can go up or down (e.g., queue depth).
@ counter
A monotonically increasing metric (e.g., total messages).
@ histogram
A distribution of values (e.g., processing latency).

◆ metric_type [2/2]

enum class kcenon::logger::metric_type
strong

Metric types for categorization.

Enumerator
gauge 

A metric that can go up or down (e.g., queue depth).

counter 

A monotonically increasing metric (e.g., total messages).

histogram 

A distribution of values (e.g., processing latency).

counter 

Monotonically increasing value.

gauge 

Value that can go up or down.

histogram 

Distribution of values.

summary 

Statistical summary.

Definition at line 37 of file monitoring_interface.h.

37 {
38 counter,
39 gauge,
40 histogram,
41 summary
42};
@ summary
Statistical summary.

◆ performance_level

Performance tuning presets.

Enumerator
low_latency 

Minimize latency (small buffers, immediate flush)

balanced 

Balanced configuration (default)

high_throughput 

Maximize throughput (large buffers, batch processing)

minimal_overhead 

Minimize resource usage (simple format, less features)

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

Definition at line 28 of file performance_strategy.h.

28 {
30 balanced,
33};
@ 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)

◆ rotation_type

enum class kcenon::logger::rotation_type
strong

Determines when log rotation should occur.

Enumerator
size 

Rotate based on file size only.

daily 

Rotate daily at midnight.

hourly 

Rotate every hour.

size_and_time 

Rotate based on both size and time.

Definition at line 29 of file rotating_file_writer.h.

29 {
30 size,
31 daily,
32 hourly,
34};
@ hourly
Rotate every hour.
@ size_and_time
Rotate based on both size and time.
@ daily
Rotate daily at midnight.
@ size
Rotate based on file size only.

◆ writer_category

enum class kcenon::logger::writer_category : std::uint8_t
strong

Categories of log writers based on operational behavior.

Writers are categorized by their primary operational mode. This categorization helps in:

  • Understanding writer behavior
  • Selecting appropriate writers for use cases
  • Documentation and API clarity
Since
1.4.0
Enumerator
synchronous 

Synchronous, blocking write operations

asynchronous 

Asynchronous, non-blocking write operations

decorator 

Wraps another writer to add functionality

composite 

Combines multiple outputs or pipeline stages

Definition at line 50 of file writer_category.h.

Function Documentation

◆ copy_log_entry()

log_entry kcenon::logger::copy_log_entry ( const log_entry & entry)
inline

Creates a copy of a log_entry for queue storage.

Since log_entry is move-only, this helper function creates a new log_entry by copying the essential fields from the source.

Parameters
entryThe source log entry to copy from
Returns
A new log_entry with copied data

Definition at line 33 of file queued_writer_base.h.

33 {
34 if (entry.location) {
35 return log_entry(entry.level,
36 entry.message.to_string(),
37 entry.location->file.to_string(),
38 entry.location->line,
39 entry.location->function.to_string(),
40 entry.timestamp);
41 }
42 return log_entry(entry.level,
43 entry.message.to_string(),
44 entry.timestamp);
45}
std::string to_string() const
Convert to std::string.
Represents a single log entry with all associated metadata.
Definition log_entry.h:155
std::optional< source_location > location
Optional source code location information.
Definition log_entry.h:183
log_level level
Severity level of the log message.
Definition log_entry.h:162
small_string_256 message
The actual log message.
Definition log_entry.h:169
std::chrono::system_clock::time_point timestamp
Timestamp when the log entry was created.
Definition log_entry.h:175

References kcenon::logger::log_entry::level, kcenon::logger::log_entry::location, kcenon::logger::log_entry::message, kcenon::logger::log_entry::timestamp, and kcenon::logger::small_string< SSO_SIZE >::to_string().

Referenced by kcenon::logger::queued_writer_base< Container >::enqueue_entry(), kcenon::logger::queued_writer_base< Container >::enqueue_entry(), and kcenon::logger::batch_writer::write().

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

◆ get_logger_error_code()

logger_error_code kcenon::logger::get_logger_error_code ( const common::VoidResult & result)
inline
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h.

Definition at line 543 of file error_codes.h.

543 {
544 if (!result.is_err()) {
545 return logger_error_code::success;
546 }
547 return static_cast<logger_error_code>(result.error().code);
548}

References success.

Referenced by kcenon::logger::security::secure_key_storage::load_key(), kcenon::logger::utils::safe_destructor_result_operation(), and kcenon::logger::security::path_validator::safe_join().

Here is the caller graph for this function:

◆ get_logger_error_message()

std::string kcenon::logger::get_logger_error_message ( const common::VoidResult & result)
inline

Get error message from a VoidResult.

Parameters
resultThe VoidResult to get message from
Returns
Error message, or empty string if no error
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h.

Definition at line 566 of file error_codes.h.

566 {
567 if (!result.is_err()) {
568 return "";
569 }
570 return result.error().message;
571}

Referenced by kcenon::logger::security::secure_key_storage::load_key(), kcenon::logger::security::path_validator::safe_join(), and kcenon::logger::encrypted_writer::write().

Here is the caller graph for this function:

◆ get_writer_category()

template<typename T >
writer_category kcenon::logger::get_writer_category ( )
constexpr

Get the primary category of a writer type.

Template Parameters
TWriter type
Returns
Primary writer category

Returns the primary category for a writer type. Priority order: composite > decorator > async > sync

Since
1.4.0

Definition at line 272 of file writer_category.h.

272 {
273 if constexpr (is_composite_writer_v<T>) {
274 return writer_category::composite;
275 } else if constexpr (is_decorator_writer_v<T>) {
276 return writer_category::decorator;
277 } else if constexpr (is_async_writer_v<T>) {
278 return writer_category::asynchronous;
279 } else if constexpr (is_sync_writer_v<T>) {
280 return writer_category::synchronous;
281 } else {
282 // Default for untagged writers
283 return writer_category::synchronous;
284 }
285}

References asynchronous, composite, decorator, is_async_writer_v, is_composite_writer_v, is_decorator_writer_v, is_sync_writer_v, and synchronous.

◆ has_logger_error()

bool kcenon::logger::has_logger_error ( const common::VoidResult & result)
inline

Check if a VoidResult contains an error.

Parameters
resultThe VoidResult to check
Returns
true if result contains an error
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h.

Definition at line 556 of file error_codes.h.

556 {
557 return result.is_err();
558}

◆ health_status_to_string()

std::string kcenon::logger::health_status_to_string ( health_status status)
inline

Convert health status to string.

Parameters
statusThe health status
Returns
String representation

Definition at line 284 of file monitoring_interface.h.

284 {
285 switch (status) {
286 case health_status::healthy:
287 return "healthy";
288 case health_status::degraded:
289 return "degraded";
290 case health_status::unhealthy:
291 return "unhealthy";
292 case health_status::unknown:
293 return "unknown";
294 default:
295 return "unknown";
296 }
297}

◆ logger_error_to_string()

std::string kcenon::logger::logger_error_to_string ( logger_error_code code)
inline

Convert logger_error_code to string representation.

Parameters
codeThe error code to convert
Returns
Human-readable error description
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h.

Definition at line 304 of file error_codes.h.

304 {
305 switch (code) {
306 case logger_error_code::success:
307 return "Success";
308 case logger_error_code::unknown_error:
309 return "Unknown error";
310 case logger_error_code::not_implemented:
311 return "Not implemented";
312 case logger_error_code::invalid_argument:
313 return "Invalid argument";
314
315 // Writer errors
316 case logger_error_code::writer_not_found:
317 return "Writer not found";
318 case logger_error_code::writer_initialization_failed:
319 return "Writer initialization failed";
320 case logger_error_code::writer_already_exists:
321 return "Writer already exists";
322 case logger_error_code::writer_not_healthy:
323 return "Writer not healthy";
324
325 // File errors
326 case logger_error_code::file_open_failed:
327 return "Failed to open file";
328 case logger_error_code::file_write_failed:
329 return "Failed to write to file";
330 case logger_error_code::file_rotation_failed:
331 return "File rotation failed";
332 case logger_error_code::file_permission_denied:
333 return "File permission denied";
334
335 // Network errors
336 case logger_error_code::network_connection_failed:
337 return "Network connection failed";
338 case logger_error_code::network_send_failed:
339 return "Network send failed";
340 case logger_error_code::network_timeout:
341 return "Network timeout";
342
343 // Buffer/Queue errors
344 case logger_error_code::buffer_overflow:
345 return "Buffer overflow";
346 case logger_error_code::queue_full:
347 return "Queue is full";
348 case logger_error_code::queue_stopped:
349 return "Queue is stopped";
350 case logger_error_code::queue_overflow_dropped:
351 return "Queue overflow: messages dropped";
352 case logger_error_code::queue_overflow_blocked:
353 return "Queue overflow: operation blocked";
354
355 // Configuration errors
356 case logger_error_code::invalid_configuration:
357 return "Invalid configuration";
358 case logger_error_code::configuration_missing:
359 return "Configuration missing";
360 case logger_error_code::configuration_conflict:
361 return "Configuration conflict";
362
363 // Metrics errors
364 case logger_error_code::metrics_collection_failed:
365 return "Metrics collection failed";
366 case logger_error_code::metrics_not_available:
367 return "Metrics not available";
368
369 // Processing errors
370 case logger_error_code::flush_timeout:
371 return "Flush timeout";
372 case logger_error_code::processing_failed:
373 return "Processing failed";
374 case logger_error_code::filter_error:
375 return "Filter error";
376 case logger_error_code::formatter_error:
377 return "Formatter error";
378 case logger_error_code::batch_processing_timeout:
379 return "Batch processing timeout";
380 case logger_error_code::batch_processing_failed:
381 return "Batch processing failed";
382
383 // Security errors
384 case logger_error_code::encryption_failed:
385 return "Encryption failed";
386 case logger_error_code::decryption_failed:
387 return "Decryption failed";
388 case logger_error_code::authentication_failed:
389 return "Authentication failed";
390 case logger_error_code::sanitization_failed:
391 return "Sanitization failed";
392 case logger_error_code::file_read_failed:
393 return "Failed to read file";
394 case logger_error_code::insecure_permissions:
395 return "Insecure file permissions";
396 case logger_error_code::path_traversal_detected:
397 return "Path traversal attack detected";
398 case logger_error_code::invalid_key_size:
399 return "Invalid encryption key size";
400 case logger_error_code::invalid_filename:
401 return "Invalid filename";
402
403 // DI Container errors
404 case logger_error_code::di_not_available:
405 return "DI container not available";
406 case logger_error_code::component_not_found:
407 return "Component not found in DI container";
408 case logger_error_code::registration_failed:
409 return "Failed to register component in DI container";
410 case logger_error_code::creation_failed:
411 return "Failed to create component from factory";
412 case logger_error_code::operation_failed:
413 return "DI container operation failed";
414 case logger_error_code::async_operation_not_running:
415 return "Async operation not running";
416 case logger_error_code::async_operation_already_running:
417 return "Async operation already running";
418
419 // Writer errors
420 case logger_error_code::writer_not_available:
421 return "Writer not available";
422 case logger_error_code::writer_configuration_error:
423 return "Writer configuration error";
424 case logger_error_code::writer_operation_failed:
425 return "Writer operation failed";
426 case logger_error_code::destructor_cleanup_failed:
427 return "Destructor cleanup failed";
428
429 default:
430 return "Unknown logger error code";
431 }
432}

References async_operation_already_running, async_operation_not_running, authentication_failed, batch_processing_failed, batch_processing_timeout, buffer_overflow, component_not_found, configuration_conflict, configuration_missing, creation_failed, decryption_failed, destructor_cleanup_failed, di_not_available, encryption_failed, file_open_failed, file_permission_denied, file_read_failed, file_rotation_failed, file_write_failed, filter_error, flush_timeout, formatter_error, insecure_permissions, invalid_argument, invalid_configuration, invalid_filename, invalid_key_size, metrics_collection_failed, metrics_not_available, network_connection_failed, network_send_failed, network_timeout, not_implemented, operation_failed, path_traversal_detected, processing_failed, queue_full, queue_overflow_blocked, queue_overflow_dropped, queue_stopped, registration_failed, sanitization_failed, success, unknown_error, writer_already_exists, writer_configuration_error, writer_initialization_failed, writer_not_available, writer_not_found, writer_not_healthy, and writer_operation_failed.

Referenced by make_logger_void_result(), and kcenon::logger::utils::error_context::to_string().

Here is the caller graph for this function:

◆ make_batch_writer()

std::unique_ptr< batch_writer > kcenon::logger::make_batch_writer ( log_writer_ptr writer,
size_t batch_size = 100,
std::chrono::milliseconds flush_interval = std::chrono::milliseconds{1000} )

Factory function to create a batch writer.

Parameters
writerThe underlying writer to wrap
batch_sizeMaximum batch size
flush_intervalAuto-flush interval in milliseconds
Returns
Unique pointer to the batch writer

Definition at line 145 of file batch_writer.cpp.

148 {
149
151 cfg.max_batch_size = batch_size;
152 cfg.flush_interval = flush_interval;
153
154 return std::make_unique<batch_writer>(std::move(writer), cfg);
155}
Configuration for batch writer.
std::chrono::milliseconds flush_interval

References kcenon::logger::batch_writer::config::flush_interval, and kcenon::logger::batch_writer::config::max_batch_size.

◆ make_buffered_writer()

std::unique_ptr< buffered_writer > kcenon::logger::make_buffered_writer ( std::unique_ptr< log_writer_interface > writer,
size_t max_entries = buffered_writer::DEFAULT_BUFFER_SIZE,
std::chrono::milliseconds flush_interval = buffered_writer::DEFAULT_FLUSH_INTERVAL )

Factory function to create a buffered writer.

Parameters
writerThe writer to wrap
max_entriesMaximum buffer size
flush_intervalTime between automatic flushes
Returns
Unique pointer to the buffered writer
Exceptions
std::invalid_argumentif writer is nullptr or max_entries is 0
Since
4.0.0

Definition at line 146 of file buffered_writer.cpp.

149 {
150 return std::make_unique<buffered_writer>(std::move(writer), max_entries, flush_interval);
151}

◆ make_composite_writer()

std::unique_ptr< composite_writer > kcenon::logger::make_composite_writer ( std::unique_ptr< log_formatter_interface > formatter,
std::unique_ptr< output_sink_interface > sink )
inline
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/writers/composite_writer.h.

Definition at line 226 of file composite_writer.h.

229{
230 return std::make_unique<composite_writer>(
231 std::move(formatter),
232 std::move(sink)
233 );
234}

Referenced by main().

Here is the caller graph for this function:

◆ make_filtered_writer()

std::unique_ptr< filtered_writer > kcenon::logger::make_filtered_writer ( std::unique_ptr< log_writer_interface > writer,
std::unique_ptr< log_filter_interface > filter )

Factory function to create a filtered writer.

Parameters
writerThe writer to wrap
filterThe filter to apply
Returns
Unique pointer to the filtered writer
Exceptions
std::invalid_argumentif writer is nullptr
Since
4.0.0

Definition at line 47 of file filtered_writer.cpp.

49 {
50 return std::make_unique<filtered_writer>(std::move(writer), std::move(filter));
51}

◆ make_formatted_writer()

std::unique_ptr< formatted_writer > kcenon::logger::make_formatted_writer ( std::unique_ptr< log_writer_interface > writer,
std::unique_ptr< log_formatter_interface > formatter )

Factory function to create a formatted writer.

Parameters
writerThe writer to wrap
formatterThe formatter to apply
Returns
Unique pointer to the formatted writer
Exceptions
std::invalid_argumentif writer is nullptr
Since
4.0.0

Definition at line 55 of file formatted_writer.cpp.

57 {
58 return std::make_unique<formatted_writer>(std::move(writer), std::move(formatter));
59}

◆ make_logger_void_result()

common::VoidResult kcenon::logger::make_logger_void_result ( logger_error_code code,
const std::string & message = "" )
inline
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h.

Definition at line 506 of file error_codes.h.

506 {
508 static_cast<int>(code),
509 message.empty() ? logger_error_to_string(code) : message,
510 "logger_system"
511 });
512}
std::string logger_error_to_string(logger_error_code code)
Convert logger_error_code to string representation.

References logger_error_to_string().

Referenced by kcenon::logger::encrypted_writer::auto_rotate_key_if_needed(), kcenon::logger::utils::check_condition(), kcenon::logger::utils::check_file_exists(), kcenon::logger::utils::check_stream_state(), kcenon::logger::logger::enable_metrics_collection(), kcenon::logger::encrypted_writer::encrypt_data(), kcenon::logger::utils::ensure_directory_exists(), kcenon::logger::async_writer::flush(), kcenon::logger::console_writer::flush(), kcenon::logger::file_sink::flush(), kcenon::logger::network_writer::flush(), kcenon::logger::encrypted_writer::generate_iv(), kcenon::logger::async_writer::handle_overflow(), kcenon::logger::queued_writer_base< Container >::handle_overflow(), kcenon::logger::thread_system_monitor_adapter::reset_metrics(), kcenon::logger::encrypted_writer::rotate_key(), kcenon::logger::security::secure_key_storage::save_key(), kcenon::logger::utils::file_utils::set_file_permissions(), kcenon::logger::utils::try_write_operation(), kcenon::logger::logger_config::validate(), kcenon::logger::security::path_validator::validate(), kcenon::logger::security::secure_key_storage::validate_key_path(), kcenon::logger::utils::file_utils::validate_log_path(), kcenon::logger::batch_writer::write(), kcenon::logger::encrypted_writer::write(), kcenon::logger::file_writer::write(), kcenon::logger::rotating_file_writer::write(), kcenon::logger::async::high_performance_async_writer::write_direct(), and kcenon::logger::file_sink::write_raw().

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

◆ make_logger_void_success()

common::VoidResult kcenon::logger::make_logger_void_success ( )
inline
Examples
/home/runner/work/logger_system/logger_system/include/kcenon/logger/core/error_codes.h.

Definition at line 526 of file error_codes.h.

526 {
527 return common::ok();
528}
VoidResult ok()

References kcenon::common::ok().

Here is the call graph for this function:

◆ metric_type_to_string()

std::string kcenon::logger::metric_type_to_string ( metric_type type)
inline

Convert metric type to string.

Parameters
typeThe metric type
Returns
String representation

Definition at line 304 of file monitoring_interface.h.

304 {
305 switch (type) {
306 case metric_type::counter:
307 return "counter";
308 case metric_type::gauge:
309 return "gauge";
310 case metric_type::histogram:
311 return "histogram";
312 case metric_type::summary:
313 return "summary";
314 default:
315 return "unknown";
316 }
317}

References counter, gauge, histogram, and summary.

◆ to_string()

const char * kcenon::logger::to_string ( writer_category cat)
constexprnoexcept

Get string representation of writer category.

Parameters
catWriter category
Returns
Category name as string
Since
1.4.0

Definition at line 294 of file writer_category.h.

294 {
295 switch (cat) {
296 case writer_category::synchronous: return "synchronous";
297 case writer_category::asynchronous: return "asynchronous";
298 case writer_category::decorator: return "decorator";
299 case writer_category::composite: return "composite";
300 }
301 return "unknown";
302}

References asynchronous, composite, decorator, and synchronous.

Variable Documentation

◆ is_async_writer_v

template<typename T >
bool kcenon::logger::is_async_writer_v = is_async_writer<T>::value
inlineconstexpr

Definition at line 171 of file writer_category.h.

Referenced by get_writer_category().

◆ is_composite_writer_v

template<typename T >
bool kcenon::logger::is_composite_writer_v = is_composite_writer<T>::value
inlineconstexpr

Definition at line 195 of file writer_category.h.

Referenced by get_writer_category().

◆ is_decorator_writer_v

template<typename T >
bool kcenon::logger::is_decorator_writer_v = is_decorator_writer<T>::value
inlineconstexpr

Definition at line 183 of file writer_category.h.

Referenced by get_writer_category().

◆ is_sync_writer_v

template<typename T >
bool kcenon::logger::is_sync_writer_v = is_sync_writer<T>::value
inlineconstexpr

Definition at line 159 of file writer_category.h.

Referenced by get_writer_category().