version  0.0.1
Defines the C++ API for MsPASS
Public Member Functions | List of all members
mspass::utility::ErrorLogger Class Reference

Container to hold error logs for a data object. More...

#include <ErrorLogger.h>

Public Member Functions

 ErrorLogger (int job)
 
 ErrorLogger (const ErrorLogger &parent)
 
void set_job_id (int jid)
 
int get_job_id ()
 
int log_error (const mspass::utility::MsPASSError &merr)
 
int log_error (const std::string alg, const std::string mess, const mspass::utility::ErrorSeverity level)
 
int log_verbose (const std::string alg, const std::string mess)
 Log a verbose message marking it informational. More...
 
std::list< LogDataget_error_log () const
 
int size () const
 
void clear ()
 
ErrorLoggeroperator= (const ErrorLogger &parent)
 
ErrorLoggeroperator+= (const ErrorLogger &parent)
 
std::list< LogDataworst_errors () const
 

Detailed Description

Container to hold error logs for a data object.

This class is intended mainly to be added to data objects in mspass to provide a scalable, thread safe method for logging errors. Atomic mspass data objects (e.g. seismograms and time series objects) all use this class to log errors and mark data with ambiguous states. The log can explain why data is an invalid state, but can also contain debug information normally enabled by something like a verbose option to a program.

Member Function Documentation

◆ clear()

void mspass::utility::ErrorLogger::clear ( )
inline

Reset error log container to make it empty.

106 {allmessages.clear();};

◆ log_error() [1/2]

int mspass::utility::ErrorLogger::log_error ( const mspass::utility::MsPASSError merr)

Logs one error message.

Parameters
merr- many mspass procedures throw MsPASSError objects. This simplifies the process of posting them to an error log.
Returns
size of error log after insertion.
82 {
83  LogData thislog(this->job_id,string("MsPASSError"),merr);
84  allmessages.push_back(thislog);
85  return allmessages.size();
86 }
Definition: ErrorLogger.h:16

◆ log_error() [2/2]

int mspass::utility::ErrorLogger::log_error ( const std::string  alg,
const std::string  mess,
const mspass::utility::ErrorSeverity  level = ErrorSeverity::Invalid 
)

Log one a message directly with a specified severity.

This is a convenience overload of log_error. It splits the MsPASSError components as arguments with a default that allows a default behavior of Invalid as the error state.

Parameters
algis name of algorithm posting this message
messis the message to be posted.
levelis the badness level to be set with the message. (default is ErrorSeverity::Invalid).
Returns
size of error log after insertion.
89 {
90  LogData thislog(this->job_id,alg,mess,level);
91  allmessages.push_back(thislog);
92  return allmessages.size();
93 }

◆ log_verbose()

int mspass::utility::ErrorLogger::log_verbose ( const std::string  alg,
const std::string  mess 
)

Log a verbose message marking it informational.

Frequently programs need a verbose option to log something of interest that is not an error but potentially useful. This alternate logging method posts the string mess and marks it Informational. Returns the size of the log after insertion.

95 {
96  int count;
97  count=this->log_error(alg,mess,ErrorSeverity::Informational);
98  return count;
99 };
int log_error(const mspass::utility::MsPASSError &merr)
Definition: ErrorLogger.cc:81

◆ operator+=()

ErrorLogger & mspass::utility::ErrorLogger::operator+= ( const ErrorLogger parent)

For this object + of += means add the log data from the rhs to the lhs. lhs defines the job_id.

71 {
72  if(this!=&other)
73  {
74  for(auto lptr=other.allmessages.begin();lptr!=other.allmessages.end();++lptr)
75  {
76  this->allmessages.push_back(*lptr);
77  }
78  }
79  return *this;
80 }

◆ worst_errors()

list< LogData > mspass::utility::ErrorLogger::worst_errors ( ) const

Return an std::list container with most serious error level marked.

108 {
109  /* Return immediately if the messages container is empty. */
110  if(allmessages.size()<=0) return allmessages;
111  list<LogData> flist,ivlist,slist,clist,dlist,ilist;
112  list<LogData>::const_iterator aptr;
113  for(aptr=allmessages.begin();aptr!=allmessages.end();++aptr)
114  {
115  switch(aptr->badness)
116  {
117  case ErrorSeverity::Fatal:
118  flist.push_back(*aptr);
119  break;
120  case ErrorSeverity::Invalid:
121  ivlist.push_back(*aptr);
122  break;
123  case ErrorSeverity::Suspect:
124  slist.push_back(*aptr);
125  break;
126  case ErrorSeverity::Complaint:
127  clist.push_back(*aptr);
128  break;
129  case ErrorSeverity::Debug:
130  dlist.push_back(*aptr);
131  break;
132  case ErrorSeverity::Informational:
133  default:
134  ilist.push_back(*aptr);
135  };
136  }
137  if(flist.size()>0) return flist;
138  if(ivlist.size()>0) return ivlist;
139  if(slist.size()>0) return slist;
140  if(clist.size()>0) return clist;
141  if(dlist.size()>0) return dlist;
142  return ilist;
143 }

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