version  0.0.1
Defines the C++ API for MsPASS
Loading...
Searching...
No Matches
ErrorLogger.h
1#ifndef _ERROR_LOGGER_H_
2#define _ERROR_LOGGER_H_
3#include "mspass/utility/ErrorLogger.h"
4#include "mspass/utility/MsPASSError.h"
5#include <boost/archive/basic_archive.hpp>
6#include <boost/archive/text_iarchive.hpp>
7#include <boost/archive/text_oarchive.hpp>
8#include <boost/serialization/list.hpp>
9#include <boost/serialization/serialization.hpp>
10#include <list>
11#include <unistd.h>
12namespace mspass {
13namespace utility {
14class LogData {
15public:
16 int job_id;
17 int p_id; // output of getpid()
18 std::string algorithm;
19 mspass::utility::ErrorSeverity badness;
20 std::string message;
21 LogData() {};
28 LogData(const int jid, const std::string alg,
37 LogData(const int jid, const std::string alg, const std::string msg,
38 const mspass::utility::ErrorSeverity lvl);
39 friend std::ostream &operator<<(std::ostream &, LogData &);
40
41private:
42 friend boost::serialization::access;
43 template <class Archive>
44 void serialize(Archive &ar, const unsigned int version) {
45 ar & job_id;
46 ar & p_id;
47 ar & algorithm;
48 ar & badness;
49 ar & message;
50 };
51};
61public:
62 ErrorLogger() { job_id = 0; };
63 ErrorLogger(int job) { job_id = job; };
64 ErrorLogger(const ErrorLogger &parent);
65 void set_job_id(int jid) { job_id = jid; };
66 int get_job_id() { return job_id; };
88 int log_error(const std::string alg, const std::string mess,
89 const mspass::utility::ErrorSeverity level);
90
98 int log_verbose(const std::string alg, const std::string mess);
99 std::list<LogData> get_error_log() const { return allmessages; };
100 int size() const { return allmessages.size(); };
102 void clear() { allmessages.clear(); };
103 ErrorLogger &operator=(const ErrorLogger &parent);
106 ErrorLogger &operator+=(const ErrorLogger &parent);
108 std::list<LogData> worst_errors() const;
109
110private:
111 int job_id;
112 std::list<LogData> allmessages;
113 friend boost::serialization::access;
114 template <class Archive>
115 void serialize(Archive &ar, const unsigned int version) {
116 ar & job_id;
117 ar & allmessages;
118 };
119};
120
133template <typename Tdata> bool data_are_valid(const Tdata &d) {
134 if (d.dead())
135 return false;
136 std::list<LogData> welog;
137 welog = d.elog.worst_errors();
138 /*The return will be empty if there are no errors logged*/
139 if (welog.size() <= 0)
140 return true;
141 LogData ld;
142 /* Worst errors can return a list of multiple entries. For
143 fatal or invalid id should never be more than one, but this is
144 a clean way to extract the first member of the list if it isn't empty*/
145 ld = *(welog.begin());
146 if (ld.badness == ErrorSeverity::Fatal ||
147 ld.badness == ErrorSeverity::Invalid)
148 return false;
149 else
150 return true;
151}
152} // namespace utility
153} // namespace mspass
154#endif
Container to hold error logs for a data object.
Definition ErrorLogger.h:60
ErrorLogger & operator+=(const ErrorLogger &parent)
Definition ErrorLogger.cc:63
int log_verbose(const std::string alg, const std::string mess)
Log a verbose message marking it informational.
Definition ErrorLogger.cc:84
std::list< LogData > worst_errors() const
Definition ErrorLogger.cc:96
int log_error(const mspass::utility::MsPASSError &merr)
Definition ErrorLogger.cc:72
void clear()
Definition ErrorLogger.h:102
Definition ErrorLogger.h:14
Base class for error object thrown by MsPASS library routines.
Definition MsPASSError.h:38