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) override
 
void report (const IssueSeverity &err) override
 
- Public Member Functions inherited from extends< Service, IIssueLogger >
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::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~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< Service, IIssueLogger >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- 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...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. 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 }
virtual Property & declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
Definition: Property.cpp:72
StringArrayProperty m_outputfile
Definition: IssueLogger.h:30
extends base_class
Typedef to this class.
Definition: extends.h:14
IssueSeverity::Level m_reportLevel
Definition: IssueLogger.h:33
StringProperty m_reportLevelS
Definition: IssueLogger.h:31
void setupStreams(Property &prop)
void setupLevels(Property &prop)
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
IssueSeverity::Level m_traceLevel
Definition: IssueLogger.h:33
BooleanProperty m_showTime
Definition: IssueLogger.h:32
StringProperty m_traceLevelS
Definition: IssueLogger.h:31
IssueLogger::~IssueLogger ( )
overridedefault

Member Function Documentation

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

Definition at line 124 of file IssueLogger.cpp.

124  {
125 
126  auto loc = ident.find(" ");
127  using Parser = Gaudi::Utils::AttribStringParser;
128  // note: if loc == string::npos then loc + 1 == 0
129  for (auto attrib: Parser(ident.substr(loc + 1))) {
130  toupper(attrib.tag);
132  if (attrib.tag == "DEBUG") { level = IssueSeverity::DEBUG;
133  } else if ( attrib.tag == "INFO") { level = IssueSeverity::INFO;
134  } else if ( attrib.tag == "WARNING") { level = IssueSeverity::WARNING;
135  } else if ( attrib.tag == "RECOVERABLE") { level = IssueSeverity::RECOVERABLE;
136  } else if ( attrib.tag == "ERROR") { level = IssueSeverity::ERROR;
137  } else if ( attrib.tag == "FATAL") { level = IssueSeverity::FATAL;
138  } else {
139  error() << "Unknown output level \"" << attrib.tag << "\""
140  << endmsg;
141  continue;
142  }
143 
144  if (m_log[level]) {
145  info() << "closing stream " << m_log[level].name() << endmsg;
146  m_log[level].reset();
147  }
148 
149  if (attrib.value == "MsgSvc") {
150  m_log[level] = { new StreamLogger(msgSvc(), s_sevMsgMap.at(level)) , &StreamLogger::WriteToMsgSvc };
151  } else if (attrib.value == "STDERR") {
153  } else if (attrib.value == "STDOUT") {
155  } else { // A file
156  try {
157  m_log[level] = { new StreamLogger(attrib.value), &StreamLogger::WriteToStream };
158  }
159  catch (std::exception&) {
160  m_log[level].reset();
161  error() << "Unable to open file \"" << attrib.value
162  << "\" for writing issues at level " << attrib.tag << endmsg;
163  return StatusCode::FAILURE;
164  }
165  }
166  debug() << "Writing " << s_levelTrans.at(level)
167  << " issues to " << m_log[level].name() << endmsg;
168  }
169  return StatusCode::SUCCESS;
170 }
Parse attribute strings allowing iteration over the various attributes.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
void toupper(std::string &s)
Definition: IssueLogger.cpp:64
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
STL class.
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:47
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
T substr(T...args)
void WriteToMsgSvc(const std::string &str)
Definition: StreamLogger.h:20
void WriteToStream(const std::string &str)
Definition: StreamLogger.h:19
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode IssueLogger::finalize ( )
override

Definition at line 112 of file IssueLogger.cpp.

112  {
113 
114  debug() << "IssueLogger::finalize" << endmsg;
116  [](logger_t& i)
117  { i.reset(); } );
118  return Service::finalize();
119 }
StatusCode finalize() override
Definition: Service.cpp:193
T end(T...args)
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:47
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T begin(T...args)
T for_each(T...args)
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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:68
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  warning() << "reinitialize not implemented" << endmsg;
105  return StatusCode::SUCCESS;
106 
107 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
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 
)
override

Definition at line 175 of file IssueLogger.cpp.

