MySQL 9.1.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
mysql_harness::logging::Registry Class Reference

#include <registry.h>

Public Member Functions

 Registry ()=default
 
 Registry (const Registry &)=delete
 
Registryoperator= (const Registry &)=delete
 
 ~Registry ()=default
 
void create_logger (const std::string &name, LogLevel level=LogLevel::kNotSet)
 Create a logger in the internal registry. More...
 
void remove_logger (const std::string &name)
 Remove a named logger from the internal registry. More...
 
Logger get_logger (const std::string &name) const
 Return logger for particular module. More...
 
Logger get_logger_or_default (const std::string &name, const std::string &default_name) const
 Return logger for particular module. More...
 
Logger get_logger_or_default (const std::string &name) const
 Return logger for particular module. More...
 
void update_logger (const std::string &name, const Logger &logger)
 Update logger for particular module. More...
 
std::set< std::string > get_logger_names () const
 Get the logger names (id's) from the internal registry. More...
 
void add_handler (std::string name, std::shared_ptr< Handler > handler)
 Add a handler to the internal registry. More...
 
void remove_handler (std::string name)
 Remove handler from the internal registry. More...
 
std::shared_ptr< Handlerget_handler (const std::string &name) const
 Return handler in the internal registry. More...
 
std::set< std::string > get_handler_names () const
 Get the handler names from the internal registry. More...
 
bool is_handled (LogLevel level) const
 Check if a log-level is handled by at least one handler. More...
 
void set_ready () noexcept
 Flag that the registry has been initialized. More...
 
bool is_ready () const noexcept
 Query if logging facility is ready to use. More...
 
void flush_all_loggers (const std::string &dst="")
 Force the flush (reopen) on all registered logger handlers, while moving old logger file to dst. More...
 

Private Attributes

std::shared_mutex mtx_
 
std::map< std::string, Loggerloggers_
 
std::map< std::string, std::shared_ptr< Handler > > handlers_
 
std::atomic< bool > ready_ {false}
 

Constructor & Destructor Documentation

◆ Registry() [1/2]

mysql_harness::logging::Registry::Registry ( )
default

◆ Registry() [2/2]

mysql_harness::logging::Registry::Registry ( const Registry )
delete

◆ ~Registry()

mysql_harness::logging::Registry::~Registry ( )
default

Member Function Documentation

◆ add_handler()

void mysql_harness::logging::Registry::add_handler ( std::string  name,
std::shared_ptr< Handler handler 
)

Add a handler to the internal registry.

Parameters
nameHandler id
handlerShared pointer to handler
Exceptions
std::logic_errorif there is a handler already registered with given module name

◆ create_logger()

void mysql_harness::logging::Registry::create_logger ( const std::string &  name,
LogLevel  level = LogLevel::kNotSet 
)

Create a logger in the internal registry.

Parameters
nameLogger id (log domain it services)
levelLog level for logger
Exceptions
std::logic_errorif there is a logger already registered with given module name

◆ flush_all_loggers()

void mysql_harness::logging::Registry::flush_all_loggers ( const std::string &  dst = "")

Force the flush (reopen) on all registered logger handlers, while moving old logger file to dst.

Parameters
dstdestination filename for old log

◆ get_handler()

std::shared_ptr< Handler > mysql_harness::logging::Registry::get_handler ( const std::string &  name) const

Return handler in the internal registry.

Parameters
nameHandler id
Exceptions
std::logic_errorif no handler is registered for given name

◆ get_handler_names()

std::set< std::string > mysql_harness::logging::Registry::get_handler_names ( ) const

Get the handler names from the internal registry.

◆ get_logger()

Logger mysql_harness::logging::Registry::get_logger ( const std::string &  name) const

Return logger for particular module.

The reason why this function returns by value is thread-safety.

Parameters
nameLogger id (log domain it services)
Exceptions
std::logic_errorif no logger is registered for given module name

◆ get_logger_names()

std::set< std::string > mysql_harness::logging::Registry::get_logger_names ( ) const

Get the logger names (id's) from the internal registry.

◆ get_logger_or_default() [1/2]

Logger mysql_harness::logging::Registry::get_logger_or_default ( const std::string &  name) const

Return logger for particular module.

if it doesn't exist, get the default logger.

Parameters
nameLogger id (log domain it services)
Exceptions
std::logic_errorif neither logger is registered for given module name

◆ get_logger_or_default() [2/2]

Logger mysql_harness::logging::Registry::get_logger_or_default ( const std::string &  name,
const std::string &  default_name 
) const

Return logger for particular module.

if it doesn't exist, get the default logger.

Parameters
nameLogger id (log domain it services)
default_namename of the default logger
Exceptions
std::logic_errorif neither logger is registered for given module name

◆ is_handled()

bool mysql_harness::logging::Registry::is_handled ( LogLevel  level) const

Check if a log-level is handled by at least one handler.

Returns
if at least one handler handles the log-level
Return values
trueat least one handler
falselog-level will be ignored.

◆ is_ready()

bool mysql_harness::logging::Registry::is_ready ( ) const
inlinenoexcept

Query if logging facility is ready to use.

The exact meaning of this flag is not defined here, see description in set_ready()

◆ operator=()

Registry & mysql_harness::logging::Registry::operator= ( const Registry )
delete

◆ remove_handler()

void mysql_harness::logging::Registry::remove_handler ( std::string  name)

Remove handler from the internal registry.

Parameters
nameHandler id
Exceptions
std::logic_errorif no handler is registered for given name

◆ remove_logger()

void mysql_harness::logging::Registry::remove_logger ( const std::string &  name)

Remove a named logger from the internal registry.

Parameters
nameLogger id (log domain it services)
Exceptions
std::logic_errorif there is no logger registered with given module name

◆ set_ready()

void mysql_harness::logging::Registry::set_ready ( )
inlinenoexcept

Flag that the registry has been initialized.

This method should be called after log initialization is complete to flag that logging facility is now available. Note that this is a convenience flag - it does not directly affect the operation of Registry. However, a logging function (i.e. log_message()) might want to query this flag when called and do whatever it deems appropriate.

◆ update_logger()

void mysql_harness::logging::Registry::update_logger ( const std::string &  name,
const Logger logger 
)

Update logger for particular module.

This function provides a thread-safe way of updating the Logger object in the registry.

Parameters
nameLogger id (log domain it services)
loggerLogger object
Exceptions
std::logic_errorif no logger is registered for given module name

Member Data Documentation

◆ handlers_

std::map<std::string, std::shared_ptr<Handler> > mysql_harness::logging::Registry::handlers_
private

◆ loggers_

std::map<std::string, Logger> mysql_harness::logging::Registry::loggers_
private

◆ mtx_

std::shared_mutex mysql_harness::logging::Registry::mtx_
mutableprivate

◆ ready_

std::atomic<bool> mysql_harness::logging::Registry::ready_ {false}
private

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