Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
adapter_pattern_poc.cpp File Reference

Proof-of-concept for adapter pattern refactoring. More...

#include <iostream>
#include <memory>
#include <string>
#include <chrono>
Include dependency graph for adapter_pattern_poc.cpp:

Go to the source code of this file.

Classes

class  logger_old
 
class  logger_core
 
class  logger_adapter
 
class  standalone_adapter
 
class  external_system_interface
 
class  thread_system_adapter
 
class  common_system_interface
 
class  common_system_adapter
 
class  full_integration_adapter
 
class  logger_factory
 

Enumerations

enum class  integration_mode { standalone , thread_system , common_system , full }
 

Functions

void demonstrate_adapters ()
 
void benchmark_overhead ()
 
int main ()
 

Detailed Description

Proof-of-concept for adapter pattern refactoring.

Definition in file adapter_pattern_poc.cpp.

Enumeration Type Documentation

◆ integration_mode

enum class integration_mode
strong
Enumerator
standalone 
thread_system 
common_system 
full 

Definition at line 204 of file adapter_pattern_poc.cpp.

Function Documentation

◆ benchmark_overhead()

void benchmark_overhead ( )
Examples
adapter_pattern_poc.cpp.

Definition at line 307 of file adapter_pattern_poc.cpp.

307 {
308 std::cout << "\n=== Performance Comparison ===\n" << std::endl;
309
310 const int iterations = 1000000;
311 auto core = std::make_shared<logger_core>();
312
313 // Direct call (no virtual)
314 {
315 auto start = std::chrono::high_resolution_clock::now();
316 for (int i = 0; i < iterations; ++i) {
317 core->log_internal("test");
318 }
319 auto end = std::chrono::high_resolution_clock::now();
320 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start);
321 std::cout << "Direct call: " << duration.count() / iterations << " ns/call" << std::endl;
322 }
323
324 // Virtual call through adapter
325 {
326 auto adapter = std::make_unique<standalone_adapter>(core);
327 auto start = std::chrono::high_resolution_clock::now();
328 for (int i = 0; i < iterations; ++i) {
329 adapter->log("test");
330 }
331 auto end = std::chrono::high_resolution_clock::now();
332 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start);
333 std::cout << "Virtual call: " << duration.count() / iterations << " ns/call" << std::endl;
334 std::cout << "Overhead: ~1-2ns (negligible for I/O operations)" << std::endl;
335 }
336}

Referenced by main().

Here is the caller graph for this function:

◆ demonstrate_adapters()

void demonstrate_adapters ( )
Examples
adapter_pattern_poc.cpp.

Definition at line 239 of file adapter_pattern_poc.cpp.

239 {
240 std::cout << "\n=== Adapter Pattern Proof of Concept ===\n" << std::endl;
241
242 // Test 1: Standalone mode
243 {
244 std::cout << "Test 1: Standalone Mode" << std::endl;
246 logger->log("Hello from standalone mode");
247 std::cout << "Messages logged: " << logger->message_count() << "\n" << std::endl;
248 }
249
250 // Test 2: Thread system integration
251 {
252 std::cout << "Test 2: Thread System Integration" << std::endl;
254
255 // Can use as logger_adapter
256 logger->log("Hello as adapter");
257
258 // Can cast to external interface
259 auto* external = dynamic_cast<external_system_interface*>(logger.get());
260 if (external) {
261 external->external_log("Hello via external interface");
262 std::cout << "Interface: " << external->get_interface_name() << std::endl;
263 }
264 std::cout << std::endl;
265 }
266
267 // Test 3: Common system integration
268 {
269 std::cout << "Test 3: Common System Integration" << std::endl;
271
272 auto* monitored = dynamic_cast<common_system_interface*>(logger.get());
273 if (monitored) {
274 monitored->monitored_log("Message 1");
275 monitored->monitored_log("Message 2");
276 std::cout << "Metrics collected: " << monitored->get_metric_count() << std::endl;
277 }
278 std::cout << std::endl;
279 }
280
281 // Test 4: Full integration (both interfaces)
282 {
283 std::cout << "Test 4: Full Integration" << std::endl;
285
286 // Use both interfaces
287 auto* external = dynamic_cast<external_system_interface*>(logger.get());
288 auto* monitored = dynamic_cast<common_system_interface*>(logger.get());
289
290 if (external && monitored) {
291 external->external_log("Via external interface");
292 monitored->monitored_log("Via monitoring interface");
293 std::cout << "Total messages: " << monitored->get_metric_count() << std::endl;
294 }
295 std::cout << std::endl;
296 }
297
298 // Test 5: Runtime mode switching (same binary!)
299 {
300 std::cout << "Test 5: Runtime Mode Switching" << std::endl;
301 std::cout << "All modes tested with SINGLE BINARY" << std::endl;
302 std::cout << "No recompilation needed!" << std::endl;
303 }
304}
static std::unique_ptr< logger_adapter > create(integration_mode mode)

References common_system, logger_factory::create(), full, standalone, and thread_system.

Referenced by main().

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

◆ main()

int main ( )
Examples
adapter_pattern_poc.cpp, advanced_features_demo.cpp, basic_usage.cpp, composite_writer_example.cpp, crash_protection/main.cpp, critical_logging_example.cpp, custom_writer_example.cpp, decorator_usage.cpp, di_pattern_example.cpp, distributed_logging_demo.cpp, logger_config_builder_example.cpp, metrics_demo.cpp, monitoring_integration_example.cpp, security_demo.cpp, structured_logging_example.cpp, and writer_builder_example.cpp.

Definition at line 338 of file adapter_pattern_poc.cpp.

338 {
341
342 std::cout << "\n=== Benefits Summary ===" << std::endl;
343 std::cout << "✅ Single binary for all modes" << std::endl;
344 std::cout << "✅ Runtime mode selection" << std::endl;
345 std::cout << "✅ Easier testing (no recompilation)" << std::endl;
346 std::cout << "✅ Clear code structure" << std::endl;
347 std::cout << "✅ Minimal performance overhead" << std::endl;
348 std::cout << "✅ Better maintainability" << std::endl;
349
350 return 0;
351}
void benchmark_overhead()
void demonstrate_adapters()

References benchmark_overhead(), and demonstrate_adapters().

Here is the call graph for this function: