36using std::chrono::system_clock;
55 return new T(context);
68 class Issue :
public std::exception
74 const std::string & message = std::string() );
77 const std::exception &
cause );
80 const std::string & message,
81 const std::exception &
cause );
115 template <
class Precision=std::chrono::seconds>
116 std::string
time(
const std::string & format =
"%Y-%b-%d %H:%M:%S",
bool isUTC =
false)
const;
119 template <
class Precision>
120 std::string
localtime(
const std::string & format =
"%Y-%b-%d %H:%M:%S")
const
124 template <
class Precision>
125 std::string
gmtime(
const std::string & format =
"%Y-%b-%d %H:%M:%S")
const
128 std::time_t
time_t()
const;
130 const system_clock::time_point &
ptime() const
133 const char *
what() const noexcept
138 void wrap_message(
const std::string & begin,
const std::string & end );
142 const system_clock::time_point & time,
144 const std::string & message,
146 const std::map<std::string, std::string> &
parameters,
150 template <
typename T>
151 void get_value(
const std::string & key, T & value )
const;
152 void get_value(
const std::string & key,
const char * & value )
const;
153 void get_value(
const std::string & key, std::string & value )
const;
156 template <
typename T>
166 chain.push_back(
"ers::Issue" ) ;
191 "value for the \"" << key <<
"\" key is not set ",
192 ((std::string)key ) )
198 string_map::const_iterator it =
m_values.find(key);
201 throw ers::NoValue(
ERS_HERE, key );
203 std::istringstream in( it->second );
211 std::ostringstream
out;
216template <
class Precision>
220 static const int width(::log10(Precision::period::den));
223 std::tm tm = isUTC ? *gmtime_r(&t, &tm) : *localtime_r(&t, &tm);
226 std::strftime(buff, 128 - 16, format.c_str(), &tm);
228 auto c = std::chrono::duration_cast<Precision>(
229 m_time.time_since_epoch()).count();
230 double frac = c - (double)t*Precision::period::den;
231 sprintf(buff + strlen(buff),
",%0*.0f", width, frac);
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
An abstract interface to access an Issue context.
Implements factory pattern for user defined Issues.
static IssueFactory & instance()
method to access singleton
void register_issue(const std::string &name, IssueCreator creator)
register an issue factory
static ers::Issue * create(const Context &context)
Base class for any user define issue.
const Context & context() const
Context of the issue.
ers::Severity severity() const
severity of the issue
Severity m_severity
Issue's severity.
void wrap_message(const std::string &begin, const std::string &end)
std::unique_ptr< Context > m_context
Context of the current issue.
virtual ~Issue() noexcept
Issue & operator=(const Issue &other)=delete
void prepend_message(const std::string &message)
system_clock::time_point m_time
Time when issue was thrown.
virtual const char * get_class_name() const =0
Get key for class (used for serialisation)
const system_clock::time_point & ptime() const
original time point of the issue
void set_message(const std::string &message)
void get_value(const std::string &key, T &value) const
const std::vector< std::string > & qualifiers() const
return array of qualifiers
const std::string & message() const
General cause of the issue.
std::string gmtime(const std::string &format="%Y-%b-%d %H:%M:%S") const
const string_map & parameters() const
return array of parameters
std::string time(const std::string &format="%Y-%b-%d %H:%M:%S", bool isUTC=false) const
string representation of local time of the issue
std::string localtime(const std::string &format="%Y-%b-%d %H:%M:%S") const
string representation of UTC time of the issue
virtual Issue * clone() const =0
virtual void raise() const =0
throws a copy of this issue preserving the real issue type
std::unique_ptr< const Issue > m_cause
Issue that caused the current issue.
void set_value(const std::string &key, T value)
string_map m_values
List of user defined attributes.
std::string m_message
Issue's explanation text.
void add_qualifier(const std::string &qualif)
adds a qualifier to the issue
virtual inheritance_type get_class_inheritance() const =0
Get inheritance chain.
const char * what() const noexcept
General cause of the issue.
ers::Severity set_severity(ers::Severity severity) const
std::time_t time_t() const
seconds since 1 Jan 1970
std::vector< std::string > m_qualifiers
List of associated qualifiers.
Issue(const Context &context, const std::string &message=std::string())
static auto _get_inheritance()
const Issue * cause() const
return the cause Issue of this Issue
FELIX Initialization std::string initerror FELIX queue timed out
std::list< std::string > inheritance_type
std::map< std::string, std::string > string_map
std::ostream & operator<<(std::ostream &, const ers::Configuration &)