IssueLogger Class Reference

#include <src/IssueLogger.h>

Inheritance diagram for IssueLogger:
Collaboration diagram for IssueLogger:

Classes

class  logger_t
 

Public Member Functions

 IssueLogger (const std::string &name, ISvcLocator *svc)
 
 ~IssueLogger () override=default
 
StatusCode initialize () override
 
StatusCode reinitialize () override
 
StatusCode finalize () override
 
void report (IssueSeverity::Level level, const std::string &msg, const std::string &origin)
 
void report (const IssueSeverity &err)
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Member Functions

StatusCode connect (const std::string &)
 
void setupDefaultLogger ()
 
void setupLevels (Property &prop)
 
void setupStreams (Property &prop)
 

Private Attributes

StringArrayProperty m_outputfile
 
StringProperty m_reportLevelS
 
StringProperty m_traceLevelS
 
BooleanProperty m_showTime
 
IssueSeverity::Level m_reportLevel
 
IssueSeverity::Level m_traceLevel
 
std::array< logger_t, IssueSeverity::NUM_LEVELSm_log
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

Definition at line 14 of file IssueLogger.h.

Constructor & Destructor Documentation

IssueLogger::IssueLogger ( const std::string &  name,
ISvcLocator svc 
)

Definition at line 72 of file IssueLogger.cpp.

73  : base_class(name, svc) {
74 
75  declareProperty ("Output", m_outputfile );
76  declareProperty ("ReportLevel", m_reportLevelS="WARNING");
77  declareProperty ("TracebackLevel", m_traceLevelS="ERROR");
78  declareProperty ("ShowTime", m_showTime=false);
79 
83 
86 
87 }
StringArrayProperty m_outputfile
Definition: IssueLogger.h:29
IssueSeverity::Level m_reportLevel
Definition: IssueLogger.h:32
StringProperty m_reportLevelS
Definition: IssueLogger.h:30
extends base_class
Typedef to this class.
Definition: extends.h:14
void setupStreams(Property &prop)
void setupLevels(Property &prop)
virtual void declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
Definition: Property.cpp:71
IssueSeverity::Level m_traceLevel
Definition: IssueLogger.h:32
BooleanProperty m_showTime
Definition: IssueLogger.h:31
StringProperty m_traceLevelS
Definition: IssueLogger.h:30
IssueLogger::~IssueLogger ( )
overridedefault

Member Function Documentation

StatusCode IssueLogger::connect ( const std::string &  ident)
private

Definition at line 126 of file IssueLogger.cpp.

