| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 "MessageSvc.h"
8 #include "GaudiKernel/IAppMgrUI.h"
9 #include "GaudiKernel/Kernel.h"
10 #include "GaudiKernel/Message.h"
11 #include "GaudiKernel/StatusCode.h"
12 #include "GaudiKernel/System.h"
13
14 #include <fstream>
15 #include <iostream>
16 #include <sstream>
17
18 namespace
19 {
20
21 // erase_if functions for containers which do NOT invalidate iterators
22 // after the erase point, eg.std::{unordered_}{,multi}map, std::{forward_,}list.
23 // To be explicit: this does NOT work with std::vector.
24
25 // TODO: replace with std::experimental::erase_if (Libraries Fundamental TS v2)
26
27 template <typename Container, typename Iterator, typename Predicate>
28 void erase_if( Container& c, Iterator first, Iterator last, Predicate pred )
29 {
30 while ( first != last ) {
31 if ( pred( *first ) )
32 first = c.erase( first );
33 else
34 ++first;
35 }
36 }
37
38 template <typename Container, typename Predicate>
39 void erase_if( Container& c, Predicate pred )
40 {
41 return erase_if( c, std::begin( c ), std::end( c ), std::forward<Predicate>( pred ) );
42 }
43
44 template <typename Container, typename Iterator, typename Predicate>
45 void erase_if( Container& c, std::pair<Iterator, Iterator> range, Predicate pred )
46 {
47 return erase_if( c, std::move( range.first ), std::move( range.second ), std::forward<Predicate>( pred ) );
48 }
49
50 std::string colTrans( const std::string& col, int offset )
51 {
52 int icol = 0;
53 if ( col == "black" )
54 icol = MSG::BLACK;
55 else if ( col == "red" )
56 icol = MSG::RED;
57 else if ( col == "green" )
58 icol = MSG::GREEN;
59 else if ( col == "yellow" )
60 icol = MSG::YELLOW;
61 else if ( col == "blue" )
62 icol = MSG::BLUE;
63 else if ( col == "purple" )
64 icol = MSG::PURPLE;
65 else if ( col == "cyan" )
66 icol = MSG::CYAN;
67 else if ( col == "white" )
68 icol = MSG::WHITE;
69 else
70 icol = 8;
71 return std::to_string( icol + offset );
72 }
73 }
74
75 // Instantiation of a static factory class used by clients to create
76 // instances of this service
77 DECLARE_COMPONENT( MessageSvc )
78
79 static const std::string levelNames[MSG::NUM_LEVELS] = {"NIL", "VERBOSE", "DEBUG", "INFO",
80 "WARNING", "ERROR", "FATAL", "ALWAYS"};
81
82 // Constructor
83 MessageSvc::MessageSvc( const std::string& name, ISvcLocator* svcloc ) : base_class( name, svcloc )
84 {
85 m_inactCount.declareUpdateHandler( &MessageSvc::setupInactCount, this );
86
87 m_outputLevel.declareUpdateHandler( [svcloc]( Gaudi::Details::PropertyBase& ) {
88 SmartIF<IAppMgrUI> app = svcloc;
89 if ( app ) app->outputLevelUpdate();
90 } );
91
92 #ifndef NDEBUG
93 // initialize the MsgStream static flag.
94 MsgStream::enableCountInactive( m_inactCount );
95 #endif
96
97 for ( int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
98 m_logColors[ic].declareUpdateHandler( &MessageSvc::setupColors, this );
99 m_msgLimit[ic].declareUpdateHandler( &MessageSvc::setupLimits, this );
100 m_thresholdProp[ic].declareUpdateHandler( &MessageSvc::setupThreshold, this );
101 }
102
103 m_logColors[MSG::FATAL].set( {"blue", "red"} );
104 m_logColors[MSG::ERROR].set( {"white", "red"} );
105 m_logColors[MSG::WARNING].set( {"yellow"} );
106
107 std::fill( std::begin( m_msgCount ), std::end( m_msgCount ), 0 );
108 }
109
110 //#############################################################################
111
113 StatusCode MessageSvc::initialize()
114 {
115 StatusCode sc = Service::initialize();
116 if ( sc.isFailure() ) return sc;
117
118 #ifdef _WIN32
119 m_color = false;
120 #endif
121
122 // make sure the map of logged stream names is initialized
123 setupLogStreams();
124
125 return StatusCode::SUCCESS;
126 }
127
128 //#############################################################################
129
131 StatusCode MessageSvc::reinitialize()
132 {
133 m_state = Gaudi::StateMachine::OFFLINE;
134 return initialize();
135 }
136
137 //#############################################################################
138
139 void MessageSvc::setupColors( Gaudi::Details::PropertyBase& prop )
140 {
141 const std::string& pname = prop.name();
142 int level;
143 if ( pname == "fatalColorCode" )
144 level = MSG::FATAL;
145 else if ( pname == "errorColorCode" )
146 level = MSG::ERROR;
147 else if ( pname == "warningColorCode" )
148 level = MSG::WARNING;
149 else if ( pname == "infoColorCode" )
150 level = MSG::INFO;
151 else if ( pname == "debugColorCode" )
152 level = MSG::DEBUG;
153 else if ( pname == "verboseColorCode" )
154 level = MSG::VERBOSE;
155 else if ( pname == "alwaysColorCode" )
156 level = MSG::ALWAYS;
157 else {
158 throw GaudiException( "ERROR: Unknown message color parameter: " + pname, name(), StatusCode::FAILURE );
159 }
160
161 auto& code = m_logColorCodes[level];
162
163 const auto& col_desc = m_logColors[level].value();
164
165 if ( col_desc.size() == 1 ) {
166 const std::string& desc = col_desc[0];
167 if ( desc.empty() ) {
168 code = "";
169 } else if ( desc[0] == '[' ) {
170 code = "\033" + desc;
171 } else {
172 code = "\033[" + colTrans( desc, 90 ) + ";1m";
173 }
174 } else if ( col_desc.size() == 2 ) {
175 code = "\033[" + colTrans( col_desc[0], 90 ) + ";" + colTrans( col_desc[1], 100 ) + ";1m";
176 } else { // empty desc: no color
177 code = "";
178 }
179 }
180 //#############################################################################
181
182 void MessageSvc::setupLimits( Gaudi::Details::PropertyBase& prop )
183 {
184 // Just report problems in the settings of the limits and unknown limit parameters
185 if ( prop.name() == "alwaysLimit" ) {
186 Gaudi::Property<int>* p = dynamic_cast<Gaudi::Property<int>*>( &prop );
187 if ( p && p->value() != 0 ) {
188 std::cout << "MessageSvc ERROR: cannot suppress ALWAYS messages" << std::endl;
189 p->setValue( 0 );
190 }
191 } else if ( prop.name() == "defaultLimit" ) {
192 for ( int i = MSG::VERBOSE; i < MSG::NUM_LEVELS; ++i ) {
193 if ( i != MSG::ALWAYS ) {
194 m_msgLimit[i] = m_msgLimit[MSG::NIL].value();
195 }
196 }
197 } else if ( prop.name() != "fatalLimit" && prop.name() != "errorLimit" && prop.name() != "warningLimit" &&
198 prop.name() == "infoLimit" && prop.name() == "debugLimit" && prop.name() == "verboseLimit" ) {
199 std::cout << "MessageSvc ERROR: Unknown message limit parameter: " << prop.name() << std::endl;
200 return;
201 }
202 }
203 //#############################################################################
204
205 void MessageSvc::setupThreshold( Gaudi::Details::PropertyBase& prop )
206 {
207
208 static const std::array<std::pair<const char*, MSG::Level>, 7> tbl{{{"setFatal", MSG::FATAL},
209 {"setError", MSG::ERROR},
210 {"setWarning", MSG::WARNING},
211 {"setInfo", MSG::INFO},
212 {"setDebug", MSG::DEBUG},
213 {"setVerbose", MSG::VERBOSE},
214 {"setAlways", MSG::ALWAYS}}};
215
216 auto i = std::find_if( std::begin( tbl ), std::end( tbl ),
217 [&]( const std::pair<const char*, MSG::Level>& t ) { return prop.name() == t.first; } );
218 if ( i == std::end( tbl ) ) {
219 std::cerr << "MessageSvc ERROR: Unknown message threshold parameter: " << prop.name() << std::endl;
220 return;
221 }
222 int ic = i->second;
223
224 Gaudi::Property<std::vector<std::string>>* sap = dynamic_cast<Gaudi::Property<std::vector<std::string>>*>( &prop );
225 if ( !sap ) {
226 std::cerr << "could not dcast " << prop.name()
227 << " to a Gaudi::Property<std::vector<std::string>> (which it should be!)" << std::endl;
228 } else {
229 for ( auto& i : sap->value() ) setOutputLevel( i, ic );
230 }
231 }
232
233 //#############################################################################
234
235 #ifdef NDEBUG
236 void MessageSvc::setupInactCount( Gaudi::Details::PropertyBase& ) {}
237 #else
238 void MessageSvc::setupInactCount( Gaudi::Details::PropertyBase& prop )
239 {
240 if ( prop.name() == "countInactive" ) {
241 Gaudi::Property<bool>* p = dynamic_cast<Gaudi::Property<bool>*>( &prop );
242 if ( p ) MsgStream::enableCountInactive( p->value() );
243 }
244 }
245 #endif
246
247 //#############################################################################
249 StatusCode MessageSvc::finalize()
250 {
251
252 m_suppress = false;
253
254 {
255 std::ostringstream os;
256
257 if ( m_stats ) {
258 os << "Summarizing all message counts" << std::endl;
259 } else {
260 os << "Listing sources of suppressed message: " << std::endl;
261 }
262
263 os << "=====================================================" << std::endl;
264 os << " Message Source | Level | Count" << std::endl;
265 os << "-----------------------------+---------+-------------" << std::endl;
266
267 bool found( false );
268
269 for ( auto itr = m_sourceMap.begin(); itr != m_sourceMap.end(); ++itr ) {
270 for ( unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
271 if ( ( itr->second.msg[ic] >= m_msgLimit[ic] && m_msgLimit[ic] != 0 ) ||
272 ( m_stats && itr->second.msg[ic] > 0 && ic >= m_statLevel.value() ) ) {
273 os << " ";
274 os.width( 28 );
275 os.setf( std::ios_base::left, std::ios_base::adjustfield );
276 os << itr->first;
277 os << "|";
278
279 os.width( 8 );
280 os.setf( std::ios_base::right, std::ios_base::adjustfield );
281 os << levelNames[ic];
282 os << " |";
283
284 os.width( 9 );
285 os << itr->second.msg[ic];
286 os << std::endl;
287
288 found = true;
289 }
290 }
291 }
292 os << "=====================================================" << std::endl;
293 if ( found || m_stats ) std::cout << os.str();
294 }
295
296 #ifndef NDEBUG
297 if ( m_inactCount.value() ) {
298
299 std::ostringstream os;
300 os << "Listing sources of Unprotected and Unseen messages\n";
301
302 bool found( false );
303
304 unsigned int ml( 0 );
305 for ( const auto& itr : m_inactiveMap ) {
306 for ( unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
307 if ( itr.second.msg[ic] != 0 && itr.first.length() > ml ) {
308 ml = itr.first.length();
309 }
310 }
311 }
312
313 for ( unsigned int i = 0; i < ml + 25; ++i ) os << "=";
314
315 os << std::endl << " ";
316 os.width( ml + 2 );
317 os.setf( std::ios_base::left, std::ios_base::adjustfield );
318 os << "Message Source";
319 os.width( 1 );
320 os << "| Level | Count" << std::endl;
321
322 for ( unsigned int i = 0; i < ml + 3; ++i ) os << "-";
323 os << "+---------+-----------" << std::endl;
324
325 for ( auto itr = m_inactiveMap.begin(); itr != m_inactiveMap.end(); ++itr ) {
326 for ( unsigned int ic = 0; ic < MSG::NUM_LEVELS; ++ic ) {
327 if ( itr->second.msg[ic] != 0 ) {
328 os << " ";
329 os.width( ml + 2 );
330 os.setf( std::ios_base::left, std::ios_base::adjustfield );
331 os << itr->first;
332
333 os << "|";
334
335 os.width( 8 );
336 os.setf( std::ios_base::right, std::ios_base::adjustfield );
337 os << levelNames[ic];
338
339 os << " |";
340
341 os.width( 9 );
342 os << itr->second.msg[ic];
343
344 os << std::endl;
345
346 found = true;
347 }
348 }
349 }
350 for ( unsigned int i = 0; i < ml + 25; ++i ) os << "=";
351 os << std::endl;
352
353 if ( found ) std::cout << os.str();
354 }
355 #endif
356
357 return StatusCode::SUCCESS;
358 }
359
360 //#############################################################################
361 // ---------------------------------------------------------------------------
362 // Routine: reportMessage
363 // Purpose: dispatches a message to the relevant streams.
364 // ---------------------------------------------------------------------------
365 //
366 void MessageSvc::reportMessage( const Message& msg, int outputLevel )
367 {
368 std::unique_lock<std::recursive_mutex> lock( m_reportMutex );
369 i_reportMessage( msg, outputLevel );
370 }
371
372 void MessageSvc::i_reportMessage( const Message& msg, int outputLevel )
373 {
374 int key = msg.getType();
375
376 ++m_msgCount[key];
377
378 const Message* cmsg = &msg;
379
380 // processing logged streams
381 if ( !m_loggedStreams.empty() ) {
382 auto iLog = m_loggedStreams.find( msg.getSource() );
383 if ( m_loggedStreams.end() != iLog ) {
384 ( *iLog->second ) << *cmsg << std::endl;
385 }
386 }
387
388 if ( m_suppress.value() || m_stats.value() ) {
389
390 // Increase the counter of 'key' type of messages for the source and
391 // get the new value.
392 const int nmsg = ++( m_sourceMap[msg.getSource()].msg[key] );
393
394 if ( m_suppress.value() && m_msgLimit[key] != 0 ) {
395 if ( nmsg > m_msgLimit[key] ) return;
396 if ( nmsg == m_msgLimit[key] ) {
397 std::string txt = levelNames[key] + " message limit (" + std::to_string( m_msgLimit[key].value() ) +
398 ") reached for " + msg.getSource() + ". Suppressing further output.";
399 cmsg = new Message( msg.getSource(), MSG::WARNING, std::move( txt ) );
400 cmsg->setFormat( msg.getFormat() );
401 }
402 }
403 }
404
405 auto range = m_streamMap.equal_range( key );
406 if ( range.first != m_streamMap.end() ) {
407 std::for_each( range.first, range.second,
408 [&]( StreamMap::const_reference sm ) { *sm.second.second << *cmsg << std::endl; } );
409 } else if ( key >= outputLevel ) {
410 msg.setFormat( m_defaultFormat );
411 msg.setTimeFormat( m_defaultTimeFormat );
412 if ( !m_color ) {
413 ( *m_defaultStream ) << *cmsg << std::endl << std::flush;
414 } else {
415 ( *m_defaultStream ) << m_logColorCodes[key] << *cmsg << "\033[m" << std::endl << std::flush;
416 }
417 }
418
419 if ( cmsg != &msg ) {
420 delete cmsg;
421 }
422 }
423
424 //#############################################################################
425 // ---------------------------------------------------------------------------
426 // Routine: reportMessage
427 // Purpose: dispatches a message to the relevant streams.
428 // ---------------------------------------------------------------------------
429 //
430 void MessageSvc::reportMessage( const Message& msg ) { reportMessage( msg, outputLevel( msg.getSource() ) ); }
431
432 //#############################################################################
433 // ---------------------------------------------------------------------------
434 // Routine: reportMessage
435 // Purpose: dispatches a message to the relevant streams.
436 // ---------------------------------------------------------------------------
437 //
438 void MessageSvc::reportMessage( const char* source, int type, const char* message )
439 {
440 reportMessage( Message{source, type, message} );
441 }
442
443 //#############################################################################
444 // ---------------------------------------------------------------------------
445 // Routine: reportMessage
446 // Purpose: dispatches a message to the relevant streams.
447 // ---------------------------------------------------------------------------
448 //
449 void MessageSvc::reportMessage( const std::string& source, int type, const std::string& message )
450 {
451 reportMessage( Message{source, type, message} );
452 }
453
454 //#############################################################################
455 // ---------------------------------------------------------------------------
456 // Routine: sendMessage
457 // Purpose: finds a message for a given status code and dispatches it.
458 // ---------------------------------------------------------------------------
459 //
460 void MessageSvc::reportMessage( const StatusCode& code, const std::string& source )
461 {
462 std::unique_lock<std::recursive_mutex> lock( m_messageMapMutex );
463 i_reportMessage( code, source );
464 }
465
466 void MessageSvc::i_reportMessage( const StatusCode& code, const std::string& source )
467 {
468 int level = outputLevel( source );
469 auto report = [&]( Message mesg ) {
470 mesg.setSource( source );
471 Message stat_code( source, mesg.getType(), "Status Code " + std::to_string( code.getCode() ) );
472 i_reportMessage( std::move( stat_code ), level );
473 i_reportMessage( std::move( mesg ), level );
474 };
475
476 auto range = m_messageMap.equal_range( code );
477 if ( range.first != m_messageMap.end() ) {
478 std::for_each( range.first, range.second, [&]( MessageMap::const_reference sm ) { report( sm.second ); } );
479 } else {
480 report( m_defaultMessage );
481 }
482 }
483
484 //#############################################################################
485 // ---------------------------------------------------------------------------
486 // Routine: insertStream
487 // Purpose: inserts a stream for a message type.
488 // ---------------------------------------------------------------------------
489 //
490
491 void MessageSvc::insertStream( int key, const std::string& name, std::ostream* stream )
492 {
493 m_streamMap.emplace( key, NamedStream( name, stream ) );
494 }
495
496 //#############################################################################
497 // ---------------------------------------------------------------------------
498 // Routine: eraseStream
499 // Purpose: erases all the streams for all the message types.
500 // ---------------------------------------------------------------------------
501 //
502
503 void MessageSvc::eraseStream() { m_streamMap.clear(); }
504
505 //#############################################################################
506 // ---------------------------------------------------------------------------
507 // Routine: eraseStream
508 // Purpose: erases all the streams for a message type.
509 // ---------------------------------------------------------------------------
510 //
511
512 void MessageSvc::eraseStream( int message_type ) { m_streamMap.erase( message_type ); }
513
514 //#############################################################################
515 // ---------------------------------------------------------------------------
516 // Routine: eraseStream
517 // Purpose: erases one stream for a message type.
518 // ---------------------------------------------------------------------------
519 //
520
521 void MessageSvc::eraseStream( int key, std::ostream* stream )
522 {
523 if ( stream ) {
524 erase_if( m_streamMap, m_streamMap.equal_range( key ),
525 [&]( StreamMap::const_reference j ) { return j.second.second == stream; } );
526 }
527 }
528
529 //#############################################################################
530 // ---------------------------------------------------------------------------
531 // Routine: eraseStream
532 // Purpose: erases one stream for all message types.
533 // ---------------------------------------------------------------------------
534 //
535
536 void MessageSvc::eraseStream( std::ostream* stream )
537 {
538 if ( stream ) {
539 erase_if( m_streamMap, [&]( StreamMap::const_reference j ) { return j.second.second == stream; } );
540 }
541 }
542
543 //#############################################################################
544 // ---------------------------------------------------------------------------
545 // Routine: insertMessage
546 // Purpose: inserts a message for a status code.
547 // ---------------------------------------------------------------------------
548 //
549
550 void MessageSvc::insertMessage( const StatusCode& key, const Message& msg )
551 {
552 std::unique_lock<std::recursive_mutex> lock( m_messageMapMutex );
553 m_messageMap.emplace( key, msg );
554 }
555
556 //#############################################################################
557 // ---------------------------------------------------------------------------
558 // Routine: eraseMessage
559 // Purpose: erases all the messages for all the status codes.
560 // ---------------------------------------------------------------------------
561 //
562
563 void MessageSvc::eraseMessage()
564 {
565 std::unique_lock<std::recursive_mutex> lock( m_messageMapMutex );
566 m_messageMap.clear();
567 }
568
569 //#############################################################################
570 // ---------------------------------------------------------------------------
571 // Routine: eraseMessage
572 // Purpose: erases all the messages for a status code.
573 // ---------------------------------------------------------------------------
574 //
575
576 void MessageSvc::eraseMessage( const StatusCode& key )
577 {
578 std::unique_lock<std::recursive_mutex> lock( m_messageMapMutex );
579 m_messageMap.erase( key );
580 }
581
582 //#############################################################################
583 // ---------------------------------------------------------------------------
584 // Routine: eraseMessage
585 // Purpose: erases one message for a status code.
586 // ---------------------------------------------------------------------------
587 //
588
589 void MessageSvc::eraseMessage( const StatusCode& key, const Message& msg )
590 {
591 std::unique_lock<std::recursive_mutex> lock( m_messageMapMutex );
592
593 erase_if( m_messageMap, m_messageMap.equal_range( key ),
594 [&]( MessageMap::const_reference j ) { return j.second == msg; } );
595 }
596
597 // ---------------------------------------------------------------------------
598 int MessageSvc::outputLevel() const
599 {
600 // ---------------------------------------------------------------------------
601 return m_outputLevel;
602 }
603
604 // ---------------------------------------------------------------------------
605 int MessageSvc::outputLevel( const std::string& source ) const
606 {
607 // ---------------------------------------------------------------------------
608 std::unique_lock<std::recursive_mutex> lock( m_thresholdMapMutex );
609 auto it = m_thresholdMap.find( source );
610 return it != m_thresholdMap.end() ? it->second : m_outputLevel.value();
611 }
612
613 // ---------------------------------------------------------------------------
614 void MessageSvc::setOutputLevel( int new_level )
615 {
616 // ---------------------------------------------------------------------------
617 m_outputLevel = new_level;
618 }
619
620 // ---------------------------------------------------------------------------
621 void MessageSvc::setOutputLevel( const std::string& source, int level )
622 {
623 // ---------------------------------------------------------------------------
624 std::unique_lock<std::recursive_mutex> lock( m_thresholdMapMutex );
625
626 // only write if we really have to...
627 auto i = m_thresholdMap.find( source );
628 if ( i == m_thresholdMap.end() ) {
629 m_thresholdMap[source] = level;
630 } else if ( i->second != level ) {
631 i->second = level;
632 }
633 }
634
635 // ---------------------------------------------------------------------------
636 std::string MessageSvc::getLogColor( int logLevel ) const
637 {
638 // ---------------------------------------------------------------------------
639 return ( logLevel < MSG::NUM_LEVELS ) ? m_logColorCodes[logLevel] : "";
640 }
641
642 // ---------------------------------------------------------------------------
643 int MessageSvc::messageCount( MSG::Level level ) const { return m_msgCount[level]; }
644
645 // ---------------------------------------------------------------------------
646 void MessageSvc::incrInactiveCount( MSG::Level level, const std::string& source )
647 {
648 ++( m_inactiveMap[source].msg[level] );
649
650 if ( std::find( begin( m_tracedInactiveSources ), end( m_tracedInactiveSources ), source ) !=
651 end( m_tracedInactiveSources ) ) {
652 std::cout << "== inactive message detected from " << source << " ==" << std::endl;
653 std::string t;
654 System::backTrace( t, 25, 0 );
655 std::cout << t << std::endl;
656 }
657 }
658
659 // ---------------------------------------------------------------------------
660 void MessageSvc::setupLogStreams()
661 {
662 // reset state
663 m_loggedStreams.clear();
664
665 for ( auto& iProp : m_loggedStreamsName ) {
666
667 std::set<std::string> outFileNames;
668 for ( auto& jProp : m_loggedStreamsName ) {
669 if ( jProp.first != iProp.first ) {
670 outFileNames.insert( jProp.second );
671 }
672 }
673 tee( iProp.first, iProp.second, outFileNames );
674
675 } //> loop over property entries
676 }
677
678 // ---------------------------------------------------------------------------
679 void MessageSvc::tee( const std::string& sourceName, const std::string& outFileName,
680 const std::set<std::string>& outFileNames )
681 {
682 const std::ios_base::openmode openMode = std::ios_base::out | std::ios_base::trunc;
683
684 auto iStream = m_loggedStreams.find( sourceName );
685 if ( iStream != std::end( m_loggedStreams ) ) {
686 m_loggedStreams.erase( iStream );
687 }
688
689 // before creating a new ofstream, make sure there is no already existing
690 // one with the same file name...
691 for ( auto& iStream : m_loggedStreams ) {
692 if ( outFileNames.find( outFileName ) != outFileNames.end() ) {
693 m_loggedStreams[sourceName] = m_loggedStreams[iStream.first];
694 return;
695 }
696 }
697
698 auto out = std::make_shared<std::ofstream>( outFileName, openMode );
699 if ( out->good() ) m_loggedStreams[sourceName] = std::move( out );
700 }
Service::m_outputLevel
Gaudi::Property< int > m_outputLevel
Definition: Service.h:183
System.h
Message::getFormat
const std::string & getFormat() const
Get the format string.
Definition: Message.cpp:154
std::ostringstream::setf
T setf(T...args)
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::SUCCESS
Definition: StatusCode.h:31
SmartIF< IAppMgrUI >
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:121
Kernel.h
std::string::empty
T empty(T...args)
Gaudi::Property::setValue
bool setValue(const ValueType &v)
Definition: Property.h:481
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudirun.c
c
Definition: gaudirun.py:407
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
Service::m_state
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:160
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
MessageSvc::m_streamMap
StreamMap m_streamMap
Stream map.
Definition: MessageSvc.h:182
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:319
StatusCode::getCode
unsigned long getCode() const
Get the status code by value.
Definition: StatusCode.h:94
MessageSvc::getLogColor
std::string getLogColor(int logLevel) const override
Definition: MessageSvc.cpp:636
IAppMgrUI.h
MessageSvc::i_reportMessage
virtual void i_reportMessage(const Message &msg, int outputLevel)
Internal implementation of reportMessage(const Message&,int) without lock.
Definition: MessageSvc.cpp:372
MessageSvc::setupInactCount
void setupInactCount(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:238
MessageSvc::m_sourceMap
std::map< std::string, MsgAry > m_sourceMap
Definition: MessageSvc.h:196
MSG::CYAN
Definition: IMessageSvc.h:17
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:40
MessageSvc::m_defaultMessage
Message m_defaultMessage
Default Message.
Definition: MessageSvc.h:181
MessageSvc::m_inactiveMap
std::map< std::string, MsgAry > m_inactiveMap
Definition: MessageSvc.h:196
MSG::GREEN
Definition: IMessageSvc.h:17
std::to_string
T to_string(T...args)
MSG::DEBUG
Definition: IMessageSvc.h:16
std::endl
T endl(T...args)
MessageSvc::m_messageMap
MessageMap m_messageMap
Message map.
Definition: MessageSvc.h:183
std
STL namespace.
MessageSvc::setupLogStreams
void setupLogStreams()
Definition: MessageSvc.cpp:660
MessageSvc::m_defaultTimeFormat
Gaudi::Property< std::string > m_defaultTimeFormat
Definition: MessageSvc.h:135
MessageSvc::MessageSvc
MessageSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MessageSvc.cpp:83
std::end
T end(T...args)
MessageSvc::m_messageMapMutex
std::recursive_mutex m_messageMapMutex
Mutex to synchronize multiple access to m_messageMap.
Definition: MessageSvc.h:216
Message::getType
int getType() const
Get the message type.
Definition: Message.cpp:87
MessageSvc::reinitialize
StatusCode reinitialize() override
Reinitialize Service.
Definition: MessageSvc.cpp:131
MSG::VERBOSE
Definition: IMessageSvc.h:16
MSG::WHITE
Definition: IMessageSvc.h:17
MessageSvc::eraseMessage
void eraseMessage() override
Definition: MessageSvc.cpp:563
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
MessageSvc::m_tracedInactiveSources
Gaudi::Property< std::vector< std::string > > m_tracedInactiveSources
Definition: MessageSvc.h:171
System::backTrace
GAUDI_API int backTrace(void **addresses, const int depth)
MessageSvc.h
MessageSvc::setupColors
void setupColors(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:139
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
begin
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:58
IAppMgrUI::outputLevelUpdate
virtual void outputLevelUpdate()=0
Function to call to update the outputLevel of the components (after a change in MessageSvc).
std::string
STL class.
MessageSvc::eraseStream
void eraseStream() override
Definition: MessageSvc.cpp:503
MessageSvc::incrInactiveCount
void incrInactiveCount(MSG::Level level, const std::string &src) override
Definition: MessageSvc.cpp:646
MessageSvc::m_loggedStreams
std::map< std::string, std::shared_ptr< std::ostream > > m_loggedStreams
Definition: MessageSvc.h:200
MSG::FATAL
Definition: IMessageSvc.h:16
MessageSvc::m_inactCount
Gaudi::Property< bool > m_inactCount
Definition: MessageSvc.h:169
MSG::Level
Level
Definition: IMessageSvc.h:16
MessageSvc::m_logColors
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_logColors
Definition: MessageSvc.h:150
MessageSvc::m_statLevel
Gaudi::Property< unsigned int > m_statLevel
Definition: MessageSvc.h:137
MessageSvc::setOutputLevel
void setOutputLevel(int new_level) override
Definition: MessageSvc.cpp:614
MSG::RED
Definition: IMessageSvc.h:17
MSG::BLUE
Definition: IMessageSvc.h:17
MessageSvc::initialize
StatusCode initialize() override
Initialize Service.
Definition: MessageSvc.cpp:113
MessageSvc::m_thresholdMap
ThresholdMap m_thresholdMap
Output level threshold map.
Definition: MessageSvc.h:184
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::ostringstream
STL class.
gaudirun.type
type
Definition: gaudirun.py:133
MessageSvc::NamedStream
std::pair< std::string, std::ostream * > NamedStream
Definition: MessageSvc.h:33
std::multimap::erase
T erase(T...args)
MessageSvc::reportMessage
void reportMessage(const Message &message) override
Definition: MessageSvc.cpp:430
std::ostringstream::width
T width(T...args)
MessageSvc::m_color
Gaudi::Property< bool > m_color
Definition: MessageSvc.h:148
MSG::NIL
Definition: IMessageSvc.h:16
std::ostringstream::str
T str(T...args)
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:85
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:64
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
MessageSvc::m_defaultFormat
Gaudi::Property< std::string > m_defaultFormat
Definition: MessageSvc.h:134
MessageSvc::m_reportMutex
std::recursive_mutex m_reportMutex
Mutex to synchronize multiple threads printing.
Definition: MessageSvc.h:213
std::multimap::clear
T clear(T...args)
std::move
T move(T...args)
compareOutputFiles.pname
pname
Definition: compareOutputFiles.py:442
std::pair
std::flush
T flush(T...args)
std::set::insert
T insert(T...args)
std::find_if
T find_if(T...args)
std::set< std::string >
std::unique_lock
Message::setFormat
void setFormat(std::string msg) const
Set the format string.
Definition: Message.cpp:171
Message
The Message class.
Definition: Message.h:15
MessageSvc::finalize
StatusCode finalize() override
Finalize Service.
Definition: MessageSvc.cpp:249
Iterator
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
Definition: Iterator.h:18
std::begin
T begin(T...args)
MSG::NUM_LEVELS
Definition: IMessageSvc.h:16
MSG
Print levels enumeration.
Definition: IMessageSvc.h:14
MSG::BLACK
Definition: IMessageSvc.h:17
Message::setTimeFormat
void setTimeFormat(std::string timeFormat) const
Set the time format string.
Definition: Message.cpp:203
std::multimap::emplace
T emplace(T...args)
BrunelScenarioForwardScheduler.app
app
Definition: BrunelScenarioForwardScheduler.py:147
MessageSvc::outputLevel
int outputLevel() const override
Definition: MessageSvc.cpp:598
std::array
STL class.
CommonMessaging
Definition: CommonMessaging.h:62
MSG::ERROR
Definition: IMessageSvc.h:16
MessageSvc::setupLimits
void setupLimits(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:182
MSG::PURPLE
Definition: IMessageSvc.h:17
MessageSvc::setupThreshold
void setupThreshold(Gaudi::Details::PropertyBase &prop)
Definition: MessageSvc.cpp:205
MessageSvc::m_stats
Gaudi::Property< bool > m_stats
Definition: MessageSvc.h:136
MessageSvc::m_logColorCodes
std::string m_logColorCodes[MSG::NUM_LEVELS]
Definition: MessageSvc.h:186
Message::getSource
const std::string & getSource() const
Get the message source.
Definition: Message.cpp:103
gaudirun.level
level
Definition: gaudirun.py:271
MessageSvc::m_msgCount
std::array< int, MSG::NUM_LEVELS > m_msgCount
Definition: MessageSvc.h:198
MessageSvc::m_thresholdProp
std::array< Gaudi::Property< std::vector< std::string > >, MSG::NUM_LEVELS > m_thresholdProp
Definition: MessageSvc.h:139
MSG::WARNING
Definition: IMessageSvc.h:16
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:479
StatusCode.h
std::fill
T fill(T...args)
MessageSvc::m_msgLimit
std::array< Gaudi::Property< int >, MSG::NUM_LEVELS > m_msgLimit
Definition: MessageSvc.h:159
MessageSvc::tee
void tee(const std::string &sourceName, const std::string &logFileName, const std::set< std::string > &declaredOutFileNames)
Definition: MessageSvc.cpp:679
MSG::INFO
Definition: IMessageSvc.h:16
Gaudi::StateMachine::OFFLINE
Definition: StateMachine.h:15
std::for_each
T for_each(T...args)
MessageSvc::m_suppress
Gaudi::Property< bool > m_suppress
Definition: MessageSvc.h:168
MessageSvc::insertMessage
void insertMessage(const StatusCode &code, const Message &message) override
Definition: MessageSvc.cpp:550
MessageSvc
Definition: MessageSvc.h:30
MSG::YELLOW
Definition: IMessageSvc.h:17
MessageSvc::m_loggedStreamsName
Gaudi::Property< std::map< std::string, std::string > > m_loggedStreamsName
Definition: MessageSvc.h:177
std::cout
MsgStream::enableCountInactive
static GAUDI_API bool enableCountInactive(bool value=true)
Enable/disable the count of inactive messages.
Definition: MsgStream.cpp:31
MSG::ALWAYS
Definition: IMessageSvc.h:16
std::multimap::equal_range
T equal_range(T...args)
MessageSvc::insertStream
void insertStream(int message_type, const std::string &name, std::ostream *stream) override
Definition: MessageSvc.cpp:491
MessageSvc::messageCount
int messageCount(MSG::Level logLevel) const override
Definition: MessageSvc.cpp:643
Message.h
MessageSvc::m_thresholdMapMutex
std::recursive_mutex m_thresholdMapMutex
Mutex to synchronize multiple access to m_thresholdMap (.
Definition: MessageSvc.h:220