LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
mf::service::ELdestination Class Reference

#include "ELdestination.h"

Inheritance diagram for mf::service::ELdestination:
mf::service::ELostreamOutput mf::service::ELstatistics mfplugins::ELsyslog

Classes

struct  Category
 
struct  CategoryParams
 
struct  Config
 
class  MsgFormatSettings
 
class  MsgStatistics
 
struct  StatsCount
 
struct  XidLimiter
 

Public Types

enum  flag_enum {
  NO_LINE_BREAKS, TIMESTAMP, MILLISECOND, MODULE,
  SUBROUTINE, TEXT, SOME_CONTEXT, SERIAL,
  FULL_CONTEXT, TIME_SEPARATE, EPILOGUE_SEPARATE, NFLAGS
}
 

Public Member Functions

virtual ~ELdestination () noexcept=default
 
 ELdestination (Config const &)
 
 ELdestination (ELdestination const &)=delete
 
 ELdestination (ELdestination &&)=delete
 
ELdestinationoperator= (ELdestination const &)=delete
 
ELdestinationoperator= (ELdestination &&)=delete
 
void setThreshold (ELseverityLevel sv)
 
virtual void log (mf::ErrorObj &)
 
virtual void finish ()
 
virtual void summary ()
 

Protected Member Functions

std::string summarizeContext (std::string const &)
 
