MySQL 9.0.0
Source Code Documentation
mysql_harness::logging::FileHandler Class Reference

Handler that writes to a file. More...

#include <handler.h>

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

Public Member Functions

 FileHandler (const Path &path, bool format_messages=true, LogLevel level=LogLevel::kNotSet, LogTimestampPrecision timestamp_precision=LogTimestampPrecision::kNotSet)
 
 ~FileHandler () override
 
void reopen (const std::string dst="") override
 Request to reopen underlying log sink. More...
 
- Public Member Functions inherited from mysql_harness::logging::StreamHandler
 StreamHandler (std::ostream &stream, bool format_messages=true, LogLevel level=LogLevel::kNotSet, LogTimestampPrecision timestamp_precision=LogTimestampPrecision::kNotSet)
 
- Public Member Functions inherited from mysql_harness::logging::Handler
 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)
 
bool has_logged () const
 check if the handler has logged at least one record. More...
 

Static Public Attributes

static constexpr const char * kDefaultName = "file"
 
- Static Public Attributes inherited from mysql_harness::logging::StreamHandler
static constexpr const char * kDefaultName = "stream"
 
- Static Public Attributes inherited from mysql_harness::logging::Handler
static constexpr const char * kDefaultName = nullptr
 Default identifier. More...
 

Private Member Functions

void do_log (const Record &record) override
 Log message handler primitive. More...
 

Private Attributes

const Path file_path_
 
std::ofstream fstream_
 

Additional Inherited Members

- Protected Member Functions inherited from mysql_harness::logging::Handler
std::string format (const Record &record) const
 
 Handler (bool format_messages, LogLevel level, LogTimestampPrecision timestamp_precision)
 
void has_logged (bool v)
 
- Protected Attributes inherited from mysql_harness::logging::StreamHandler
std::ostream & stream_
 
std::mutex stream_mutex_
 

Detailed Description

Handler that writes to a file.

Logger logger("my_module");
...
logger.add_handler(FileHandler("/var/log/router.log"));
FileHandler(const Path &path, bool format_messages=true, LogLevel level=LogLevel::kNotSet, LogTimestampPrecision timestamp_precision=LogTimestampPrecision::kNotSet)
Definition: handler.cc:163
static Logger logger
The "top-level" logger used when no connection context is given.
Definition: test_trace_plugin.cc:296

Constructor & Destructor Documentation

◆ FileHandler()

mysql_harness::logging::FileHandler::FileHandler ( const Path path,
bool  format_messages = true,
LogLevel  level = LogLevel::kNotSet,
LogTimestampPrecision  timestamp_precision = LogTimestampPrecision::kNotSet 
)
explicit

◆ ~FileHandler()

mysql_harness::logging::FileHandler::~FileHandler ( )
overridedefault

Member Function Documentation

◆ do_log()

void mysql_harness::logging::FileHandler::do_log ( const Record record)
overrideprivatevirtual

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.

Reimplemented from mysql_harness::logging::StreamHandler.

◆ reopen()

void mysql_harness::logging::FileHandler::reopen ( const std::string  dst = "")
overridevirtual

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.

Reimplemented from mysql_harness::logging::StreamHandler.

Member Data Documentation

◆ file_path_

const Path mysql_harness::logging::FileHandler::file_path_
private

◆ fstream_

std::ofstream mysql_harness::logging::FileHandler::fstream_
private

◆ kDefaultName

constexpr const char* mysql_harness::logging::FileHandler::kDefaultName = "file"
staticconstexpr

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