ATLAS Offline Software
Loading...
Searching...
No Matches
errorcheck::ReportMessage Class Reference

Helper class to use to report a message. More...

#include <errorcheck.h>

Inheritance diagram for errorcheck::ReportMessage:
Collaboration diagram for errorcheck::ReportMessage:

Public Member Functions

 ReportMessage (MSG::Level level, int line, const char *file, const char *func, const char *pkg, const std::string &context, StatusCode sc)
 Constructor.
 ReportMessage (MSG::Level level, int line, const char *file, const char *func, const char *pkg, const std::string &context)
 Constructor.
 ~ReportMessage ()
 Destructor.
virtual MsgStream & doOutput () override
 Emit the message.
MsgStream & msgstream ()
 Convert to a MsgStream reference.

Static Public Member Functions

static void hideErrorLocus (bool flag=true)
 If set to true, hide the source file and line number in the output.
static void hideFunctionNames (bool flag=true)
 If set to true, hide function names in the output.

Private Member Functions

void format_common (MSG::Level level, int line, const char *file, const char *func, const char *pkg)
 Generate the common header for messages.

Private Attributes

std::string::size_type m_pos
 The position in the output message after the standard header.

Static Private Attributes

static std::atomic< bool > s_hide_error_locus
 If true, hide the source file and line number in output messages.
static std::atomic< bool > s_hide_function_names
 If true, hide the function names in output messages.

Detailed Description

Helper class to use to report a message.

To report a message, create an instance of this class. A standard header, containing the file/line, context name, and so forth, is automatically put at the start of the message. More text may be added using the standard MsgStream streaming operators. The message is actually emitted when this object is destroyed.

Definition at line 171 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

Constructor & Destructor Documentation

◆ ReportMessage() [1/2]

errorcheck::ReportMessage::ReportMessage ( MSG::Level level,
int line,
const char * file,
const char * func,
const char * pkg,
const std::string & context,
StatusCode sc )

Constructor.

Parameters
levelThe error logging level for the message.
lineThe source line from which the report is being made.
fileThe source file name from which the report is being made.
funcThe name of the function from which the report is being made.
pkgThe name of the package from which the report is being made.
contextThe name of the context (algorithm/tool/service/etc.) from which the report is being made.
scThe StatusCode to include in the error message.

Definition at line 64 of file errorcheck.cxx.

71 : MsgStream (Athena::getMessageSvc(), context)
72{
73 // The common part.
74 format_common (level, line, file, func, pkg);
75
76 // The status code.
77 *this << ": code " << sc;
78
79 // Remember the end of the header.
80 m_pos = stream().str().size();
81}
static Double_t sc
std::string::size_type m_pos
The position in the output message after the standard header.
void format_common(MSG::Level level, int line, const char *file, const char *func, const char *pkg)
Generate the common header for messages.
IMessageSvc * getMessageSvc(bool quiet=false)
TFile * file

◆ ReportMessage() [2/2]

errorcheck::ReportMessage::ReportMessage ( MSG::Level level,
int line,
const char * file,
const char * func,
const char * pkg,
const std::string & context )

Constructor.

Parameters
levelThe error logging level for the message.
lineThe source line from which the report is being made.
fileThe source file name from which the report is being made.
funcThe name of the function from which the report is being made.
pkgThe name of the package from which the report is being made.
contextThe name of the context (algorithm/tool/service/etc.) from which the report is being made.

Definition at line 94 of file errorcheck.cxx.

100 : MsgStream (Athena::getMessageSvc(), context)
101{
102 // The common part.
103 format_common (level, line, file, func, pkg);
104
105 // Remember the end of the header.
106 m_pos = stream().str().size();
107}

◆ ~ReportMessage()

errorcheck::ReportMessage::~ReportMessage ( )

Destructor.

This will cause the message to be emitted, if it hasn't already been.

Definition at line 152 of file errorcheck.cxx.

153{
154 // Don't do anything if the message has already been emitted
155 // (due to using << endmsg, for example).
156 if (!stream().str().empty())
157 *this << endmsg;
158}
#define endmsg
static const Attributes_t empty

Member Function Documentation

◆ doOutput()

MsgStream & errorcheck::ReportMessage::doOutput ( )
overridevirtual

Emit the message.

We override this method from MsgStream in order to fix up the message punctuation.

