6 #include "GaudiKernel/Kernel.h"
7 #include "GaudiKernel/StatusCode.h"
8 #include "GaudiKernel/Message.h"
19 static const std::string levelNames[
MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
20 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
24 : base_class(
name, svcloc ), m_keysUsed(false)
27 m_outputLevel = MSG::INFO;
28 declareProperty(
"Format",
m_defaultFormat = Message::getDefaultFormat() );
30 declareProperty(
"showStats",
m_stats =
false );
42 declareProperty(
"useColors",
m_color=
false);
46 declareProperty(
"errorColorCode",
m_logColors[MSG::ERROR] );
47 declareProperty(
"warningColorCode",
m_logColors[MSG::WARNING] );
48 declareProperty(
"infoColorCode",
m_logColors[MSG::INFO] );
64 declareProperty(
"enableSuppression",
m_suppress =
false );
71 declareProperty(
"loggingLevel",
m_logLevel =
MSG::FATAL,
"Message level above which all messages are saved" );
74 declareProperty(
"keywords",
m_keywords,
"keywords to scan messages for and save");
77 declareProperty(
"loggedStreams",
79 "MessageStream sources we want to dump into a logfile" );
100 for ( ; iStream != endStream; ++iStream ) {
101 delete iStream->second;
102 iStream->second =
nullptr;
112 if(
sc.isFailure() )
return sc;
138 return StatusCode::SUCCESS;
145 m_state = Gaudi::StateMachine::OFFLINE;
156 vector<string> fatDef;
157 fatDef.push_back(
"[94;101;1m" );
164 vector<string> errDef;
165 errDef.push_back(
"[97;101;1m" );
172 vector<string> warDef;
173 warDef.push_back(
"[93;1m" );
198 if (prop.name() ==
"fatalColorCode") {
200 }
else if (prop.name() ==
"errorColorCode") {
202 }
else if (prop.name() ==
"warningColorCode") {
204 }
else if (prop.name() ==
"infoColorCode") {
206 }
else if (prop.name() ==
"debugColorCode") {
208 }
else if (prop.name() ==
"verboseColorCode") {
210 }
else if (prop.name() ==
"alwaysColorCode") {
213 cout <<
"ERROR: Unknown message color parameter: " << prop.name()
219 vector<string>::const_iterator itr;
226 }
else if ((*itr)[0] ==
'[') {
227 code =
"\033" + *itr;
233 vector<string>::const_iterator itr2 = itr + 1;
248 if (prop.name() ==
"fatalLimit") {
250 }
else if (prop.name() ==
"errorLimit") {
252 }
else if (prop.name() ==
"warningLimit") {
254 }
else if (prop.name() ==
"infoLimit") {
256 }
else if (prop.name() ==
"debugLimit") {
258 }
else if (prop.name() ==
"verboseLimit") {
260 }
else if (prop.name() ==
"alwaysLimit") {
261 IntegerProperty *
p =
dynamic_cast<IntegerProperty*
>(&prop);
262 if (
p &&
p->value() != 0) {
263 cout <<
"LoggedMessageSvc ERROR: cannot suppress ALWAYS messages" << endl;
267 }
else if (prop.name() ==
"defaultLimit") {
274 cout <<
"LoggedMessageSvc ERROR: Unknown message limit parameter: "
275 << prop.name() << endl;
285 if (prop.name() ==
"setFatal") {
287 }
else if (prop.name() ==
"setError") {
289 }
else if (prop.name() ==
"setWarning") {
291 }
else if (prop.name() ==
"setInfo") {
293 }
else if (prop.name() ==
"setDebug") {
295 }
else if (prop.name() ==
"setVerbose") {
297 }
else if (prop.name() ==
"setAlways") {
299 }
else if (prop.name() ==
"loggingLevel") {
300 IntegerProperty *iap =
dynamic_cast<IntegerProperty*
>( &prop );
304 }
else if (prop.name() ==
"keywords") {
305 StringArrayProperty *sap =
dynamic_cast<StringArrayProperty*
>( &prop );
306 if (sap!=
nullptr && sap->value().size() > 0) {
313 cerr <<
"LoggedMessageSvc ERROR: Unknown message theshold parameter: "
314 << prop.name() << endl;
318 StringArrayProperty *sap =
dynamic_cast<StringArrayProperty*
>( &prop);
319 if (sap ==
nullptr) {
320 std::cerr <<
"could not dcast " << prop.name()
321 <<
" to a StringArrayProperty (which it should be!)" << endl;
324 std::vector<std::string>::const_iterator itr;
325 for ( itr = sap->value().begin();
326 itr != sap->value().end();
337 if (prop.name() ==
"countInactive") {
339 BooleanProperty *
p =
dynamic_cast<BooleanProperty*
>(&prop);
341 MsgStream::enableCountInactive(
p->value());
352 std::ostringstream
os;
355 os <<
"Summarizing all message counts" << endl;
357 os <<
"Listing sources of suppressed message: " << endl;
360 os <<
"=====================================================" << endl;
361 os <<
" Message Source | Level | Count" << endl;
362 os <<
"-----------------------------+---------+-------------" << endl;
367 std::map<std::string,MsgAry>::const_iterator itr;
374 os.setf(ios_base::left,ios_base::adjustfield);
380 os.setf(ios_base::right,ios_base::adjustfield);
381 os << levelNames[
ic];
386 os << itr->second.msg[
ic];
394 os <<
"=====================================================" << endl;
404 std::ostringstream
os;
405 os <<
"Listing sources of Unprotected and Unseen messages\n";
410 std::map<std::string,MsgAry>::const_iterator itr;
413 if (itr->second.msg[
ic] != 0) {
414 if (itr->first.length() > ml) { ml = itr->first.length(); }
419 for (
unsigned int i=0;
i<ml+25; ++
i) {
425 os.setf(ios_base::left,ios_base::adjustfield);
426 os <<
"Message Source";
428 os <<
"| Level | Count" << endl;
430 for (
unsigned int i=0;
i<ml+3; ++
i) {
433 os <<
"+---------+-----------" << endl;
438 if (itr->second.msg[
ic] != 0) {
441 os.setf(ios_base::left,ios_base::adjustfield);
447 os.setf(ios_base::right,ios_base::adjustfield);
448 os << levelNames[
ic];
453 os << itr->second.msg[
ic];
461 for (
unsigned int i=0;
i<ml+25; ++
i) {
472 return StatusCode::SUCCESS;
484 std::ostringstream os1;
512 if (
msg.getSource() !=
"AthenaSummarySvc") {
513 for (vector<string>::const_iterator itr=
m_keywords.value().begin(); itr!=
m_keywords.value().end(); ++itr) {
514 if (
msg.getMessage().find( *itr ) != string::npos) {
523 std::unique_ptr<Message> suppressed_msg;
529 (*iLog->second) << *cmsg << std::endl;
538 itr->second.msg[
key] += 1;
539 nmsg = itr->second.msg[
key];
554 std::string
str = levelNames[
key] +
" message limit (";
556 str +=
") reached for ";
557 str +=
msg.getSource() +
". Suppressing further output.";
558 suppressed_msg = std::make_unique<Message>(
msg.getSource(),MSG::WARNING,
str);
559 suppressed_msg->setFormat(
msg.getFormat());
560 cmsg = suppressed_msg.get();
572 while(
first != last ) {
573 std::ostream&
stream = *( (*first).second.second );
574 stream << *cmsg << std::endl;
582 (*m_defaultStream) << *cmsg << std::endl <<
std::flush;
628 while(
first != last ) {
631 std::ostringstream os1;
632 os1 <<
"Status Code " <<
key.getCode() << std::ends;
642 std::ostringstream
os2;
643 os2 <<
"Status Code " <<
key.getCode() << std::ends;
697 if (
nullptr !=
stream ) {
703 while(
first != last ) {
704 if ( (*first).second.second ==
stream ) {
722 if (
nullptr !=
stream ) {
728 if ( (*first).second.second ==
stream ) {
797 while(
first != last ) {
811 return m_outputLevel;
825 m_outputLevel = new_level;
837 }
else if (
i->second !=
level ) {
882 typedef std::map<std::string,std::string> StreamMap_t;
884 typedef StreamMap_t::const_iterator StreamMapIter;
886 for ( StreamMapIter iProp = streamMap.begin(), iEnd = streamMap.end();
890 const std::string sourceName = iProp->first;
893 std::set<std::string> outFileNames;
894 for ( StreamMapIter jProp = streamMap.begin();
897 if ( jProp->first != iProp->first ) {
898 outFileNames.insert( jProp->second );
912 const std::set<std::string>& outFileNames )
915 std::ios_base::trunc;
919 if ( iStream != iEnd ) {
920 delete iStream->second;
921 iStream->second =
nullptr;
928 for ( iStream =
m_loggedStreams.begin(); iStream != iEnd; ++iStream ) {
929 if ( outFileNames.find(
outFileName ) != outFileNames.end() ) {
935 std::ofstream *
out =
new std::ofstream(
outFileName.c_str(), openMode );
937 if ( !
out->good() ) {
955 const std::vector< std::pair<std::string, std::string> >&