ATLAS Offline Software
Loading...
Searching...
No Matches
Control
AthenaMonitoring
AthenaMonitoring
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
24
class
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
39
~LogFileMsgStream
() {
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
) {
72
m_FormatString
=
str
;
73
}
74
75
private
:
76
// default constructor, unusable !
77
LogFileMsgStream
();
78
79
std::ofstream
m_logfile
;
80
81
std::string
m_FormatString
;
82
83
};
84
85
#endif
LogFileMsgStream::m_FormatString
std::string m_FormatString
Definition
LogFileMsgStream.h:81
LogFileMsgStream::setFormat
void setFormat(const std::string &str)
Definition
LogFileMsgStream.h:71
LogFileMsgStream::LogFileMsgStream
LogFileMsgStream()
LogFileMsgStream::~LogFileMsgStream
~LogFileMsgStream()
Definition
LogFileMsgStream.h:39
LogFileMsgStream::LogFileMsgStream
LogFileMsgStream(IMessageSvc *svc, const std::string &source, const std::string &filename, bool startlogging)
Definition
LogFileMsgStream.h:27
LogFileMsgStream::operator<<
LogFileMsgStream & operator<<(MSG::Level level)
Accept MsgStream activation using MsgStreamer operator.
Definition
LogFileMsgStream.h:46
LogFileMsgStream::m_logfile
std::ofstream m_logfile
Definition
LogFileMsgStream.h:79
LogFileMsgStream::doOutput
MsgStream & doOutput()
Definition
LogFileMsgStream.h:62
str
Definition
BTagTrackIpAccessor.cxx:11
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.14.0