Belle II Software  release-05-02-19
LogConnectionTxtFile.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/logging/LogConnectionTxtFile.h>
12 #include <framework/logging/LogMessage.h>
13 
14 using namespace Belle2;
15 using namespace std;
16 
17 LogConnectionTxtFile::LogConnectionTxtFile(const string& filename, bool append): m_fileStream{filename.c_str(), append ? ios::app : ios::out}
18 {
19  if (!m_fileStream.is_open()) throw std::runtime_error("Cannot open output file '" + filename + "': " + strerror(errno));
20 }
21 
23 
25 {
26  return (bool)m_fileStream;
27 }
28 
30 {
31  if (isConnected()) {
32  m_fileStream << message;
33  return true;
34  } else return false;
35 }
36 
38 {
39  m_fileStream.close();
40 }
Belle2::LogConnectionTxtFile::LogConnectionTxtFile
LogConnectionTxtFile(const std::string &filename, bool append=false)
The constructor.
Definition: LogConnectionTxtFile.cc:17
Belle2::LogConnectionTxtFile::m_fileStream
std::ofstream m_fileStream
The file output stream used for sending the log message.
Definition: LogConnectionTxtFile.h:72
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::LogConnectionTxtFile::finalizeOnAbort
void finalizeOnAbort() override
Make sure the file is closed on abort.
Definition: LogConnectionTxtFile.cc:37
Belle2::LogConnectionTxtFile::isConnected
bool isConnected() override
Returns true if the connection to the text file could be established.
Definition: LogConnectionTxtFile.cc:24
Belle2::LogConnectionTxtFile::sendMessage
bool sendMessage(const LogMessage &message) override
Sends a log message.
Definition: LogConnectionTxtFile.cc:29
Belle2::LogConnectionTxtFile::~LogConnectionTxtFile
virtual ~LogConnectionTxtFile()
The LogConnectionTxtFile destructor.
Belle2::LogMessage
The LogMessage class.
Definition: LogMessage.h:39