Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::integrated::adapters::backends::common_logger_backend Class Reference

Logger backend using common_system's ILogger interface. More...

#include <common_logger_backend.h>

Inheritance diagram for database::integrated::adapters::backends::common_logger_backend:
Inheritance graph
Collaboration diagram for database::integrated::adapters::backends::common_logger_backend:
Collaboration graph

Public Member Functions

 common_logger_backend (const db_logger_config &config)
 Construct common logger backend.
 
 ~common_logger_backend () override
 
 common_logger_backend (const common_logger_backend &)=delete
 
common_logger_backendoperator= (const common_logger_backend &)=delete
 
 common_logger_backend (common_logger_backend &&)=delete
 
common_logger_backendoperator= (common_logger_backend &&)=delete
 
common::VoidResult initialize () override
 Initialize the logger backend.
 
common::VoidResult shutdown () override
 Shutdown the logger backend gracefully.
 
bool is_initialized () const override
 Check if backend is initialized.
 
void log (db_log_level level, const std::string &message) override
 Log a message.
 
void flush () override
 Flush pending log messages.
 
- Public Member Functions inherited from database::integrated::adapters::backends::logger_backend
virtual ~logger_backend ()=default
 

Private Attributes

const db_logger_configconfig_
 
bool initialized_
 

Detailed Description

Logger backend using common_system's ILogger interface.

This backend uses the kcenon/common_system for logging through the GlobalLoggerRegistry and ILogger interface.

Definition at line 44 of file common_logger_backend.h.

Constructor & Destructor Documentation

◆ common_logger_backend() [1/3]

database::integrated::adapters::backends::common_logger_backend::common_logger_backend ( const db_logger_config & config)
explicit

Construct common logger backend.

Parameters
configLogger configuration

Definition at line 32 of file common_logger_backend.cpp.

◆ ~common_logger_backend()

database::integrated::adapters::backends::common_logger_backend::~common_logger_backend ( )
override

Definition at line 37 of file common_logger_backend.cpp.

38{
39 if (initialized_)
40 {
41 shutdown();
42 }
43}
common::VoidResult shutdown() override
Shutdown the logger backend gracefully.

References initialized_, and shutdown().

Here is the call graph for this function:

◆ common_logger_backend() [2/3]

database::integrated::adapters::backends::common_logger_backend::common_logger_backend ( const common_logger_backend & )
delete

◆ common_logger_backend() [3/3]

database::integrated::adapters::backends::common_logger_backend::common_logger_backend ( common_logger_backend && )
delete

Member Function Documentation

◆ flush()

void database::integrated::adapters::backends::common_logger_backend::flush ( )
overridevirtual

Flush pending log messages.

Implements database::integrated::adapters::backends::logger_backend.

Definition at line 116 of file common_logger_backend.cpp.

117{
118#if KCENON_HAS_COMMON_SYSTEM
119 if (initialized_)
120 {
121 kcenon::common::logging::flush();
122 }
123#endif
124}

References initialized_.

◆ initialize()

common::VoidResult database::integrated::adapters::backends::common_logger_backend::initialize ( )
overridevirtual

Initialize the logger backend.

Returns
VoidResult::ok() on success, error on failure

Implements database::integrated::adapters::backends::logger_backend.

Definition at line 45 of file common_logger_backend.cpp.

46{
47 if (initialized_)
48 {
49 return common::ok();
50 }
51
52#if KCENON_HAS_COMMON_SYSTEM
53 try
54 {
55 // The GlobalLoggerRegistry is already initialized by common_system.
56 // We just need to verify we can access it.
57 auto& registry = kcenon::common::interfaces::GlobalLoggerRegistry::instance();
58
59 // Check if a default logger is available
60 if (!registry.has_default_logger())
61 {
62 // No default logger registered, but that's okay.
63 // LOG_* macros will use NullLogger as fallback.
64 }
65
66 initialized_ = true;
67 return common::ok();
68 }
69 catch (const std::exception& e)
70 {
71 return make_error(std::string("Logger initialization failed: ") + e.what());
72 }
73#else
74 return make_error("common_system not available");
75#endif
76}
VoidResult ok()

References initialized_, and common::ok().

Here is the call graph for this function:

◆ is_initialized()

bool database::integrated::adapters::backends::common_logger_backend::is_initialized ( ) const
overridevirtual

Check if backend is initialized.

Returns
true if initialized and ready to log

Implements database::integrated::adapters::backends::logger_backend.

Definition at line 91 of file common_logger_backend.cpp.

92{
93 return initialized_;
94}

References initialized_.

◆ log()

void database::integrated::adapters::backends::common_logger_backend::log ( db_log_level level,
const std::string & message )
overridevirtual

Log a message.

Parameters
levelLog level
messageMessage to log

Implements database::integrated::adapters::backends::logger_backend.

Definition at line 96 of file common_logger_backend.cpp.

97{
98 if (!initialized_)
99 {
100 return;
101 }
102
103 // Check if this level should be logged
104 if (level < config_.min_log_level)
105 {
106 return;
107 }
108
109#if KCENON_HAS_COMMON_SYSTEM
110 // Use common_system's logging functions
111 auto common_level = convert_log_level(level);
112 kcenon::common::logging::log(common_level, message);
113#endif
114}
db_log_level min_log_level
Minimum log level to output.

References config_, initialized_, and database::integrated::db_logger_config::min_log_level.

◆ operator=() [1/2]

common_logger_backend & database::integrated::adapters::backends::common_logger_backend::operator= ( common_logger_backend && )
delete

◆ operator=() [2/2]

common_logger_backend & database::integrated::adapters::backends::common_logger_backend::operator= ( const common_logger_backend & )
delete

◆ shutdown()

common::VoidResult database::integrated::adapters::backends::common_logger_backend::shutdown ( )
overridevirtual

Shutdown the logger backend gracefully.

Returns
VoidResult::ok() on success, error on failure

Implements database::integrated::adapters::backends::logger_backend.

Definition at line 78 of file common_logger_backend.cpp.

79{
80 if (!initialized_)
81 {
82 return common::ok();
83 }
84
85 // GlobalLoggerRegistry is a singleton managed by common_system.
86 // We don't need to shut it down here.
87 initialized_ = false;
88 return common::ok();
89}

References initialized_, and common::ok().

Referenced by ~common_logger_backend().

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

Member Data Documentation

◆ config_

const db_logger_config& database::integrated::adapters::backends::common_logger_backend::config_
private

Definition at line 75 of file common_logger_backend.h.

Referenced by log().

◆ initialized_

bool database::integrated::adapters::backends::common_logger_backend::initialized_
private

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