version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
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.
 
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.

Constructor & Destructor Documentation

◆ ErrorLogger() [1/3]

mspass::utility::ErrorLogger::ErrorLogger ( )
inline
62{ job_id = 0; };

◆ ErrorLogger() [2/3]

mspass::utility::ErrorLogger::ErrorLogger ( int  job)
inline
63{ job_id = job; };

◆ ErrorLogger() [3/3]

mspass::utility::ErrorLogger::ErrorLogger ( const ErrorLogger parent)
48 {
49 job_id = parent.job_id;
50 /* Just copy this. Could call getpid every time, but the only way I can
51 conceive that would be an issue is if the entry were serialized and sent
52 somewhere through something like mpi. A copy is a copy so seems best to
53 clone this not ask for confusion. */
54 allmessages = parent.allmessages;
55}

Member Function Documentation

◆ clear()

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

Reset error log container to make it empty.

102{ allmessages.clear(); };

◆ get_error_log()

std::list< LogData > mspass::utility::ErrorLogger::get_error_log ( ) const
inline
99{ return allmessages; };

◆ get_job_id()

int mspass::utility::ErrorLogger::get_job_id ( )
inline
66{ return job_id; };

◆ 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.
72 {
73 LogData thislog(this->job_id, string("MsPASSError"), merr);
74 allmessages.push_back(thislog);
75 return allmessages.size();
76}
Definition ErrorLogger.h:14

◆ 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.
79 {
80 LogData thislog(this->job_id, alg, mess, level);
81 allmessages.push_back(thislog);
82 return allmessages.size();
83}

◆ 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.

84 {
85 int count;
86 count = this->log_error(alg, mess, ErrorSeverity::Informational);
87 return count;
88};
int log_error(const mspass::utility::MsPASSError &merr)
Definition ErrorLogger.cc:72

References log_error().

◆ 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.

63 {
64 if (this != &other) {
65 for (auto lptr = other.allmessages.begin(); lptr != other.allmessages.end();
66 ++lptr) {
67 this->allmessages.push_back(*lptr);
68 }
69 }
70 return *this;
71}

◆ operator=()

ErrorLogger & mspass::utility::ErrorLogger::operator= ( const ErrorLogger parent)
56 {
57 if (this != &parent) {
58 job_id = parent.job_id;
59 allmessages = parent.allmessages;
60 }
61 return *this;
62}

◆ set_job_id()

void mspass::utility::ErrorLogger::set_job_id ( int  jid)
inline
65{ job_id = jid; };

◆ size()

int mspass::utility::ErrorLogger::size ( ) const
inline
100{ return allmessages.size(); };

◆ worst_errors()

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

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

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

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