126  {
127 
128  MsgStream log ( msgSvc(), name() );
129 
130  auto loc = ident.find(" ");
131  using Parser = Gaudi::Utils::AttribStringParser;
132  // note: if loc == string::npos then loc + 1 == 0
133  for (auto attrib: Parser(ident.substr(loc + 1))) {
134  toupper(attrib.tag);
136  if (attrib.tag == "DEBUG") { level = IssueSeverity::DEBUG;
137  } else if ( attrib.tag == "INFO") { level = IssueSeverity::INFO;
138  } else if ( attrib.tag == "WARNING") { level = IssueSeverity::WARNING;
139  } else if ( attrib.tag == "RECOVERABLE") { level = IssueSeverity::RECOVERABLE;
140  } else if ( attrib.tag == "ERROR") { level = IssueSeverity::ERROR;
141  } else if ( attrib.tag == "FATAL") { level = IssueSeverity::FATAL;
142  } else {
143  log << MSG::ERROR << "Unknown output level \"" << attrib.tag << "\""
144  << endmsg;
145  continue;
146  }
147 
148  if (m_log[level]) {
149  log << MSG::INFO << "closing stream " << m_log[level].name() << endmsg;
150  m_log[level].reset();
151  }
152 
153  if (attrib.value == "MsgSvc") {
154  m_log[level] = { new StreamLogger(msgSvc(), s_sevMsgMap.at(level)) , &StreamLogger::WriteToMsgSvc };
155  } else if (attrib.value == "STDERR") {
156  m_log[level] = { new StreamLogger(std::cerr), &StreamLogger::WriteToStream };
157  } else if (attrib.value == "STDOUT") {
158  m_log[level] = { new StreamLogger(std::cout), &StreamLogger::WriteToStream };
159  } else { // A file
160  try {
161  m_log[level] = { new StreamLogger(attrib.value), &StreamLogger::WriteToStream };
162  }
163  catch (std::exception&) {
164  m_log[level].reset();
165  log << MSG::ERROR << "Unable to open file \"" << attrib.value
166  << "\" for writing issues at level " << attrib.tag << endmsg;
167  return StatusCode::FAILURE;
168  }
169  }
170  log << MSG::DEBUG << "Writing " << s_levelTrans.at(level)
171  << " issues to " << m_log[level].name() << endmsg;
172  }
173  return StatusCode::SUCCESS;
174 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void toupper(std::string &s)
Definition: IssueLogger.cpp:64
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:46
void WriteToMsgSvc(const std::string &str)
Definition: StreamLogger.h:20
void WriteToStream(const std::string &str)
Definition: StreamLogger.h:19
StatusCode IssueLogger::finalize ( )
override

Definition at line 113 of file IssueLogger.cpp.

113  {
114 
115  MsgStream log ( msgSvc(), name() );
116  log << MSG::DEBUG << "IssueLogger::finalize" << endmsg;
117  std::for_each( std::begin(m_log), std::end(m_log),
118  [](logger_t& i)
119  { i.reset(); } );
120  return Service::finalize();
121 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode finalize() override
Definition: Service.cpp:187
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:46
list i
Definition: ana.py:128
StatusCode IssueLogger::initialize ( )
override

Definition at line 92 of file IssueLogger.cpp.

92  {
93 
95  if (st.isSuccess()) { setupDefaultLogger(); }
96  return st;
97 }
StatusCode initialize() override
Definition: Service.cpp:62
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
void setupDefaultLogger()
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode IssueLogger::reinitialize ( )
override

Definition at line 102 of file IssueLogger.cpp.

102  {
103 
104  MsgStream log ( msgSvc(), name() );
105  log << MSG::WARNING << "reinitialize not implemented" << endmsg;
106  return StatusCode::SUCCESS;
107 
108 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void IssueLogger::report ( IssueSeverity::Level  level,
const std::string &  msg,
const std::string &  origin 
)

Definition at line 179 of file IssueLogger.cpp.

180  {
181  if ( lev < m_reportLevel) return;
182  std::string msg = s_levelTrans.at(lev) + " " + org + " \"" + str + "\"";
183  if (m_showTime) msg += " [" + Gaudi::Time::current().format(true, "%H:%M:%S %Y/%m/%d %Z") +"]";
184  if (lev >= m_traceLevel) msg += "\n" + getTraceBack();
185  m_log[lev](msg);
186 }
static Time current(void)
Returns the current time.
Definition: Time.cpp:113
IssueSeverity::Level m_reportLevel
Definition: IssueLogger.h:32
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:46
IssueSeverity::Level m_traceLevel
Definition: IssueLogger.h:32
BooleanProperty m_showTime
Definition: IssueLogger.h:31
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
Definition: Time.cpp:279
void IssueLogger::report ( const IssueSeverity err)

Definition at line 191 of file IssueLogger.cpp.

191  {
192  report(err.getLevel(), err.getMsg(), err.getOrigin());
193 }
std::string getOrigin() const
void report(IssueSeverity::Level level, const std::string &msg, const std::string &origin)
IssueSeverity::Level getLevel() const
Definition: IssueSeverity.h:82
std::string getMsg() const
Definition: IssueSeverity.h:83
void IssueLogger::setupDefaultLogger ( )
private

Definition at line 254 of file IssueLogger.cpp.

254  {
255  for (int i=1; i<IssueSeverity::NUM_LEVELS; ++i) {
256  if (!m_log[i]) {
257  // default: dump to msgSvc
259  m_log[j] = { new StreamLogger(msgSvc(), s_sevMsgMap.at(j)) , &StreamLogger::WriteToMsgSvc };
260  MsgStream log ( msgSvc(), name() );
261  log << MSG::DEBUG << "Writing " << s_levelTrans.at(j)
262  << " issues to " << m_log[j].name() << endmsg;
263  }
264  }
265 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:46
void WriteToMsgSvc(const std::string &str)
Definition: StreamLogger.h:20
list i
Definition: ana.py:128
void IssueLogger::setupLevels ( Property prop)
private

Definition at line 198 of file IssueLogger.cpp.

198  {
199 
200  StringProperty *sap = dynamic_cast<StringProperty*> (&prop);
201  if (!sap) {
202  MsgStream log ( msgSvc(), name() );
203  log << MSG::ERROR << "Could not convert " << prop.name()
204  << "to a StringProperty (which it should be!)" << endmsg;
205  return;
206  }
207 
208  const std::string& val = sap->value();
209  auto set = [&](IssueSeverity::Level& key, IssueSeverity::Level def) {
210  if (s_levelSTrans.find(val) == s_levelSTrans.end()) {
211  key = def;
212  MsgStream log ( this->msgSvc(), this->name() );
213  log << MSG::ERROR << "Option " << prop.name() << ": unknown Issue Severity level \""
214  << val << "\". Setting it " << s_levelTrans.at(def) << endmsg;
215  } else {
216  key = s_levelSTrans.at(val);
217  }
218  };
219 
220  if (prop.name() == "ReportLevel") {
222  } else if (prop.name() == "TracebackLevel") {
224  } else {
225  MsgStream log ( msgSvc(), name() );
226  log << MSG::ERROR << "setting up unknown property \""
227  << prop.name() << "\"" << endmsg;
228  }
229 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
const std::string & name() const
property name
Definition: Property.h:45
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IssueSeverity::Level m_reportLevel
Definition: IssueLogger.h:32
const TYPE & value() const
explicit conversion
Definition: Property.h:341
IssueSeverity::Level m_traceLevel
Definition: IssueLogger.h:32
void IssueLogger::setupStreams ( Property prop)
private

Definition at line 234 of file IssueLogger.cpp.

234  {
235 
236  StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop );
237  if ( !sap ) {
238  MsgStream log ( msgSvc(), name() );
239  log << MSG::ERROR << "Could not convert " << prop.name()
240  << "to a StringArrayProperty (which it should be!)" << endmsg;
241  return;
242  }
243  for (const auto& s : sap->value() ) {
244  if (connect(s).isFailure()) {
245  MsgStream log ( msgSvc(), name() );
246  log << MSG::ERROR << "Could not setup stream " << s << endmsg;
247  }
248  }
249 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode connect(const std::string &)
const std::string & name() const
property name
Definition: Property.h:45
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
const TYPE & value() const
explicit conversion
Definition: Property.h:341
string s
Definition: gaudirun.py:246

Member Data Documentation

std::array<logger_t,IssueSeverity::NUM_LEVELS> IssueLogger::m_log
private

Definition at line 46 of file IssueLogger.h.

StringArrayProperty IssueLogger::m_outputfile
private

Definition at line 29 of file IssueLogger.h.

IssueSeverity::Level IssueLogger::m_reportLevel
private

Definition at line 32 of file IssueLogger.h.

StringProperty IssueLogger::m_reportLevelS
private

Definition at line 30 of file IssueLogger.h.

BooleanProperty IssueLogger::m_showTime
private

Definition at line 31 of file IssueLogger.h.

IssueSeverity::Level IssueLogger::m_traceLevel
private

Definition at line 32 of file IssueLogger.h.

StringProperty IssueLogger::m_traceLevelS
private

Definition at line 30 of file IssueLogger.h.


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