176  {
177  if ( lev < m_reportLevel) return;
178  std::string msg = s_levelTrans.at(lev) + " " + org + " \"" + str + "\"";
179  if (m_showTime) msg += " [" + Gaudi::Time::current().format(true, "%H:%M:%S %Y/%m/%d %Z") +"]";
180  if (lev >= m_traceLevel) msg += "\n" + getTraceBack();
181  m_log[lev](msg);
182 }
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
static Time current(void)
Returns the current time.
Definition: Time.cpp:113
IssueSeverity::Level m_reportLevel
Definition: IssueLogger.h:33
STL class.
T at(T...args)
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:47
IssueSeverity::Level m_traceLevel
Definition: IssueLogger.h:33
BooleanProperty m_showTime
Definition: IssueLogger.h:32
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)
override

Definition at line 187 of file IssueLogger.cpp.

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

Definition at line 245 of file IssueLogger.cpp.

245  {
246  for (int i=1; i<IssueSeverity::NUM_LEVELS; ++i) {
247  if (!m_log[i]) {
248  // default: dump to msgSvc
250  m_log[j] = { new StreamLogger(msgSvc(), s_sevMsgMap.at(j)) , &StreamLogger::WriteToMsgSvc };
251  debug() << "Writing " << s_levelTrans.at(j)
252  << " issues to " << m_log[j].name() << endmsg;
253  }
254  }
255 }
std::array< logger_t, IssueSeverity::NUM_LEVELS > m_log
Definition: IssueLogger.h:47
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void WriteToMsgSvc(const std::string &str)
Definition: StreamLogger.h:20
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void IssueLogger::setupLevels ( Property prop)
private

Definition at line 194 of file IssueLogger.cpp.

194  {
195 
196  StringProperty *sap = dynamic_cast<StringProperty*> (&prop);
197  if (!sap) {
198  error() << "Could not convert " << prop.name()
199  << "to a StringProperty (which it should be!)" << endmsg;
200  return;
201  }
202 
203  const std::string& val = sap->value();
204  auto set = [&](IssueSeverity::Level& key, IssueSeverity::Level def) {
205  if (s_levelSTrans.find(val) == s_levelSTrans.end()) {
206  key = def;
207  error() << "Option " << prop.name() << ": unknown Issue Severity level \""
208  << val << "\". Setting it " << s_levelTrans.at(def) << endmsg;
209  } else {
210  key = s_levelSTrans.at(val);
211  }
212  };
213 
214  if (prop.name() == "ReportLevel") {
216  } else if (prop.name() == "TracebackLevel") {
218  } else {
219  error() << "setting up unknown property \""
220  << prop.name() << "\"" << endmsg;
221  }
222 }
const std::string & name() const
property name
Definition: Property.h:45
IssueSeverity::Level m_reportLevel
Definition: IssueLogger.h:33
STL class.
T at(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
const TYPE & value() const
explicit conversion
Definition: Property.h:341
IssueSeverity::Level m_traceLevel
Definition: IssueLogger.h:33
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void IssueLogger::setupStreams ( Property prop)
private

Definition at line 227 of file IssueLogger.cpp.

227  {
228 
229  StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop );
230  if ( !sap ) {
231  error() << "Could not convert " << prop.name()
232  << "to a StringArrayProperty (which it should be!)" << endmsg;
233  return;
234  }
235  for (const auto& s : sap->value() ) {
236  if (connect(s).isFailure()) {
237  error() << "Could not setup stream " << s << endmsg;
238  }
239  }
240 }
StatusCode connect(const std::string &)
const std::string & name() const
property name
Definition: Property.h:45
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
const TYPE & value() const
explicit conversion
Definition: Property.h:341
string s
Definition: gaudirun.py:245
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

Member Data Documentation

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

Definition at line 47 of file IssueLogger.h.

StringArrayProperty IssueLogger::m_outputfile
private

Definition at line 30 of file IssueLogger.h.

IssueSeverity::Level IssueLogger::m_reportLevel
private

Definition at line 33 of file IssueLogger.h.

StringProperty IssueLogger::m_reportLevelS
private

Definition at line 31 of file IssueLogger.h.

BooleanProperty IssueLogger::m_showTime
private

Definition at line 32 of file IssueLogger.h.

IssueSeverity::Level IssueLogger::m_traceLevel
private

Definition at line 33 of file IssueLogger.h.

StringProperty IssueLogger::m_traceLevelS
private

Definition at line 31 of file IssueLogger.h.


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