Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
backend_logger.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
15#pragma once
16
17#ifdef BUILD_WITH_COMMON_SYSTEM
18#include <kcenon/common/logging/log_functions.h>
19#else
20#include <iostream>
21#endif
22
23#include <string>
24#include <string_view>
25
26namespace database
27{
28namespace utils
29{
30
53{
54public:
59 explicit backend_logger(std::string_view backend_name)
60 : backend_name_(backend_name)
61 {
62 }
63
69 void error(std::string_view context, std::string_view message) const
70 {
71 std::string formatted
72 = "[" + backend_name_ + ":" + std::string(context) + "] " + std::string(message);
73#ifdef BUILD_WITH_COMMON_SYSTEM
74 kcenon::common::logging::log_error(formatted);
75#else
76 std::cerr << formatted << std::endl;
77#endif
78 }
79
84 void warning(std::string_view message) const
85 {
86 std::string formatted = "[" + backend_name_ + "] " + std::string(message);
87#ifdef BUILD_WITH_COMMON_SYSTEM
88 kcenon::common::logging::log_warning(formatted);
89#else
90 std::cerr << formatted << std::endl;
91#endif
92 }
93
98 void info(std::string_view message) const
99 {
100 std::string formatted = "[" + backend_name_ + "] " + std::string(message);
101#ifdef BUILD_WITH_COMMON_SYSTEM
102 kcenon::common::logging::log_info(formatted);
103#else
104 std::cout << formatted << std::endl;
105#endif
106 }
107
108private:
109 std::string backend_name_;
110};
111
112} // namespace utils
113} // namespace database
Centralized logging utility for database backends.
void error(std::string_view context, std::string_view message) const
Log an error message with context.
backend_logger(std::string_view backend_name)
Construct a logger for a specific backend.
void warning(std::string_view message) const
Log a warning message.
void info(std::string_view message) const
Log an info message.