Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::utils::backend_logger Class Reference

Centralized logging utility for database backends. More...

#include <backend_logger.h>

Collaboration diagram for database::utils::backend_logger:
Collaboration graph

Public Member Functions

 backend_logger (std::string_view backend_name)
 Construct a logger for a specific backend.
 
void error (std::string_view context, std::string_view message) const
 Log an error message with context.
 
void warning (std::string_view message) const
 Log a warning message.
 
void info (std::string_view message) const
 Log an info message.
 

Private Attributes

std::string backend_name_
 

Detailed Description

Centralized logging utility for database backends.

This class provides a unified logging interface that replaces the duplicate *_LOG_ERROR, *_LOG_WARNING, and *_LOG_INFO macros previously defined in each backend implementation.

Usage:

namespace {
const database::utils::backend_logger logger_("PostgreSQL");
}
void some_function() {
logger_.error("initialize", "Connection failed");
logger_.warning("Mock mode enabled");
logger_.info("Connection established");
}
Centralized logging utility for database backends.

Definition at line 52 of file backend_logger.h.

Constructor & Destructor Documentation

◆ backend_logger()

database::utils::backend_logger::backend_logger ( std::string_view backend_name)
inlineexplicit

Construct a logger for a specific backend.

Parameters
backend_nameName of the backend (e.g., "PostgreSQL", "SQLite")

Definition at line 59 of file backend_logger.h.

60 : backend_name_(backend_name)
61 {
62 }

Member Function Documentation

◆ error()

void database::utils::backend_logger::error ( std::string_view context,
std::string_view message ) const
inline

Log an error message with context.

Parameters
contextThe operation context (e.g., "initialize", "execute_query")
messageThe error message

Definition at line 69 of file backend_logger.h.

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 }

References backend_name_.

◆ info()

void database::utils::backend_logger::info ( std::string_view message) const
inline

Log an info message.

Parameters
messageThe info message

Definition at line 98 of file backend_logger.h.

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 }

References backend_name_.

◆ warning()

void database::utils::backend_logger::warning ( std::string_view message) const
inline

Log a warning message.

Parameters
messageThe warning message

Definition at line 84 of file backend_logger.h.

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 }

References backend_name_.

Member Data Documentation

◆ backend_name_

std::string database::utils::backend_logger::backend_name_
private

Definition at line 109 of file backend_logger.h.

Referenced by error(), info(), and warning().


The documentation for this class was generated from the following file: