Belle II Software light-2406-ragdoll
LogConnectionTxtFile.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/logging/LogConnectionTxtFile.h>
10#include <framework/logging/LogMessage.h>
11
12using namespace Belle2;
13using namespace std;
14
15LogConnectionTxtFile::LogConnectionTxtFile(const string& filename, bool append): 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}
19
21
23{
24 return (bool)m_fileStream;
25}
26
28{
29 if (isConnected()) {
30 m_fileStream << message;
31 return true;
32 } else return false;
33}
34
36{
37 m_fileStream.close();
38}
virtual ~LogConnectionTxtFile()
The LogConnectionTxtFile destructor.
std::ofstream m_fileStream
The file output stream used for sending the log message.
LogConnectionTxtFile(const std::string &filename, bool append=false)
The constructor.
bool isConnected() override
Returns true if the connection to the text file could be established.
bool sendMessage(const LogMessage &message) override
Sends a log message.
void finalizeOnAbort() override
Make sure the file is closed on abort.
The LogMessage class.
Definition: LogMessage.h:29
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.