ATLAS Offline Software
Loading...
Searching...
No Matches
LogFileMsgStream.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef LOGFILEMSGSTREAM_H
6#define LOGFILEMSGSTREAM_H
7
8// ********************************************************************
9//
10// NAME: LogFileMsgStream.H
11//
12// DESCRIPTION: class for piping output to logfile and MessageSvc
13//
14// AUTHOR: Rolf Seuster 27.10.2005: 1st implementation
15//
16// ********************************************************************
17
18#include "GaudiKernel/MsgStream.h"
19#include "GaudiKernel/Message.h"
20
21#include <fstream>
22#include <string>
23
24class LogFileMsgStream : public MsgStream {
25 public:
26 // constructor
27 LogFileMsgStream(IMessageSvc* svc,
28 const std::string& source,
29 const std::string& filename,
30 bool startlogging ) :
31 MsgStream(svc, source), m_FormatString("")
32 {
33 if(startlogging)
34 m_logfile.open(filename.c_str(),
35 std::ofstream::out | std::ofstream::app);
36 };
37
38 // destructor
40 if(m_logfile.is_open())
41 m_logfile.close();
42 };
43
45 // almost plain copy from MsgStream.h
46 LogFileMsgStream& operator<< (MSG::Level level) {
47 return (LogFileMsgStream&)MsgStream::report(level);
48 }
49
51 // template <typename T>
52 // copied from MsgStream.h, doesn't work for all types (vectors)
53 // but that deficit doesn't harm
54 template <class T>
55 MsgStream& operator<< (const T& arg) {
56 if(isActive()) m_stream << arg;
57 return *this;
58 }
59
60 // copied from MsgStream.cpp
61 // here we copy the output to a file as well
62 MsgStream& doOutput() {
63 Message msg(m_source,m_currLevel,m_stream.str());
64 if(m_FormatString!="")
65 msg.setFormat(m_FormatString);
66 if(m_logfile.is_open())
67 m_logfile << msg << "\n";
68 return MsgStream::doOutput();
69 }
70
71 void setFormat(const std::string& str) {
73 }
74
75 private:
76 // default constructor, unusable !
78
79 std::ofstream m_logfile;
80
81 std::string m_FormatString;
82
83};
84
85#endif
std::string m_FormatString
void setFormat(const std::string &str)
LogFileMsgStream(IMessageSvc *svc, const std::string &source, const std::string &filename, bool startlogging)
LogFileMsgStream & operator<<(MSG::Level level)
Accept MsgStream activation using MsgStreamer operator.
std::ofstream m_logfile
MsgStream & doOutput()
MsgStream & msg
Definition testRead.cxx:32