Definition at line 166 of file errorcheck.cxx.

167{
168 // The deal here is this. We want
169 // REPORT_MESSAGE(MSG::INFO) << "foo";
170 // to get a `: ' before the `foo'.
171 // But we don't want
172 // REPORT_MESSAGE(MSG::INFO);
173 // to have a trailing `: '.
174 // So, after we generate the common header part, we remember
175 // where we are in the string. When the message is emitted, we look
176 // to see if additional text has been added. If not, then we don't
177 // need to do anything. But if so, we insert a `: ' after the header.
178 if (m_pos != stream().str().size()) {
179 std::string tmp1 = stream().str();
180 std::string tmp2 = tmp1.substr(0, m_pos);
181 tmp2 += ": ";
182 tmp2.append( tmp1, m_pos);
183 stream().str (tmp2);
184 }
185 return MsgStream::doOutput();
186}

◆ format_common()

void errorcheck::ReportMessage::format_common ( MSG::Level level,
int line,
const char * file,
const char * func,
const char * pkg )
private

Generate the common header for messages.

Parameters
levelThe error logging level for the message.
lineThe source line from which the report is being made.
fileThe source file name from which the report is being made.
funcThe name of the function from which the report is being made.
pkgThe name of the package from which the report is being made.

Definition at line 118 of file errorcheck.cxx.

123{
124 // Logging level.
125 *this << level;
126
127 // Write the source file/line.
129 *this << "FILE:LINE";
130 else {
131 if (pkg && pkg[0] != '\0')
132 *this << munge_filename(file, pkg) << ":" << line;
133 else
134 *this << file << ":" << line;
135 }
136
137 // Include the function name if available.
139 *this << " (FUNC)";
140 else {
141 if (func && func[0] != '\0') {
142 *this << " (" << CxxUtils::normalizeFunctionName(func) << ")";
143 }
144 }
145}
static std::atomic< bool > s_hide_function_names
If true, hide the function names in output messages.
static std::atomic< bool > s_hide_error_locus
If true, hide the source file and line number in output messages.
std::string normalizeFunctionName(const std::string &fname)
Normalize a pretty-printed C++ function name.
std::string munge_filename(const std::string &file, const std::string &pkg)
Shorten filename.

◆ hideErrorLocus()

void errorcheck::ReportMessage::hideErrorLocus ( bool flag = true)
static

If set to true, hide the source file and line number in the output.

This is intended for use in regression tests, where it's undesirable to have the output change if source lines are added or deleted.

Definition at line 197 of file errorcheck.cxx.

198{
200}
bool flag
Definition master.py:29

◆ hideFunctionNames()

void errorcheck::ReportMessage::hideFunctionNames ( bool flag = true)
static

If set to true, hide function names in the output.

in the output.

This is intended for use in regression tests, where function names may be formatted differently on different platforms.

Definition at line 211 of file errorcheck.cxx.

212{
214}

◆ msgstream()

MsgStream & errorcheck::ReportMessage::msgstream ( )
inline

Convert to a MsgStream reference.

Trying to use a ReportMessage like

ReportMessage(...) << "foo";
ReportMessage(MSG::Level level, int line, const char *file, const char *func, const char *pkg, const std::string &context, StatusCode sc)
Constructor.

doesn't work, because (as of Gaudi 19) the MsgStream inserters are written as free functions:

MsgStream& operator<< (MsgStream&, ...);
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)

and the non-const MsgStream reference won't bind to the temporary. We can work around this problem with this method, which will convert the temporary to a non-const reference. So, this should work:

ReportMessage(...).stream() << "foo";

Definition at line 251 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

251{ return *this; }

Member Data Documentation

◆ m_pos

std::string::size_type errorcheck::ReportMessage::m_pos
private

The position in the output message after the standard header.

Definition at line 292 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

◆ s_hide_error_locus

std::atomic< bool > errorcheck::ReportMessage::s_hide_error_locus
staticprivate

If true, hide the source file and line number in output messages.

Definition at line 295 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.

◆ s_hide_function_names

std::atomic< bool > errorcheck::ReportMessage::s_hide_function_names
staticprivate

If true, hide the function names in output messages.

Definition at line 298 of file Control/AthenaKernel/AthenaKernel/errorcheck.h.


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