Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MessageSvc.cpp
Go to the documentation of this file.
1 #ifdef _WIN32
2 // Avoid conflicts between windows and the message service.
3 #define NOMSG
4 #define NOGDI
5 #endif
6 
7 #include "GaudiKernel/Kernel.h"
10 #include "GaudiKernel/Message.h"
11 #include "GaudiKernel/xtoa.h"
12 #include "MessageSvc.h"
13 
14 #include <sstream>
15 #include <iostream>
16 #include <fstream>
17 
18 using namespace std;
19 
20 // Instantiation of a static factory class used by clients to create
21 // instances of this service
23 
24 static std::string levelNames[MSG::NUM_LEVELS];
25 
26 // Constructor
27 MessageSvc::MessageSvc( const std::string& name, ISvcLocator* svcloc )
28  : base_class( name, svcloc ) {
29  m_defaultStream = &std::cout;
30  m_outputLevel = MSG::NIL;
31  declareProperty( "Format", m_defaultFormat = Message::getDefaultFormat() );
32  declareProperty( "timeFormat", m_defaultTimeFormat = Message::getDefaultTimeFormat() );
33  declareProperty( "showStats", m_stats = false );
34  declareProperty( "statLevel", m_statLevel = 0 );
35 
36  // Special properties to control output level of individual sources
37  declareProperty( "setVerbose", m_thresholdProp[MSG::VERBOSE] );
38  declareProperty( "setDebug", m_thresholdProp[MSG::DEBUG] );
39  declareProperty( "setInfo", m_thresholdProp[MSG::INFO] );
40  declareProperty( "setWarning", m_thresholdProp[MSG::WARNING] );
41  declareProperty( "setError", m_thresholdProp[MSG::ERROR] );
42  declareProperty( "setFatal", m_thresholdProp[MSG::FATAL] );
43  declareProperty( "setAlways", m_thresholdProp[MSG::ALWAYS] );
44 
45  declareProperty( "useColors", m_color=false);
46  m_color.declareUpdateHandler(&MessageSvc::initColors, this);
47 
48  declareProperty( "fatalColorCode", m_logColors[MSG::FATAL] );
49  declareProperty( "errorColorCode", m_logColors[MSG::ERROR] );
50  declareProperty( "warningColorCode", m_logColors[MSG::WARNING] );
51  declareProperty( "infoColorCode", m_logColors[MSG::INFO] );
52  declareProperty( "debugColorCode", m_logColors[MSG::DEBUG] );
53  declareProperty( "verboseColorCode", m_logColors[MSG::VERBOSE] );
54  declareProperty( "alwaysColorCode", m_logColors[MSG::ALWAYS] );
55 
56  const int defaultLimit = 500;
57  declareProperty( "fatalLimit", m_msgLimit[MSG::FATAL] = defaultLimit );
58  declareProperty( "errorLimit", m_msgLimit[MSG::ERROR] = defaultLimit );
59  declareProperty( "warningLimit", m_msgLimit[MSG::WARNING] = defaultLimit );
60  declareProperty( "infoLimit", m_msgLimit[MSG::INFO] = defaultLimit );
61  declareProperty( "debugLimit", m_msgLimit[MSG::DEBUG] = defaultLimit );
62  declareProperty( "verboseLimit", m_msgLimit[MSG::VERBOSE] = defaultLimit );
63  declareProperty( "alwaysLimit", m_msgLimit[MSG::ALWAYS] = 0 );
64 
65  declareProperty( "defaultLimit", m_msgLimit[MSG::NIL] = defaultLimit );
66 
67  declareProperty( "enableSuppression", m_suppress = false );
68  declareProperty( "countInactive", m_inactCount = false )->declareUpdateHandler( &MessageSvc::setupInactCount, this );
69 #ifndef NDEBUG
70  // initialize the MsgStream static flag.
71  MsgStream::enableCountInactive(m_inactCount);
72 #endif
73 
74  declareProperty( "loggedStreams",
75  m_loggedStreamsName,
76  "MessageStream sources we want to dump into a logfile" );
77 
78  for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
79  m_logColors[ic].declareUpdateHandler(&MessageSvc::setupColors, this);
80  m_msgLimit[ic].declareUpdateHandler(&MessageSvc::setupLimits, this);
81  m_thresholdProp[ic].declareUpdateHandler(&MessageSvc::setupThreshold, this);
82  }
83 
84  levelNames[0] = "NIL";
85  levelNames[1] = "VERBOSE";
86  levelNames[2] = "DEBUG";
87  levelNames[3] = "INFO";
88  levelNames[4] = "WARNING";
89  levelNames[5] = "ERROR";
90  levelNames[6] = "FATAL";
91  levelNames[7] = "ALWAYS";
92 
93  for (int i=0; i<MSG::NUM_LEVELS; ++i) {
94  m_msgCount[i] = 0;
95  }
96 
97 }
98 
99 //#############################################################################
100 
102 {
103  // closing log-files, if any
104  LoggedStreamsMap_t::iterator iStream = m_loggedStreams.begin();
105  LoggedStreamsMap_t::iterator endStream = m_loggedStreams.end();
106  for ( ; iStream != endStream; ++iStream ) {
107  delete iStream->second;
108  iStream->second = 0;
109  }
110 }
111 //#############################################################################
112 
113 
116  StatusCode sc;
117  sc = Service::initialize();
118  if( sc.isFailure() ) return sc;
119  // Release pointer to myself done in Service base class
120  //if( m_msgsvc.isValid() ) {
121  // m_msgsvc = 0;
122  //}
123  // Set my own properties
124  sc = setProperties();
125  if (sc.isFailure()) return sc;
126 
127 #ifdef _WIN32
128  m_color = false;
129 #endif
130 
131  m_colMap["black"] = MSG::BLACK;
132  m_colMap["red"] = MSG::RED;
133  m_colMap["green"] = MSG::GREEN;
134  m_colMap["yellow"] = MSG::YELLOW;
135  m_colMap["blue"] = MSG::BLUE;
136  m_colMap["purple"] = MSG::PURPLE;
137  m_colMap["cyan"] = MSG::CYAN;
138  m_colMap["white"] = MSG::WHITE;
139 
140  // make sure the map of logged stream names is initialized
141  setupLogStreams();
142 
143  return StatusCode::SUCCESS;
144 }
145 
146 //#############################################################################
147 
151  return initialize();
152 }
153 
154 //#############################################################################
155 
157 
158  if (m_color == true) {
159 
160  if (m_logColors[MSG::FATAL].value().size() == 0) {
161  vector<string> fatDef;
162  fatDef.push_back( "[94;101;1m" );
163  m_logColors[MSG::FATAL].set( fatDef );
164  } else {
165  MessageSvc::setupColors( m_logColors[MSG::FATAL] );
166  }
167 
168  if (m_logColors[MSG::ERROR].value().size() == 0) {
169  vector<string> errDef;
170  errDef.push_back( "[97;101;1m" );
171  m_logColors[MSG::ERROR].set( errDef );
172  } else {
173  MessageSvc::setupColors( m_logColors[MSG::ERROR] );
174  }
175 
176  if (m_logColors[MSG::WARNING].value().size() == 0) {
177  vector<string> warDef;
178  warDef.push_back( "[93;1m" );
179  m_logColors[MSG::WARNING].set( warDef );
180  } else {
181  MessageSvc::setupColors( m_logColors[MSG::WARNING] );
182  }
183 
184  } else {
185 
186  // reset all color codes;
187  for (int ic=0; ic<MSG::NUM_LEVELS; ++ic) {
188  vector<string> def;
189  m_logColors[ic].set( def );
190  }
191 
192  }
193 
194 }
195 
196 //#############################################################################
197 
199 
200  if (! m_color) return;
201 
202  int ic;
203  if (prop.name() == "fatalColorCode") {
204  ic = MSG::FATAL;
205  } else if (prop.name() == "errorColorCode") {
206  ic = MSG::ERROR;
207  } else if (prop.name() == "warningColorCode") {
208  ic = MSG::WARNING;
209  } else if (prop.name() == "infoColorCode") {
210  ic = MSG::INFO;
211  } else if (prop.name() == "debugColorCode") {
212  ic = MSG::DEBUG;
213  } else if (prop.name() == "verboseColorCode") {
214  ic = MSG::VERBOSE;
215  } else if (prop.name() == "alwaysColorCode") {
216  ic = MSG::ALWAYS;
217  } else {
218  cout << "ERROR: Unknown message color parameter: " << prop.name()
219  << endl;
220  return;
221  }
222 
223  string code;
225  itr = m_logColors[ic].value().begin();
226 
227  if ( m_logColors[ic].value().size() == 1 ) {
228 
229  if (*itr == "") {
230  code = "";
231  } else if (itr->substr(0,1) == "[") {
232  code = "\033" + *itr;
233  } else {
234  code = "\033[" + colTrans(*itr, 90) + ";1m";
235  }
236 
237  } else if (m_logColors[ic].value().size() == 2) {
238  vector<string>::const_iterator itr2 = itr + 1;
239 
240  code = "\033[" + colTrans(*itr, 90) + ";"
241  + colTrans(*itr2, 100) + ";1m";
242 
243  }
244 
245  m_logColorCodes[ic] = code;
246 
247 }
248 //#############################################################################
249 
251  // Just report problems in the settings of the limits and unknown limit parameters
252  if (prop.name() == "alwaysLimit") {
253  IntegerProperty *p = dynamic_cast<IntegerProperty*>(&prop);
254  if (p && p->value() != 0) {
255  cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << endl;
256  p->setValue(0);
257  }
258  } else if (prop.name() == "defaultLimit") {
259  for (int i = MSG::VERBOSE; i< MSG::NUM_LEVELS; ++i) {
260  if (i != MSG::ALWAYS) {
261  m_msgLimit[i] = m_msgLimit[MSG::NIL].value();
262  }
263  }
264  } else if (prop.name() != "fatalLimit" &&
265  prop.name() != "errorLimit" &&
266  prop.name() != "warningLimit" &&
267  prop.name() == "infoLimit" &&
268  prop.name() == "debugLimit" &&
269  prop.name() == "verboseLimit") {
270  cout << "MessageSvc ERROR: Unknown message limit parameter: "
271  << prop.name() << endl;
272  return;
273  }
274 }
275 //#############################################################################
276 
278 
279  int ic = 0;
280  if (prop.name() == "setFatal") {
281  ic = MSG::FATAL;
282  } else if (prop.name() == "setError") {
283  ic = MSG::ERROR;
284  } else if (prop.name() == "setWarning") {
285  ic = MSG::WARNING;
286  } else if (prop.name() == "setInfo") {
287  ic = MSG::INFO;
288  } else if (prop.name() == "setDebug") {
289  ic = MSG::DEBUG;
290  } else if (prop.name() == "setVerbose") {
291  ic = MSG::VERBOSE;
292  } else if (prop.name() == "setAlways") {
293  ic = MSG::ALWAYS;
294  } else {
295  cerr << "MessageSvc ERROR: Unknown message threshold parameter: "
296  << prop.name() << endl;
297  return;
298  }
299 
300  StringArrayProperty *sap = dynamic_cast<StringArrayProperty*>( &prop);
301  if (sap == 0) {
302  std::cerr << "could not dcast " << prop.name()
303  << " to a StringArrayProperty (which it should be!)" << endl;
304  return;
305  } else {
307  for ( itr = sap->value().begin();
308  itr != sap->value().end();
309  ++itr) {
310  setOutputLevel( *itr, ic );
311  }
312  }
313 
314 }
315 
316 //#############################################################################
317 
318 #ifdef NDEBUG
320 #else
322  if (prop.name() == "countInactive") {
323  BooleanProperty *p = dynamic_cast<BooleanProperty*>(&prop);
324  if (p)
326  }
327 }
328 #endif
329 
330 
331 //#############################################################################
334 
335  m_suppress = false;
336 
337  {
339 
340  if (m_stats) {
341  os << "Summarizing all message counts" << endl;
342  } else {
343  os << "Listing sources of suppressed message: " << endl;
344  }
345 
346  os << "=====================================================" << endl;
347  os << " Message Source | Level | Count" << endl;
348  os << "-----------------------------+---------+-------------" << endl;
349 
350 
351  bool found(false);
352 
354  for (itr=m_sourceMap.begin(); itr!=m_sourceMap.end(); ++itr) {
355  for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
356  if ( (itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) ||
357  (m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value()) ) {
358  os << " ";
359  os.width(28);
361  os << itr->first;
362 
363  os << "|";
364 
365  os.width(8);
367  os << levelNames[ic];
368 
369  os << " |";
370 
371  os.width(9);
372  os << itr->second.msg[ic];
373 
374  os << endl;
375 
376  found = true;
377  }
378  }
379  }
380  os << "=====================================================" << endl;
381 
382  if (found || m_stats) {
383  cout << os.str();
384  }
385  }
386 
387 #ifndef NDEBUG
388  if (m_inactCount.value()) {
389 
391  os << "Listing sources of Unprotected and Unseen messages\n";
392 
393  bool found(false);
394 
395  unsigned int ml(0);
397  for (itr=m_inactiveMap.begin(); itr!=m_inactiveMap.end(); ++itr) {
398  for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
399  if (itr->second.msg[ic] != 0) {
400  if (itr->first.length() > ml) { ml = itr->first.length(); }
401  }
402  }
403  }
404 
405  for (unsigned int i=0; i<ml+25; ++i) {
406  os << "=";
407  }
408 
409  os << endl << " ";
410  os.width(ml+2);
412  os << "Message Source";
413  os.width(1);
414  os << "| Level | Count" << endl;
415 
416  for (unsigned int i=0; i<ml+3; ++i) {
417  os << "-";
418  }
419  os << "+---------+-----------" << endl;
420 
421 
422  for (itr=m_inactiveMap.begin(); itr!=m_inactiveMap.end(); ++itr) {
423  for (unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic) {
424  if (itr->second.msg[ic] != 0) {
425  os << " ";
426  os.width(ml+2);
428  os << itr->first;
429 
430  os << "|";
431 
432  os.width(8);
434  os << levelNames[ic];
435 
436  os << " |";
437 
438  os.width(9);
439  os << itr->second.msg[ic];
440 
441  os << endl;
442 
443  found = true;
444  }
445  }
446  }
447  for (unsigned int i=0; i<ml+25; ++i) {
448  os << "=";
449  }
450  os << endl;
451 
452  if (found) {
453  cout << os.str();
454  }
455  }
456 #endif
457 
458  return StatusCode::SUCCESS;
459 }
460 
461 //#############################################################################
463  ColorMap::const_iterator itr = m_colMap.find(col);
464  int icol;
465  if (itr != m_colMap.end()) {
466  icol = offset + itr->second;
467  } else {
468  icol = offset + 8;
469  }
470  std::ostringstream os1;
471 
472  os1 << icol;
473 
474  return os1.str();
475 
476 }
477 
478 //#############################################################################
479 // ---------------------------------------------------------------------------
480 // Routine: reportMessage
481 // Purpose: dispatches a message to the relevant streams.
482 // ---------------------------------------------------------------------------
483 //
484 
485 void MessageSvc::reportMessage( const Message& msg, int outputLevel ) {
486  boost::recursive_mutex::scoped_lock lock(m_reportMutex);
487 
488  int key = msg.getType();
489 
490  m_msgCount[key] ++;
491 
492  const Message *cmsg = &msg;
493 
494  // processing logged streams
495  if ( !m_loggedStreams.empty() ) {
496  const LoggedStreamsMap_t::iterator iLog = m_loggedStreams.find( msg.getSource() );
497  if ( m_loggedStreams.end() != iLog ) {
498  (*iLog->second) << *cmsg << std::endl;
499  }
500  }
501 
502  if ( m_suppress.value() || m_stats.value() ) {
503 
504  // Increase the counter of 'key' type of messages for the source and
505  // get the new value.
506  const int nmsg = ++(m_sourceMap[msg.getSource()].msg[key]);
507 
508  if (m_suppress.value()) {
509 
510  if ( m_msgLimit[key] != 0 ) {
511  if (nmsg == m_msgLimit[key]) {
512  std::ostringstream txt;
513  txt << levelNames[key] << " message limit ("
514  << m_msgLimit[key].value()
515  << ") reached for "
516  << msg.getSource() + ". Suppressing further output.";
517  cmsg = new Message(msg.getSource(), MSG::WARNING, txt.str());
518  cmsg->setFormat(msg.getFormat());
519  } else if (nmsg > m_msgLimit[key]) {
520  return;
521  }
522  }
523  }
524 
525  }
526 
527  StreamMap::const_iterator first = m_streamMap.lower_bound( key );
528  if ( first != m_streamMap.end() ) {
529  StreamMap::const_iterator last = m_streamMap.upper_bound( key );
530  while( first != last ) {
531  std::ostream& stream = *( (*first).second.second );
532  stream << *cmsg << std::endl;
533  first++;
534  }
535  }
536  else if ( key >= outputLevel ) {
537  msg.setFormat(m_defaultFormat);
538  msg.setTimeFormat(m_defaultTimeFormat);
539  if (!m_color) {
540  (*m_defaultStream) << *cmsg << std::endl << std::flush;
541  } else {
542  (*m_defaultStream) << m_logColorCodes[key] << *cmsg << "\033[m"
543  << std::endl << std::flush;
544  }
545  }
546 
547  if (cmsg != &msg) { delete cmsg; }
548 
549 }
550 
551 //#############################################################################
552 // ---------------------------------------------------------------------------
553 // Routine: reportMessage
554 // Purpose: dispatches a message to the relevant streams.
555 // ---------------------------------------------------------------------------
556 //
558  reportMessage(msg, outputLevel(msg.getSource()));
559 }
560 
561 //#############################################################################
562 // ---------------------------------------------------------------------------
563 // Routine: reportMessage
564 // Purpose: dispatches a message to the relevant streams.
565 // ---------------------------------------------------------------------------
566 //
567 void MessageSvc::reportMessage (const char* source,
568  int type,
569  const char* message) {
570  Message msg( source, type, message);
571  reportMessage( msg );
572 }
573 
574 //#############################################################################
575 // ---------------------------------------------------------------------------
576 // Routine: reportMessage
577 // Purpose: dispatches a message to the relevant streams.
578 // ---------------------------------------------------------------------------
579 //
581  int type,
582  const std::string& message) {
583  Message msg( source, type, message);
584  reportMessage( msg );
585 }
586 
587 //#############################################################################
588 // ---------------------------------------------------------------------------
589 // Routine: sendMessage
590 // Purpose: finds a message for a given status code and dispatches it.
591 // ---------------------------------------------------------------------------
592 //
593 
595  const std::string& source)
596 {
597  boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
598 
599  MessageMap::const_iterator first = m_messageMap.lower_bound( key );
600  if ( first != m_messageMap.end() ) {
601  MessageMap::const_iterator last = m_messageMap.upper_bound( key );
602  while( first != last ) {
603  Message msg = (*first).second;
604  msg.setSource( source );
605  std::ostringstream os1;
606  os1 << "Status Code " << key.getCode() << std::ends;
607  Message stat_code1( source, msg.getType(), os1.str() );
608  reportMessage( stat_code1 );
609  reportMessage( msg );
610  first++;
611  }
612  }
613  else {
614  Message mesg = m_defaultMessage;
615  mesg.setSource( source );
616  std::ostringstream os2;
617  os2 << "Status Code " << key.getCode() << std::ends;
618  Message stat_code2( source, mesg.getType(), os2.str() );
619  reportMessage( stat_code2 );
620  reportMessage( mesg );
621  }
622 }
623 
624 //#############################################################################
625 // ---------------------------------------------------------------------------
626 // Routine: insertStream
627 // Purpose: inserts a stream for a message type.
628 // ---------------------------------------------------------------------------
629 //
630 
632  const std::string& name,
633  std::ostream *stream)
634 {
635  typedef StreamMap::value_type value_type;
636  m_streamMap.insert( value_type( key, NamedStream(name,stream) ) );
637 }
638 
639 //#############################################################################
640 // ---------------------------------------------------------------------------
641 // Routine: eraseStream
642 // Purpose: erases all the streams for all the message types.
643 // ---------------------------------------------------------------------------
644 //
645 
647 {
648  m_streamMap.erase( m_streamMap.begin(), m_streamMap.end() );
649 }
650 
651 //#############################################################################
652 // ---------------------------------------------------------------------------
653 // Routine: eraseStream
654 // Purpose: erases all the streams for a message type.
655 // ---------------------------------------------------------------------------
656 //
657 
658 void MessageSvc::eraseStream( int message_type )
659 {
660  m_streamMap.erase( message_type );
661 }
662 
663 //#############################################################################
664 // ---------------------------------------------------------------------------
665 // Routine: eraseStream
666 // Purpose: erases one stream for a message type.
667 // ---------------------------------------------------------------------------
668 //
669 
670 void MessageSvc::eraseStream( int key, std::ostream* stream ) {
671  if ( 0 != stream ) {
672  bool changed = true;
673  while( changed ) {
674  changed = false;
675  StreamMap::iterator first = m_streamMap.lower_bound( key );
676  StreamMap::iterator last = m_streamMap.upper_bound( key );
677  while( first != last ) {
678  if ( (*first).second.second == stream ) {
679  m_streamMap.erase( first );
680  changed = true;
681  break;
682  }
683  }
684  }
685  }
686 }
687 
688 //#############################################################################
689 // ---------------------------------------------------------------------------
690 // Routine: eraseStream
691 // Purpose: erases one stream for all message types.
692 // ---------------------------------------------------------------------------
693 //
694 
696  if ( 0 != stream ) {
697  bool changed = true;
698  while( changed ) {
699  changed = false;
700  StreamMap::iterator first = m_streamMap.begin();
701  while( first != m_streamMap.end() ) {
702  if ( (*first).second.second == stream ) {
703  m_streamMap.erase( first );
704  changed = true;
705  break;
706  }
707  }
708  }
709  }
710 }
711 
712 
713 //#############################################################################
714 // ---------------------------------------------------------------------------
715 // Routine: insertMessage
716 // Purpose: inserts a message for a status code.
717 // ---------------------------------------------------------------------------
718 //
719 
721 {
722  boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
723 
724  typedef MessageMap::value_type value_type;
725  m_messageMap.insert( value_type( key, msg ) );
726 }
727 
728 //#############################################################################
729 // ---------------------------------------------------------------------------
730 // Routine: eraseMessage
731 // Purpose: erases all the messages for all the status codes.
732 // ---------------------------------------------------------------------------
733 //
734 
736 {
737  boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
738 
739  m_messageMap.erase( m_messageMap.begin(), m_messageMap.end() );
740 }
741 
742 //#############################################################################
743 // ---------------------------------------------------------------------------
744 // Routine: eraseMessage
745 // Purpose: erases all the messages for a status code.
746 // ---------------------------------------------------------------------------
747 //
748 
750 {
751  boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
752 
753  m_messageMap.erase( key );
754 }
755 
756 //#############################################################################
757 // ---------------------------------------------------------------------------
758 // Routine: eraseMessage
759 // Purpose: erases one message for a status code.
760 // ---------------------------------------------------------------------------
761 //
762 
763 void MessageSvc::eraseMessage( const StatusCode& key, const Message& msg )
764 {
765  boost::recursive_mutex::scoped_lock lock(m_messageMapMutex);
766 
767  bool changed = true;
768  while( changed ) {
769  changed = false;
770  MessageMap::iterator first = m_messageMap.lower_bound( key );
771  MessageMap::iterator last = m_messageMap.upper_bound( key );
772  while( first != last ) {
773  const Message& message = (*first).second;
774  if ( message == msg ) {
775  m_messageMap.erase( first );
776  changed = true;
777  break;
778  }
779  }
780  }
781 }
782 
783 // ---------------------------------------------------------------------------
785 // ---------------------------------------------------------------------------
786  return m_outputLevel;
787 }
788 
789 // ---------------------------------------------------------------------------
790 int MessageSvc::outputLevel( const std::string& source ) const {
791 // ---------------------------------------------------------------------------
792  boost::recursive_mutex::scoped_lock lock(m_thresholdMapMutex);
793 
795 
796  it = m_thresholdMap.find( source );
797  if( it != m_thresholdMap.end() ) {
798  return (*it).second;
799  }
800  else {
801  return m_outputLevel;
802  }
803 }
804 
805 // ---------------------------------------------------------------------------
806 void MessageSvc::setOutputLevel(int new_level) {
807 // ---------------------------------------------------------------------------
808  m_outputLevel = new_level;
809 }
810 
811 // ---------------------------------------------------------------------------
812 void MessageSvc::setOutputLevel(const std::string& source, int level) {
813 // ---------------------------------------------------------------------------
814  boost::recursive_mutex::scoped_lock lock(m_thresholdMapMutex);
815 
816  /*
817  std::pair<ThresholdMap::iterator, bool> p;
818  p = m_thresholdMap.insert(ThresholdMap::value_type( source, level) );
819  if( p.second == false ) {
820  // Already esisting an output level for that source. Erase and enter it again
821  m_thresholdMap.erase ( p.first );
822  m_thresholdMap.insert(ThresholdMap::value_type( source, level) );
823  }
824  */
825  m_thresholdMap[source] = level;
826 }
827 
828 // ---------------------------------------------------------------------------
830 // ---------------------------------------------------------------------------
831  if (logLevel < MSG::NUM_LEVELS) {
832  return m_logColorCodes[logLevel];
833  } else {
834  return "";
835  }
836 }
837 
838 // ---------------------------------------------------------------------------
840 
841  return m_msgCount[level];
842 
843 }
844 
845 // ---------------------------------------------------------------------------
846 void
848 
849  ++(m_inactiveMap[source].msg[level]);
850 
851 }
852 
853 // ---------------------------------------------------------------------------
855 {
856  // reset state
857  for ( LoggedStreamsMap_t::iterator iLog = m_loggedStreams.begin();
858  iLog != m_loggedStreams.end();
859  ++iLog ) {
860  delete iLog->second;
861  }
862  m_loggedStreams.clear();
863 
864  typedef std::map<std::string,std::string> StreamMap_t;
865  const StreamMap_t& streamMap = m_loggedStreamsName;
866  typedef StreamMap_t::const_iterator StreamMapIter;
867 
868  for ( StreamMapIter iProp = streamMap.begin(), iEnd = streamMap.end();
869  iProp != iEnd;
870  ++iProp ) {
871 
872  const std::string sourceName = iProp->first;
873  const std::string outFileName = iProp->second;
874 
875  std::set<std::string> outFileNames;
876  for ( StreamMapIter jProp = streamMap.begin();
877  jProp != iEnd;
878  ++jProp ) {
879  if ( jProp->first != iProp->first ) {
880  outFileNames.insert( jProp->second );
881  }
882  }
883 
884  tee( sourceName, outFileName, outFileNames );
885 
886  }//> loop over property entries
887 
888  return;
889 }
890 
891 // ---------------------------------------------------------------------------
892 void MessageSvc::tee( const std::string& sourceName,
893  const std::string& outFileName,
894  const std::set<std::string>& outFileNames )
895 {
898 
899  LoggedStreamsMap_t::iterator iEnd = m_loggedStreams.end();
900  LoggedStreamsMap_t::iterator iStream = m_loggedStreams.find( sourceName );
901  if ( iStream != iEnd ) {
902  delete iStream->second;
903  iStream->second = 0;
904  m_loggedStreams.erase( iStream );
905  }
906 
907  // before creating a new ofstream, make sure there is no already existing
908  // one with the same file name...
909  iEnd = m_loggedStreams.end();
910  for ( iStream = m_loggedStreams.begin(); iStream != iEnd; ++iStream ) {
911  if ( outFileNames.find( outFileName ) != outFileNames.end() ) {
912  m_loggedStreams[sourceName] = m_loggedStreams[iStream->first];
913  return;
914  }
915  }
916 
917  std::ofstream * out = new std::ofstream( outFileName.c_str(), openMode );
918 
919  if ( !out->good() ) {
920  out->close();
921  delete out;
922  return;
923  }
924 
925  m_loggedStreams[sourceName] = out;
926 
927  return;
928 }
929 

Generated at Wed Nov 28 2012 12:17:12 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004