Belle II Software light-2406-ragdoll
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.
 
virtual ~LogConnectionTxtFile ()
 The LogConnectionTxtFile destructor.
 
bool sendMessage (const LogMessage &message) override
 Sends a log message.
 
bool isConnected () override
 Returns true if the connection to the text file could be established.
 
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

◆ finalizeOnAbort()

void finalizeOnAbort ( )
overridevirtual

Make sure the file is closed on abort.

Reimplemented from LogConnectionBase.

Definition at line 35 of file LogConnectionTxtFile.cc.

36{
37 m_fileStream.close();
38}

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

23{
24 return (bool)m_fileStream;
25}

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

28{
29 if (isConnected()) {
30 m_fileStream << message;
31 return true;
32 } else return false;
33}
bool isConnected() override
Returns true if the connection to the text file could be established.

Member Data Documentation

◆ m_fileStream

std::ofstream m_fileStream
private

The file output stream used for sending the log message.

Definition at line 62 of file LogConnectionTxtFile.h.


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