Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
deployment_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
21#include "../logger_config.h"
22
23namespace kcenon::logger {
24
29enum class deployment_env {
31 staging,
33 testing
34};
35
46public:
52 : env_(env) {}
53
54 std::string get_name() const override {
55 return "deployment:" + env_to_string(env_);
56 }
57
58 void apply(logger_config& config) const override {
59 switch (env_) {
61 apply_development(config);
62 break;
64 apply_staging(config);
65 break;
67 apply_production(config);
68 break;
70 apply_testing(config);
71 break;
72 }
73 }
74
75 int priority() const override {
76 return 75; // Higher than performance, lower than environment
77 }
78
79private:
81
82 static void apply_development(logger_config& config) {
83 config.async = false;
84 config.min_level = log_level::trace;
85 config.enable_metrics = true;
86 config.enable_crash_handler = true;
87 config.enable_color_output = true;
88 config.enable_source_location = true;
89 config.enable_structured_logging = false;
90 config.batch_size = 1;
91 config.flush_interval = std::chrono::milliseconds(0);
92 }
93
94 static void apply_staging(logger_config& config) {
95 config.async = true;
96 config.min_level = log_level::info;
97 config.enable_metrics = true;
98 config.enable_crash_handler = true;
99 config.enable_color_output = false;
100 config.enable_structured_logging = true;
101 config.buffer_size = 16384;
102 config.batch_size = 100;
103 config.flush_interval = std::chrono::milliseconds(1000);
104 config.max_file_size = 50 * 1024 * 1024; // 50MB
105 config.max_file_count = 5;
106 config.enable_batch_writing = true;
107 }
108
109 static void apply_production(logger_config& config) {
110 config.async = true;
111 config.min_level = log_level::warn;
112 config.enable_metrics = true;
113 config.enable_crash_handler = true;
114 config.enable_color_output = false;
115 config.enable_source_location = false;
116 config.enable_structured_logging = true;
117 config.buffer_size = 32768;
118 config.batch_size = 200;
119 config.flush_interval = std::chrono::milliseconds(2000);
120 config.max_file_size = 100 * 1024 * 1024; // 100MB
121 config.max_file_count = 10;
122 config.enable_compression = true;
123 config.enable_batch_writing = true;
124 config.queue_overflow_policy = logger_config::overflow_policy::drop_oldest;
125 }
126
127 static void apply_testing(logger_config& config) {
128 config.async = false;
129 config.min_level = log_level::trace;
130 config.enable_metrics = false;
131 config.enable_crash_handler = false;
132 config.enable_color_output = false;
133 config.enable_source_location = true;
134 config.batch_size = 1;
135 config.flush_interval = std::chrono::milliseconds(0);
136 }
137
138 static std::string env_to_string(deployment_env env) {
139 switch (env) {
140 case deployment_env::development: return "development";
141 case deployment_env::staging: return "staging";
142 case deployment_env::production: return "production";
143 case deployment_env::testing: return "testing";
144 default: return "unknown";
145 }
146 }
147};
148
149} // namespace kcenon::logger
Abstract interface for logger configuration strategies.
Configuration strategy based on deployment environment.
void apply(logger_config &config) const override
Apply this strategy to a logger configuration.
int priority() const override
Get the strategy priority.
static void apply_staging(logger_config &config)
deployment_strategy(deployment_env env)
Constructor with deployment environment.
std::string get_name() const override
Get the strategy name.
static void apply_development(logger_config &config)
static std::string env_to_string(deployment_env env)
static void apply_testing(logger_config &config)
static void apply_production(logger_config &config)
Interface for logger configuration strategies (Strategy Pattern)
Configuration structure for logger with validation.
deployment_env
Deployment environment types.
@ development
Development environment (verbose, colorful)
@ staging
Staging environment (JSON, file + console)
@ testing
Testing environment (memory buffer, sync)
@ production
Production environment (optimized, safe)
Configuration structure for logger with validation.
log_level min_level
Minimum log level to process.
std::size_t batch_size
Number of messages per batch write.
bool enable_batch_writing
Enable batch writing mode.
std::size_t max_file_size
Maximum file size in bytes (default: 100MB).
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.
std::size_t max_file_count
Maximum number of rotating log files.
bool enable_crash_handler
Enable crash signal handler.
bool enable_structured_logging
Enable structured (JSON) log output.