35 template <
typename Container,
typename Iterator,
typename Predicate>
37 while ( first != last ) {
39 first =
c.erase( first );
45 template <
typename Container,
typename Iterator,
typename Predicate>
46 void erase_if( Container&
c, std::pair<Iterator, Iterator>
range, Predicate pred ) {
47 return erase_if(
c, std::move(
range.first ), std::move(
range.second ), std::forward<Predicate>( pred ) );
50 std::string colTrans( std::string_view col,
int offset ) {
60 return std::to_string( icol + offset );
66 static const std::string levelNames[
MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
67 "WARNING",
"ERROR",
"FATAL",
"ALWAYS" };
73 if (
app )
app->outputLevelUpdate();
125 :
pname ==
"alwaysColorCode"
134 if ( col_desc.size() == 1 ) {
135 const std::string& desc = col_desc[0];
136 if ( desc.empty() ) {
138 }
else if ( desc[0] ==
'[' ) {
139 code =
"\033" + desc;
141 code =
"\033[" + colTrans( desc, 90 ) +
";1m";
143 }
else if ( col_desc.size() == 2 ) {
144 code =
"\033[" + colTrans( col_desc[0], 90 ) +
";" + colTrans( col_desc[1], 100 ) +
";1m";
152 if ( prop.
name() ==
"alwaysLimit" ) {
154 if ( p && p->
value() != 0 ) {
155 std::cout <<
"MessageSvc ERROR: cannot suppress ALWAYS messages" << std::endl;
158 }
else if ( prop.
name() ==
"defaultLimit" ) {
162 }
else if ( prop.
name() !=
"fatalLimit" && prop.
name() !=
"errorLimit" && prop.
name() !=
"warningLimit" &&
163 prop.
name() ==
"infoLimit" && prop.
name() ==
"debugLimit" && prop.
name() ==
"verboseLimit" ) {
164 std::cout <<
"MessageSvc ERROR: Unknown message limit parameter: " << prop.
name() << std::endl;
171 static const std::array<std::pair<const char*, MSG::Level>, 7> tbl{ { {
"setFatal",
MSG::FATAL },
180 [&](
const std::pair<const char*, MSG::Level>&
t ) {
return prop.
name() ==
t.first; } );
182 std::cerr <<
"MessageSvc ERROR: Unknown message threshold parameter: " << prop.
name() << std::endl;
189 std::cerr <<
"could not dcast " << prop.
name()
190 <<
" to a Gaudi::Property<std::vector<std::string>> (which it should be!)" << std::endl;
200 if ( prop.
name() ==
"countInactive" ) {
211 std::ostringstream os;
214 os <<
"Summarizing all message counts" << std::endl;
216 os <<
"Listing sources of suppressed message: " << std::endl;
219 os <<
"=====================================================" << std::endl;
220 os <<
" Message Source | Level | Count" << std::endl;
221 os <<
"-----------------------------+---------+-------------" << std::endl;
231 os.setf( std::ios_base::left, std::ios_base::adjustfield );
236 os.setf( std::ios_base::right, std::ios_base::adjustfield );
237 os << levelNames[ic];
241 os << itr->second.msg[ic];
248 os <<
"=====================================================" << std::endl;
249 if ( found ||
m_stats ) std::cout << os.str() << std::flush;
255 std::ostringstream os;
256 os <<
"Listing sources of Unprotected and Unseen messages\n";
260 unsigned int ml( 0 );
263 if ( itr.second.msg[ic] != 0 && itr.first.length() > ml ) { ml = itr.first.length(); }
267 for (
unsigned int i = 0; i < ml + 25; ++i ) os <<
"=";
269 os << std::endl <<
" ";
271 os.setf( std::ios_base::left, std::ios_base::adjustfield );
272 os <<
"Message Source";
274 os <<
"| Level | Count" << std::endl;
276 for (
unsigned int i = 0; i < ml + 3; ++i ) os <<
"-";
277 os <<
"+---------+-----------" << std::endl;
281 if ( itr->second.msg[ic] != 0 ) {
284 os.setf( std::ios_base::left, std::ios_base::adjustfield );
290 os.setf( std::ios_base::right, std::ios_base::adjustfield );
291 os << levelNames[ic];
296 os << itr->second.msg[ic];
304 for (
unsigned int i = 0; i < ml + 25; ++i ) os <<
"=";
307 if ( found ) std::cout << os.str() << std::flush;
329 if (
m_loggedStreams.end() != iLog ) { ( *iLog->second ) << *cmsg << std::endl; }
341 std::string txt = levelNames[
key] +
" message limit (" + std::to_string(
m_msgLimit[
key].value() ) +
342 ") reached for " +
msg.getSource() +
". Suppressing further output.";
352 [&]( StreamMap::const_reference sm ) { *sm.second.second << *cmsg << std::endl; } );
357 ( *m_defaultStream ) << *cmsg << std::endl << std::flush;
359 ( *m_defaultStream ) <<
m_logColorCodes[
key] << *cmsg <<
"\033[m" << std::endl << std::flush;
363 if ( cmsg != &
msg ) {
delete cmsg; }
379 auto report = [&](
Message mesg ) {
380 mesg.setSource( source );
381 Message stat_code( std::string{ source }, mesg.getType(),
"Status Code " + std::to_string( code.
getCode() ) );
405 [&]( StreamMap::const_reference
j ) { return j.second.second == stream; } );
411 erase_if(
m_streamMap, [&]( StreamMap::const_reference
j ) {
return j.second.second ==
stream; } );
434 [&]( MessageMap::const_reference
j ) { return j.second == msg; } );
454 }
else if ( i->second !=
level ) {
468 ++entry->second.msg[
level];
472 std::cout <<
"== inactive message detected from " << source <<
" ==\n";
475 std::cout <<
t << std::endl;
484 std::set<std::string_view> outFileNames;
486 std::inserter( outFileNames, outFileNames.end() ),
487 [](
const auto& p ) -> std::string_view { return p.second; } );
489 std::map<std::string_view, std::shared_ptr<std::ofstream>> outStreams;
490 std::transform( outFileNames.begin(), outFileNames.end(), std::inserter( outStreams, outStreams.end() ),
491 []( std::string_view fname ) {
492 return std::pair{ fname, std::make_shared<std::ofstream>(
493 std::string{ fname }, std::ios_base::out | std::ios_base::trunc ) };
496 for (
auto& iProp : m_loggedStreamsName ) {
497 auto&
stream = outStreams.at( iProp.second );
498 if (
stream->good() ) m_loggedStreams.emplace( iProp.first,
stream );