void emitToken (std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
 
std::string formSummary ()
 
bool skipMsg (ELextendedID const &)
 
void resetLimiters ()
 
void resetMsgCounters ()
 
virtual void fillPrefix (std::ostringstream &, mf::ErrorObj const &msg)
 
virtual void fillUsrMsg (std::ostringstream &, mf::ErrorObj const &msg)
 
virtual void fillSuffix (std::ostringstream &, mf::ErrorObj const &msg)
 
virtual void routePayload (std::ostringstream const &, mf::ErrorObj const &msg)
 
virtual void flush ()
 

Protected Attributes

ELseverityLevel threshold_
 
MsgFormatSettings format_
 
int defaultLimit_
 
int defaultReportEvery_
 
int defaultTimespan_
 
std::map< std::string const, CategoryParamscategoryParams_
 
std::map< ELextendedID const, XidLimiterxidLimiters_
 
std::map< ELextendedID const, StatsCountstatsMap_
 
bool outputStatistics_ {false}
 
bool updatedStats_ {false}
 
bool reset_ {false}
 

Private Attributes

std::size_t charsOnLine_ {}
 

Detailed Description

Definition at line 24 of file ELdestination.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

virtual mf::service::ELdestination::~ELdestination ( )
virtualdefaultnoexcept
mf::service::ELdestination::ELdestination ( Config const &  pset)

Definition at line 274 of file ELdestination.cc.

References util::begin(), categoryParams_, charsOnLine_, defaultLimit_, defaultReportEvery_, defaultTimespan_, e, util::end(), format_, fhicl::ParameterSet::get_if_present(), fhicl::ParameterSet::get_pset_names(), outputStatistics_, reset_, statsMap_, mf::service::ELdestination::Config::threshold, updatedStats_, fhicl::detail::validationException::what(), and xidLimiters_.

275  : threshold_{pset.threshold()}
276  , format_{pset.format()}
277  , defaultLimit_{numeric_limits<decltype(defaultLimit_)>::max()}
278  , defaultReportEvery_{-1}
279  , defaultTimespan_{numeric_limits<decltype(defaultTimespan_)>::max()}
280  , categoryParams_{}
281  , xidLimiters_{}
282  , statsMap_{}
283  , outputStatistics_{pset.outputStatistics()}
284  , updatedStats_{false}
285  , reset_{pset.msgStatistics().reset() ||
286  pset.msgStatistics().resetStatistics()}
287  , charsOnLine_{}
288  {
289  vector<string> configuration_errors;
290  // Grab this destination's category configurations.
291  fhicl::ParameterSet cats_pset{};
292  pset.categories.get_if_present<fhicl::ParameterSet>(cats_pset);
293  // Grab the list of categories, removing the default category
294  // since it is handled specially.
295  auto const default_category_name = "default"s;
296  auto categories = cats_pset.get_pset_names();
297  auto erase_from =
298  remove_if(begin(categories), end(categories), [](auto const& category) {
299  return category == "default"s;
300  });
301  categories.erase(erase_from, categories.cend());
302  // Setup the default configuration for categories--this involves
303  // resetting the limits table according to the user-specified
304  // default configuration.
305  auto const& default_pset =
306  cats_pset.get<fhicl::ParameterSet>("default"s, {});
307  try {
308  fhicl::WrappedTable<Category::Config> default_params{default_pset};
309  defaultLimit_ = (default_params().limit() < 0) ?
310  numeric_limits<decltype(defaultLimit_)>::max() :
311  default_params().limit();
312  defaultReportEvery_ = default_params().reportEvery();
313  defaultTimespan_ = (default_params().timespan() < 0) ?
314  numeric_limits<decltype(defaultTimespan_)>::max() :
315  default_params().timespan();
316  }
317  catch (fhicl::detail::validationException const& e) {
318  string msg{"Category: "s + cet::bold_fontify("default"s) + "\n\n"s};
319  msg += e.what();
320  configuration_errors.push_back(std::move(msg));
321  }
322  // Now establish this destination's limit/reportEvery/timespan for
323  // each category, using the values of the possibly-specified
324  // default configuration when a given category is missing the
325  // fields.
326  for (auto const& category : categories) {
327  fhicl::Table<Category::Config> category_params{fhicl::Name{category},
328  default_pset};
329  try {
330  category_params.validate(cats_pset.get<fhicl::ParameterSet>(category));
331  }
332  catch (fhicl::detail::validationException const& e) {
333  string msg{"Category: " + cet::bold_fontify(category) + "\n\n"};
334  msg += e.what();
335  configuration_errors.push_back(std::move(msg));
336  }
337 
338  if (category_params().limit() < 0) {
339  categoryParams_[category].limit_ = numeric_limits<int>::max();
340  } else {
341  categoryParams_[category].limit_ = category_params().limit();
342  }
343  categoryParams_[category].reportEvery_ = category_params().reportEvery();
344  if (category_params().timespan() < 0) {
345  categoryParams_[category].timespan_ = numeric_limits<int>::max();
346  } else {
347  categoryParams_[category].timespan_ = category_params().timespan();
348  }
349  }
350  if (!configuration_errors.empty()) {
351  string msg{"The following categories were misconfigured:\n\n"};
352  for (auto const& error : configuration_errors) {
353  msg += error;
354  }
356  }
357  }
std::map< std::string const, CategoryParams > categoryParams_
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
std::vector< std::string > get_pset_names() const
std::map< ELextendedID const, StatsCount > statsMap_
ELseverityLevel threshold_
char const * what() const noexcept override
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:267
MsgFormatSettings format_
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
std::map< ELextendedID const, XidLimiter > xidLimiters_
Float_t e
Definition: plot.C:35
mf::service::ELdestination::ELdestination ( ELdestination const &  )
delete
mf::service::ELdestination::ELdestination ( ELdestination &&  )
delete

Member Function Documentation

void mf::service::ELdestination::emitToken ( std::ostream &  os,
std::string const &  s,
bool  nl = false,
bool  preambleMode = false 
)
protected

Definition at line 390 of file ELdestination.cc.

References charsOnLine_, format_, art::detail::indent(), and mf::service::ELdestination::MsgFormatSettings::lineLength.

Referenced by mf::service::ELostreamOutput::ELostreamOutput(), fillPrefix(), fillSuffix(), and fillUsrMsg().

394  {
395  string const indent(6, ' ');
396  if (s.empty()) {
397  if (nl) {
398  os << '\n';
399  charsOnLine_ = 0UL;
400  }
401  return;
402  }
403  if (!preambleMode) {
404  os << s;
405  return;
406  }
407  char const first = s[0];
408  char const second = (s.length() < 2) ? '\0' : s[1];
409  char const last = (s.length() < 2) ? '\0' : s[s.length() - 1];
410  char const last2 = (s.length() < 3) ? '\0' : s[s.length() - 2];
411  // checking -2 because the very last char is sometimes a ' '
412  // inserted by ErrorLog::operator<<
413  // Accounts for newline @ the beginning of the string
414  if (first == '\n' || (charsOnLine_ + s.length()) > format_.lineLength) {
415  charsOnLine_ = 0UL;
416  if (second != ' ') {
417  os << ' ';
418  ++charsOnLine_;
419  }
420  if (first == '\n') {
421  os << s.substr(1);
422  } else {
423  os << s;
424  }
425  } else {
426  os << s;
427  }
428  if ((last == '\n') || (last2 == '\n')) {
429  os << indent;
430  if (last != ' ') {
431  os << ' ';
432  }
433  charsOnLine_ = indent.length() + 1UL;
434  }
435  if (nl) {
436  os << '\n';
437  charsOnLine_ = 0UL;
438  } else {
439  charsOnLine_ += s.length();
440  }
441  }
std::string indent(std::size_t const i)
MsgFormatSettings format_
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
std::string nl(std::size_t i=1)
void mf::service::ELdestination::fillPrefix ( std::ostringstream &  oss,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog.

Definition at line 444 of file ELdestination.cc.

References charsOnLine_, mf::ErrorObj::context(), emitToken(), EPILOGUE_SEPARATE, format_, mf::ErrorObj::idOverflow(), mf::ErrorObj::is_verbatim(), MODULE, mf::ErrorObj::serial(), SERIAL, SOME_CONTEXT, SUBROUTINE, TIME_SEPARATE, TIMESTAMP, mf::ErrorObj::timestamp(), mf::service::ELdestination::MsgFormatSettings::timestamp(), mf::service::ELdestination::MsgFormatSettings::want(), and mf::ErrorObj::xid().

Referenced by log().

445  {
446  if (msg.is_verbatim()) {
447  return;
448  }
449  auto const& xid = msg.xid();
450  charsOnLine_ = 0UL;
451  emitToken(oss, "%MSG"s, false, true);
452  emitToken(oss, xid.severity().getSymbol(), false, true);
453  emitToken(oss, " ", false, true);
454  emitToken(oss, xid.id(), false, true);
455  emitToken(oss, msg.idOverflow(), false, true);
456  emitToken(oss, ": ", false, true);
457  if (format_.want(SERIAL)) {
458  ostringstream s;
459  s << msg.serial();
460  emitToken(oss, "[serial #" + s.str() + "] ", false, true);
461  }
462  bool needAspace = true;
464  if (xid.module().length() + xid.subroutine().length() > 0) {
465  emitToken(oss, "\n", false, true);
466  needAspace = false;
467  } else if (format_.want(TIMESTAMP) && !format_.want(TIME_SEPARATE)) {
468  emitToken(oss, "\n", false, true);
469  needAspace = false;
470  }
471  }
472  if (format_.want(MODULE) && (xid.module().length() > 0)) {
473  if (needAspace) {
474  emitToken(oss, " ", false, true);
475  needAspace = false;
476  }
477  emitToken(oss, xid.module() + " ", false, true);
478  }
479  if (format_.want(SUBROUTINE) && (xid.subroutine().length() > 0)) {
480  if (needAspace) {
481  emitToken(oss, " ", false, true);
482  needAspace = false;
483  }
484  emitToken(oss, xid.subroutine() + "() ", false, true);
485  }
486  if (format_.want(TIMESTAMP)) {
487  if (format_.want(TIME_SEPARATE)) {
488  emitToken(oss, "\n", false, true);
489  needAspace = false;
490  }
491  if (needAspace) {
492  emitToken(oss, " ", false, true);
493  needAspace = false;
494  }
495  emitToken(oss, format_.timestamp(msg.timestamp()) + " ", false, true);
496  }
497  if (format_.want(SOME_CONTEXT)) {
498  if (needAspace) {
499  emitToken(oss, " ", false, true);
500  needAspace = false;
501  }
502  emitToken(oss, msg.context(), false, true);
503  }
504  }
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
MsgFormatSettings format_
void mf::service::ELdestination::fillSuffix ( std::ostringstream &  oss,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog.

Definition at line 534 of file ELdestination.cc.

References emitToken(), format_, mf::ErrorObj::is_verbatim(), NO_LINE_BREAKS, and mf::service::ELdestination::MsgFormatSettings::want().

Referenced by log().

535  {
536  if (!msg.is_verbatim() && !format_.want(NO_LINE_BREAKS)) {
537  emitToken(oss, "\n%MSG");
538  }
539  oss << '\n';
540  }
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
MsgFormatSettings format_
void mf::service::ELdestination::fillUsrMsg ( std::ostringstream &  oss,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog.

Definition at line 507 of file ELdestination.cc.

References emitToken(), mf::ErrorObj::filename(), format_, mf::ErrorObj::is_verbatim(), mf::ErrorObj::items(), mf::ErrorObj::lineNumber(), NO_LINE_BREAKS, TEXT, util::to_string(), and mf::service::ELdestination::MsgFormatSettings::want().

Referenced by mfplugins::ELsyslog::fillUsrMsg(), and log().

508  {
509  if (!format_.want(TEXT)) {
510  return;
511  }
512  // Determine if file and line should be included
513  if (!msg.is_verbatim()) {
514  if (!msg.filename().empty()) {
515  emitToken(oss, " "s);
516  emitToken(oss, msg.filename());
517  emitToken(oss, ":"s);
518  emitToken(oss, to_string(msg.lineNumber()));
519  }
520  // Check for user-requested line breaks
521  if (format_.want(NO_LINE_BREAKS)) {
522  emitToken(oss, " ==> ");
523  } else {
524  emitToken(oss, "", true);
525  }
526  }
527  // Print the contents.
528  for (auto const& val : msg.items()) {
529  emitToken(oss, val);
530  }
531  }
void emitToken(std::ostream &os, std::string const &s, bool nl=false, bool preambleMode=false)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
MsgFormatSettings format_
void mf::service::ELdestination::finish ( )
virtual

Definition at line 703 of file ELdestination.cc.

704  {}
void mf::service::ELdestination::flush ( )
protectedvirtual

Definition at line 715 of file ELdestination.cc.

References mf::ELwarning, and log().

716  {
717  ErrorObj msg{ELwarning, "ELdestination"s};
718  msg << "Call to unimplemented flush()!";
719  log(msg);
720  }
virtual void log(mf::ErrorObj &)
ELslProxy< ELwarningGen > constexpr ELwarning
string mf::service::ELdestination::formSummary ( )
protected

Definition at line 576 of file ELdestination.cc.

References art::left(), n, mf::ELseverityLevel::nLevels, art::right(), and statsMap_.

Referenced by mf::service::ELstatistics::summary(), and summary().

577  {
578  ostringstream s;
579  int n{};
580  // ----- Summary part I:
581  //
582  bool ftnote{false};
583  struct part3 {
584  long n{}, t{};
586  for (auto const& [xid, count] : statsMap_) {
587  auto const& cat = xid.id();
588  // ----- Emit new part I header, if needed:
589  //
590  if (n == 0) {
591  s << "\n";
592  s << " type category sev module subroutine "
593  " count total\n"
594  << " ---- -------------------- -- ---------------- "
595  "---------------- ----- -----\n";
596  }
597  // ----- Emit detailed message information:
598  //
599  s
600  // Type
601  << right << setw(5) << ++n
602  << ' '
603  // Category
604  << left << setw(20) << cat.substr(0, 20)
605  << ' '
606  // Severity
607  << left << setw(2) << xid.severity().getSymbol()
608  << ' '
609  // Module
610  << left << setw(16) << xid.module().substr(0, 16)
611  << ' '
612  // Subroutine
613  << left << setw(16)
614  << xid.subroutine().substr(0, 16)
615  // Count
616  << right << setw(7) << count.n_ << left << setw(1)
617  << (count.ignoredFlag_ ? '*' : ' ')
618  // Total Count
619  << right << setw(8) << count.aggregateN_ << '\n';
620  ftnote = ftnote || count.ignoredFlag_;
621  // ----- Obtain information for Part III, below:
622  //
623  p3[xid.severity().getLevel()].n += count.n_;
624  p3[xid.severity().getLevel()].t += count.aggregateN_;
625  }
626  // ----- Provide footnote to part I, if needed:
627  //
628  if (ftnote) {
629  s << "\n* Some occurrences of this message were suppressed in all "
630  "logs, due to limits.\n";
631  }
632  // ----- Summary part II:
633  //
634  n = 0;
635  for (auto const& pr : statsMap_) {
636  auto const& xid = pr.first;
637  auto const& count = pr.second;
638  string const& cat = xid.id();
639  if (n == 0) {
640  s << '\n'
641  << " type category Examples: run/evt run/evt "
642  "run/evt\n"
643  << " ---- -------------------- ---------------- ---------------- "
644  "----------------\n";
645  }
646  s
647  // Type
648  << right << setw(5) << ++n
649  << ' '
650  // Category
651  << left << setw(20) << cat
652  << ' '
653  // Context1
654  << left << setw(16) << count.context1_.c_str()
655  << ' '
656  // Context2
657  << left << setw(16) << count.context2_.c_str()
658  << ' '
659  // ContextLast
660  << count.contextLast_ << '\n';
661  }
662  // ----- Summary part III:
663  //
664  s << '\n'
665  << "Severity # Occurrences Total Occurrences\n"
666  << "-------- ------------- -----------------\n";
667  for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
668  if (p3[k].n != 0 || p3[k].t != 0) {
669  s
670  // Severity
671  << left << setw(8)
672  << ELseverityLevel{ELseverityLevel::ELsev_(k)}.getName().c_str()
673  // Occurrences
674  << right << setw(17)
675  << p3[k].n
676  // Total Occurrences
677  << right << setw(20) << p3[k].t << '\n';
678  }
679  }
680  return s.str();
681  }
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
std::map< ELextendedID const, StatsCount > statsMap_
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
Char_t n[5]
void mf::service::ELdestination::log ( mf::ErrorObj msg)
virtual

Reimplemented in mf::service::ELstatistics.

Definition at line 547 of file ELdestination.cc.

References mf::ErrorObj::context(), fillPrefix(), fillSuffix(), fillUsrMsg(), outputStatistics_, routePayload(), mf::ErrorObj::setReactedTo(), mf::ELextendedID::severity(), skipMsg(), statsMap_, summarizeContext(), threshold_, updatedStats_, and mf::ErrorObj::xid().

Referenced by flush().

548  {
549  if (msg.xid().severity() < threshold_) {
550  if (outputStatistics_) {
551  statsMap_[msg.xid()].add(summarizeContext(msg.context()), false);
552  updatedStats_ = true;
553  }
554  return;
555  }
556  if (skipMsg(msg.xid())) {
557  if (outputStatistics_) {
558  statsMap_[msg.xid()].add(summarizeContext(msg.context()), false);
559  updatedStats_ = true;
560  }
561  return;
562  }
563  msg.setReactedTo(true);
564  ostringstream payload;
565  fillPrefix(payload, msg);
566  fillUsrMsg(payload, msg);
567  fillSuffix(payload, msg);
568  routePayload(payload, msg);
569  if (outputStatistics_) {
570  statsMap_[msg.xid()].add(summarizeContext(msg.context()), true);
571  updatedStats_ = true;
572  }
573  }
ELseverityLevel severity() const
Definition: ELextendedID.cc:33
virtual void fillUsrMsg(std::ostringstream &, mf::ErrorObj const &msg)
bool skipMsg(ELextendedID const &)
virtual void fillSuffix(std::ostringstream &, mf::ErrorObj const &msg)
std::string const & context() const
Definition: ErrorObj.cc:98
std::map< ELextendedID const, StatsCount > statsMap_
std::string summarizeContext(std::string const &)
ELextendedID const & xid() const
Definition: ErrorObj.cc:61
ELseverityLevel threshold_
virtual void fillPrefix(std::ostringstream &, mf::ErrorObj const &msg)
virtual void setReactedTo(bool)
Definition: ErrorObj.cc:177
virtual void routePayload(std::ostringstream const &, mf::ErrorObj const &msg)
ELdestination& mf::service::ELdestination::operator= ( ELdestination const &  )
delete
ELdestination& mf::service::ELdestination::operator= ( ELdestination &&  )
delete
void mf::service::ELdestination::resetLimiters ( )
protected

Definition at line 819 of file ELdestination.cc.

References xidLimiters_.

Referenced by mf::service::ELstatistics::summary(), and summary().

820  {
821  xidLimiters_.clear();
822  }
std::map< ELextendedID const, XidLimiter > xidLimiters_
void mf::service::ELdestination::resetMsgCounters ( )
protected

Definition at line 813 of file ELdestination.cc.

References statsMap_.

Referenced by mf::service::ELstatistics::summary(), and summary().

814  {
815  statsMap_.clear();
816  }
std::map< ELextendedID const, StatsCount > statsMap_
void mf::service::ELdestination::routePayload ( std::ostringstream const &  ,
mf::ErrorObj const &  msg 
)
protectedvirtual

Reimplemented in mfplugins::ELsyslog, and mf::service::ELostreamOutput.

Definition at line 543 of file ELdestination.cc.

Referenced by log(), and summary().

544  {}
void mf::service::ELdestination::setThreshold ( ELseverityLevel  sv)

Definition at line 709 of file ELdestination.cc.

References threshold_.

710  {
711  threshold_ = sv;
712  }
ELseverityLevel threshold_
bool mf::service::ELdestination::skipMsg ( ELextendedID const &  xid)
protected

Definition at line 726 of file ELdestination.cc.

References categoryParams_, defaultLimit_, defaultReportEvery_, defaultTimespan_, mf::ELextendedID::id(), mf::service::ELdestination::XidLimiter::limit_, mf::service::ELdestination::XidLimiter::msgCount_, mf::service::ELdestination::XidLimiter::previousTimestamp_, r, mf::service::ELdestination::XidLimiter::reportEvery_, mf::service::ELdestination::XidLimiter::skippedMsgCount_, mf::service::ELdestination::XidLimiter::timespan_, and xidLimiters_.

Referenced by mf::service::ELstatistics::log(), and log().

727  {
728  auto xl_iter = xidLimiters_.find(xid);
729  if (xl_iter == xidLimiters_.end()) {
730  // Need to create and initialize a limiter for this xid.
731  int limit{defaultLimit_};
732  int reportEvery{defaultReportEvery_};
733  int timespan{defaultTimespan_};
734  // Does the category of this xid have explicit limits?
735  auto cp_iter = categoryParams_.find(xid.id());
736  if (cp_iter != categoryParams_.end()) {
737  // Category limits found, use them.
738  auto const& cp = cp_iter->second;
739  limit = (cp.limit_ < 0) ? defaultLimit_ : cp.limit_;
740  reportEvery =
741  (cp.reportEvery_ < 0) ? defaultReportEvery_ : cp.reportEvery_;
742  timespan = (cp.timespan_ < 0) ? defaultTimespan_ : cp.timespan_;
743  }
744  XidLimiter& limiter = xidLimiters_[xid];
745  limiter.previousTimestamp_ = time(0);
746  limiter.msgCount_ = 0;
747  limiter.skippedMsgCount_ =
748  reportEvery - 1; // So that the FIRST of the prescaled messages emerges
749  limiter.limit_ = limit;
750  limiter.reportEvery_ = reportEvery;
751  limiter.timespan_ = timespan;
752  xl_iter = xidLimiters_.find(xid);
753  }
754  XidLimiter& limiter = xl_iter->second;
755  time_t now = time(0);
756  // Has it been so long that we should restart counting toward the limit?
757  if ((limiter.timespan_ >= 0) &&
758  (difftime(now, limiter.previousTimestamp_) >= limiter.timespan_)) {
759  limiter.msgCount_ = 0;
760  if (limiter.reportEvery_ > 0) {
761  // So this message will be reacted to
762  limiter.skippedMsgCount_ = limiter.reportEvery_ - 1;
763  } else {
764  limiter.skippedMsgCount_ = 0;
765  }
766  }
767  limiter.previousTimestamp_ = now;
768  ++limiter.msgCount_;
769  ++limiter.skippedMsgCount_;
770  if (limiter.skippedMsgCount_ < limiter.reportEvery_) {
771  // Skip message.
772  return true;
773  }
774  if (limiter.limit_ == 0) {
775  // Zero limit - never react to this
776  // Skip message.
777  return true;
778  }
779  if ((limiter.limit_ < 0) || (limiter.msgCount_ <= limiter.limit_)) {
780  limiter.skippedMsgCount_ = 0;
781  // Accept message.
782  return false;
783  }
784  // Now we are over the limit - have we exceeded limit by 2^N * limit?
785  long diff = limiter.msgCount_ - limiter.limit_;
786  long r = diff / limiter.limit_;
787  if (r * limiter.limit_ != diff) {
788  // Not a multiple of limit - don't react
789  // Skip message.
790  return true;
791  }
792  if (r == 1) {
793  // Exactly twice limit - react
794  limiter.skippedMsgCount_ = 0;
795  // Accept message.
796  return false;
797  }
798  while (r > 1) {
799  if ((r & 1) != 0) {
800  // Not 2**msgCount_ times limit - don't react
801  // Skip message.
802  return true;
803  }
804  r >>= 1;
805  }
806  // If you never get an odd number till one, r is 2**msgCount_ so react
807  limiter.skippedMsgCount_ = 0;
808  // Accept message.
809  return false;
810  }
TRandom r
Definition: spectrum.C:23
std::map< std::string const, CategoryParams > categoryParams_
std::map< ELextendedID const, XidLimiter > xidLimiters_
string mf::service::ELdestination::summarizeContext ( std::string const &  )
protected

Definition at line 360 of file ELdestination.cc.

Referenced by mf::service::ELstatistics::log(), and log().

361  {
362  if (c.substr(0, 4) != "Run:") {
363  return c;
364  }
365  istringstream is(c);
366  string runWord;
367  int run;
368  is >> runWord >> run;
369  if (!is) {
370  return c;
371  }
372  if (runWord != "Run:") {
373  return c;
374  }
375  string eventWord;
376  int event;
377  is >> eventWord >> event;
378  if (!is) {
379  return c;
380  }
381  if (eventWord != "Event:") {
382  return c;
383  }
384  ostringstream os;
385  os << run << "/" << event;
386  return os.str();
387  }
Event finding and building.
void mf::service::ELdestination::summary ( )
virtual

Reimplemented in mf::service::ELstatistics.

Definition at line 686 of file ELdestination.cc.

References mf::ELzeroSeverity, formSummary(), outputStatistics_, reset_, resetLimiters(), resetMsgCounters(), routePayload(), and updatedStats_.

687  {
689  ostringstream payload;
690  payload << "\n=============================================\n\n"
691  << "MessageLogger Summary\n"
692  << formSummary();
693  routePayload(payload, ErrorObj{ELzeroSeverity, "No ostream"s});
694  }
695  updatedStats_ = false;
696  if (reset_) {
698  resetLimiters();
699  }
700  }
ELslProxy< ELzeroSeverityGen > constexpr ELzeroSeverity
virtual void routePayload(std::ostringstream const &, mf::ErrorObj const &msg)

Member Data Documentation

std::map<std::string const, CategoryParams> mf::service::ELdestination::categoryParams_
protected

Definition at line 229 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

std::size_t mf::service::ELdestination::charsOnLine_ {}
private

Definition at line 237 of file ELdestination.h.

Referenced by ELdestination(), emitToken(), and fillPrefix().

int mf::service::ELdestination::defaultLimit_
protected

Definition at line 226 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

int mf::service::ELdestination::defaultReportEvery_
protected

Definition at line 227 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

int mf::service::ELdestination::defaultTimespan_
protected

Definition at line 228 of file ELdestination.h.

Referenced by ELdestination(), and skipMsg().

MsgFormatSettings mf::service::ELdestination::format_
protected
bool mf::service::ELdestination::outputStatistics_ {false}
protected
bool mf::service::ELdestination::reset_ {false}
protected

Definition at line 234 of file ELdestination.h.

Referenced by ELdestination(), mf::service::ELstatistics::summary(), and summary().

std::map<ELextendedID const, StatsCount> mf::service::ELdestination::statsMap_
protected
ELseverityLevel mf::service::ELdestination::threshold_
protected

Definition at line 224 of file ELdestination.h.

Referenced by mf::service::ELstatistics::log(), log(), and setThreshold().

bool mf::service::ELdestination::updatedStats_ {false}
protected
std::map<ELextendedID const, XidLimiter> mf::service::ELdestination::xidLimiters_
protected

Definition at line 230 of file ELdestination.h.

Referenced by ELdestination(), resetLimiters(), and skipMsg().


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