OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
Base.hpp
Go to the documentation of this file.
1 
2 #ifndef FOCS_LOG_BASE
3 #define FOCS_LOG_BASE
4 
5 #include <limits>
6 #include <memory>
7 #include <string>
8 
9 namespace focs {
10 
45 enum class LogSeverity : int {
46  debug = 7,
47  info = 6,
48  notice = 5,
49  warning = 4,
50  error = 3,
51  critical = 2,
52  alert = 1,
53  emergency = 0,
54 
55  warn = warning,
56  err = error,
57  crit = critical,
58  emerg = emergency,
59 
62 };
68 class LogFacility {
69  public:
71  virtual ~LogFacility(){}
72 
79  virtual void log(int severity, const std::string& s) = 0;
88  virtual void log(LogSeverity severity, const std::string& s){ this->log(static_cast<int>(severity), s); }
89 };
97 class LogTarget {
99  public:
100  LogTarget(int min_severity, int max_severity, std::unique_ptr<LogFacility> f) : min_severity_{min_severity}, max_severity_{max_severity}, log_facility_{std::move(f)} {}
101  LogTarget(int min_severity, std::unique_ptr<LogFacility> f) : min_severity_{min_severity}, log_facility_{std::move(f)}{}
102  LogTarget(std::unique_ptr<LogFacility> f) : log_facility_{std::move(f)}{}
103 
104  // move
105  LogTarget(LogTarget&& other){
106  swap(std::move(other));
107  }
108  LogTarget& operator=(LogTarget&& other){
109  swap(std::move(other));
110  return *this;
111  }
112 
113  // no copying
114  LogTarget(const LogTarget&) = delete;
115  LogTarget& operator=(const LogTarget&) = delete;
116 
117  int min_severity(){ return min_severity_; }
118  int max_severity(){ return max_severity_; }
119  LogFacility& log_facility(){ return *log_facility_; }
120 
121  private:
122  int min_severity_{static_cast<int>(LogSeverity::info)};
123  int max_severity_{static_cast<int>(LogSeverity::max)};
124  std::unique_ptr<LogFacility> log_facility_;
125 
126  void swap(LogTarget&& other){
127  auto min = min_severity_;
128  auto max = max_severity_;
129  auto log = std::move(log_facility_);
130  min_severity_ = other.min_severity_;
131  max_severity_ = other.max_severity_;
132  log_facility_ = std::move(other.log_facility_);
133  other.min_severity_ = min;
134  other.max_severity_ = max;
135  other.log_facility_ = std::move(log);
136  }
137 };
139 } // namespace focs
140 
141 #endif // FOCS_LOG_BASE
142 
@ emergency
emergency severity
Simple class containing a log facility and the severity ranges it should receive.
@ debug
debug severity
@ err
error severity (alias for error)
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
virtual ~LogFacility()
Empty, virtual destructor.
Definition: Base.hpp:71
@ crit
critical severity (alias for critical)
@ min
minimum severity possible
@ string
double precision function f(R1)
Definition: tmd.lp.f:1454
virtual void log(LogSeverity severity, const std::string &s)
Wrapper for the above function, converting the LogSeverity enum to its underlying numeric severity....
Definition: Base.hpp:88
@ warning
warning severity
@ critical
critical severity
#define max(A, B)
Definition: main_biosmap.c:61
@ emerg
emergency severity (alias for emergency)
@ max
maximum severity possible
#define min(A, B)
Definition: main_biosmap.c:62
@ info
info severity
Base class to create new loggers.
Definition: Base.hpp:68
@ alert
alert severity
@ notice
notice severity
data_t s[NROOTS]
Definition: decode_rs.h:75
virtual void log(int severity, const std::string &s)=0
Print a message to this log facility, with a given severity.
@ warn
warning severity (alias for warning)
@ error
error severity
l2prod max
LogSeverity
Log severities, for use with focs::Log.
Definition: Base.hpp:45