MySQL 8.3.0
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:

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 ( )

◆ Handler() [2/3]

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

◆ ~Handler()

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

◆ Handler() [3/3]

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

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.

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

◆ get_level()

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

◆ handle()

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

◆ has_logged() [1/2]

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

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)

◆ operator=()

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

◆ 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)

◆ set_timestamp_precision()

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

Member Data Documentation

◆ format_messages_

bool mysql_harness::logging::Handler::format_messages_

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}

◆ kDefaultName

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

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_

Log level set for the handler.

◆ precision_

LogTimestampPrecision mysql_harness::logging::Handler::precision_

Timestamp precision for logging.

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