MySQL 8.0.30
Source Code Documentation
mysql_harness::logging::Handler Class Referenceabstract

Base class for log message handler. More...

#include <handler.h>

Inheritance diagram for mysql_harness::logging::Handler:
[legend]

Public Member Functions

 Handler ()=default
 
 Handler (const Handler &)=default
 
Handleroperator= (const Handler &)=default
 
virtual ~Handler ()=default
 
void handle (const Record &record)
 
void set_level (LogLevel level)
 
LogLevel get_level () const
 
void set_timestamp_precision (LogTimestampPrecision precision)
 
virtual void reopen (const std::string dst="")=0
 Request to reopen underlying log sink. More...
 
bool has_logged () const
 check if the handler has logged at least one record. More...
 

Static Public Attributes

static constexpr const char * kDefaultName = nullptr
 Default identifier. More...
 

Protected Member Functions

std::string format (const Record &record) const
 
 Handler (bool format_messages, LogLevel level, LogTimestampPrecision timestamp_precision)
 
void has_logged (bool v)
 

Private Member Functions

virtual void do_log (const Record &record)=0
 Log message handler primitive. More...
 

Private Attributes

bool format_messages_
 Flags if log messages should be formatted (prefixed with log level, timestamp, etc) before logging. More...
 
LogLevel level_
 Log level set for the handler. More...
 
LogTimestampPrecision precision_
 Timestamp precision for logging. More...
 
bool has_logged_ {false}
 

Detailed Description

Base class for log message handler.

This class is used to implement a log message handler. You need to implement the do_log primitive to process the log record. If, for some reason, the implementation is unable to log the record, and exception can be thrown that will be caught by the harness.

Constructor & Destructor Documentation

◆ Handler() [1/3]

mysql_harness::logging::Handler::Handler ( )
explicitdefault

◆ Handler() [2/3]

mysql_harness::logging::Handler::Handler ( const Handler )
explicitdefault

◆ ~Handler()

virtual mysql_harness::logging::Handler::~Handler ( )
virtualdefault

◆ Handler() [3/3]

mysql_harness::logging::Handler::Handler ( bool  format_messages,
LogLevel  level,
LogTimestampPrecision  timestamp_precision 
)
explicitprotected

Member Function Documentation

◆ do_log()

virtual void mysql_harness::logging::Handler::do_log ( const Record record)
privatepure virtual

Log message handler primitive.

This member function is implemented by subclasses to properly log a record wherever it need to be logged. If it is not possible to log the message properly, an exception should be thrown and will be caught by the caller.

Parameters
recordRecord containing information about the message.

Implemented in EventlogHandler, SyslogHandler, mysql_harness::logging::StreamHandler, mysql_harness::logging::NullHandler, and mysql_harness::logging::FileHandler.

◆ format()

std::string mysql_harness::logging::Handler::format ( const Record record) const
protected

◆ get_level()

LogLevel mysql_harness::logging::Handler::get_level ( ) const
inline

◆ handle()

void mysql_harness::logging::Handler::handle ( const Record record)

◆ has_logged() [1/2]

bool mysql_harness::logging::Handler::has_logged ( ) const
inline

check if the handler has logged at least one record.

Return values
trueif at least one record was logged
falseif no record has been logged yet.

◆ has_logged() [2/2]

void mysql_harness::logging::Handler::has_logged ( bool  v)
inlineprotected

◆ operator=()

Handler & mysql_harness::logging::Handler::operator= ( const Handler )
default

◆ reopen()

virtual void mysql_harness::logging::Handler::reopen ( const std::string  dst = "")
pure virtual

Request to reopen underlying log sink.

Should be no-op for handlers NOT writing to a file. Useful for log rotation, when the logger got the signal with the request to reopen the file. Provide a destination filename for the old file for file based handlers.

Implemented in EventlogHandler, mysql_harness::logging::FileHandler, mysql_harness::logging::StreamHandler, mysql_harness::logging::NullHandler, and SyslogHandler.

◆ set_level()

void mysql_harness::logging::Handler::set_level ( LogLevel  level)
inline

◆ set_timestamp_precision()

void mysql_harness::logging::Handler::set_timestamp_precision ( LogTimestampPrecision  precision)
inline

Member Data Documentation

◆ format_messages_

bool mysql_harness::logging::Handler::format_messages_
private

Flags if log messages should be formatted (prefixed with log level, timestamp, etc) before logging.

◆ has_logged_

bool mysql_harness::logging::Handler::has_logged_ {false}
private

◆ kDefaultName

constexpr const char* mysql_harness::logging::Handler::kDefaultName = nullptr
staticconstexpr

Default identifier.

Every handler provides a default name which could be used as key in registry to uniquely identify it. There is no obligation to use it, it is only supplied for convenience. In case of many instances of the same handler, using a key derived from this default (such as "my_handler:instance1") is suggested.

This field should be set in derived classes

◆ level_

LogLevel mysql_harness::logging::Handler::level_
private

Log level set for the handler.

◆ precision_

LogTimestampPrecision mysql_harness::logging::Handler::precision_
private

Timestamp precision for logging.


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