Belle II Software  release-08-01-10
LogConnectionTxtFile Class Referencefinal

Implements a log connection to a text file. More...

#include <LogConnectionTxtFile.h>

Inheritance diagram for LogConnectionTxtFile:
Collaboration diagram for LogConnectionTxtFile:

Public Member Functions

 LogConnectionTxtFile (const std::string &filename, bool append=false)
 The constructor. More...
 
virtual ~LogConnectionTxtFile ()
 The LogConnectionTxtFile destructor.
 
bool sendMessage (const LogMessage &message) override
 Sends a log message. More...
 
bool isConnected () override
 Returns true if the connection to the text file could be established. More...
 
void finalizeOnAbort () override
 Make sure the file is closed on abort.
 

Private Attributes

std::ofstream m_fileStream
 The file output stream used for sending the log message.
 

Detailed Description

Implements a log connection to a text file.

Inherits from the abstract base class LogConnectionBase.

Definition at line 27 of file LogConnectionTxtFile.h.

Constructor & Destructor Documentation

◆ LogConnectionTxtFile()

LogConnectionTxtFile ( const std::string &  filename,
bool  append = false 
)
explicit

The constructor.

Parameters
filenameThe path and name of the text file.
appendIf this value is set to true, an existing file will not be overridden, but instead the log messages will be added to the end of the file.

Definition at line 15 of file LogConnectionTxtFile.cc.

15  : m_fileStream{filename.c_str(), append ? ios::app : ios::out}
16 {
17  if (!m_fileStream.is_open()) throw std::runtime_error("Cannot open output file '" + filename + "': " + strerror(errno));
18 }
std::ofstream m_fileStream
The file output stream used for sending the log message.

Member Function Documentation

◆ isConnected()

bool isConnected ( )
overridevirtual

Returns true if the connection to the text file could be established.

Returns
True if the connection to the text file could be established.

Implements LogConnectionBase.

Definition at line 22 of file LogConnectionTxtFile.cc.

◆ sendMessage()

bool sendMessage ( const LogMessage message)
overridevirtual

Sends a log message.

Parameters
messageThe log message object.
Returns
Returns true if the message could be send.

Implements LogConnectionBase.

Definition at line 27 of file LogConnectionTxtFile.cc.


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