Logger System 1.0.0
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
backend_integration_example.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, kcenon
3// See the LICENSE file in the project root for full license information.
4
5// @note Relocated from the repository root (test_backend.cpp) into examples/
6// under Issue #642. This manual main()-based backend smoke demo belongs
7// in the example tree, not the project root.
8
9#include <iostream>
14
15// Note: thread_system_backend was removed in Issue #225
16// thread_system is now optional and standalone_backend is the default
17
18using namespace kcenon::logger;
19
20int main() {
21 std::cout << "Testing backend integration..." << std::endl;
22
23 // Test 1: Standalone backend
24 {
25 std::cout << "\n=== Test 1: Standalone Backend ===" << std::endl;
26 auto standalone_backend = std::make_unique<backends::standalone_backend>();
27 std::cout << "Backend name: " << standalone_backend->get_backend_name() << std::endl;
28
29 auto logger_result = logger_builder()
31 .with_async(false)
32 .add_writer("console", std::make_unique<console_writer>())
33 .build();
34
35 if (logger_result) {
36 auto logger_inst = std::move(logger_result.value());
37 logger_inst->log(log_level::info, std::string("Test message from standalone backend"));
38 std::cout << "[PASS] Standalone backend test passed" << std::endl;
39 } else {
40 std::cerr << "[FAIL] Failed to build logger: " << logger_result.error_message() << std::endl;
41 return 1;
42 }
43 }
44
45 // Note: Test 2 (Thread system backend) was removed in Issue #225
46 // thread_system is now optional and standalone_backend is used by default
47
48 // Test 2: Auto-detection (default, always uses standalone_backend since Issue #225)
49 {
50 std::cout << "\n=== Test 2: Auto-Detection ===" << std::endl;
51 auto logger_result = logger_builder()
52 .with_async(false)
53 .add_writer("console", std::make_unique<console_writer>())
54 .build();
55
56 if (logger_result) {
57 auto logger_inst = std::move(logger_result.value());
58 logger_inst->log(log_level::info, std::string("Test message with auto-detected backend"));
59 std::cout << "[PASS] Auto-detection test passed (standalone backend)" << std::endl;
60 } else {
61 std::cerr << "[FAIL] Failed to build logger: " << logger_result.error_message() << std::endl;
62 return 1;
63 }
64 }
65
66 std::cout << "\n=== All backend tests passed! ===" << std::endl;
67 return 0;
68}
Builder pattern for logger construction with validation.
logger_builder & with_standalone_backend()
Use standalone backend explicitly.
logger_builder & with_async(bool async=true)
result< std::unique_ptr< logger > > build()
logger_builder & add_writer(const std::string &name, log_writer_ptr writer)
Add a writer to the logger.
Console writer for logging to stdout/stderr.
High-performance, thread-safe logging system with asynchronous capabilities.
Builder pattern implementation for flexible logger configuration kcenon.
Standalone integration backend implementation kcenon.