41 "The stream configuration string \"" << config <<
"\" has syntax errors.",
42 ((std::string)config))
48const char SEPARATOR =
',';
50const char*
const DefaultOutputStreams[] = {
64 std::string env_name(
"DUNEDAQ_ERS_");
66 const char* env = ::getenv(env_name.c_str());
67 return env ? env : DefaultOutputStreams[severity];
71parse_stream_definition(
const std::string& text, std::vector<std::string>& result)
73 std::string::size_type start_p = 0, end_p = 0;
74 short brackets_open = 0;
75 while (end_p < text.length()) {
76 switch (text[end_p]) {
85 result.push_back(text.substr(start_p, end_p - start_p));
95 throw ers::BadConfiguration(
ERS_HERE, text);
97 if (start_p != end_p) {
98 result.push_back(text.substr(start_p, end_p - start_p));
119 std::scoped_lock lock(
m_mutex);
127 std::cout << issue << std::endl;
129 std::cerr << issue << std::endl;
184 if (head && !head->isNull()) {
198 InputStream* in = ers::StreamFactory::instance().create_in_stream(stream, filter);
201 std::scoped_lock lock(
m_mutex);
202 m_in_streams.push_back(std::shared_ptr<InputStream>(in));
207 const std::initializer_list<std::string>& params,
210 InputStream* in = ers::StreamFactory::instance().create_in_stream(stream, params);
213 std::scoped_lock lock(
m_mutex);
214 m_in_streams.push_back(std::shared_ptr<InputStream>(in));
220 std::scoped_lock lock(
m_mutex);
222 if ((*it)->m_receiver == receiver)
232 std::string config = get_stream_description(
severity);
233 std::vector<std::string> streams;
235 parse_stream_definition(config, streams);
236 }
catch (ers::BadConfiguration& ex) {
238 <<
"\" stream is invalid. "
239 "Default configuration will be used.");
245 std::vector<std::string> default_streams;
247 parse_stream_definition(DefaultOutputStreams[
severity], default_streams);
249 }
catch (ers::BadConfiguration& ex) {
262 for (; cnt < streams.size(); ++cnt) {
263 main = ers::StreamFactory::instance().create_out_stream(streams[cnt]);
273 for (++cnt; cnt < streams.size(); ++cnt) {
274 ers::OutputStream* chained = ers::StreamFactory::instance().create_out_stream(streams[cnt]);
static Configuration & instance()
return the singleton
ERS Issue receiver interface.
Base class for any user define issue.
ers::Severity severity() const
severity of the issue
ers::Severity set_severity(ers::Severity severity) const
ERS abstract output stream interface.
virtual bool isNull() const
friend class StreamManager
void write(const Issue &issue)
std::recursive_mutex m_mutex
StreamManager & m_manager
StreamInitializer(StreamManager &manager)
This class manages and provides access to ERS streams.
void add_output_stream(ers::severity severity, ers::OutputStream *new_stream)
void error(const Issue &issue)
sends an issue to the error stream
std::shared_ptr< OutputStream > m_init_streams[ers::Fatal+1]
array of pointers to streams per severity
OutputStream * setup_stream(ers::severity severity)
void warning(const Issue &issue)
sends an issue to the warning stream
static StreamManager & instance()
return the singleton
std::list< std::shared_ptr< InputStream > > m_in_streams
void report_issue(ers::severity type, const Issue &issue)
void log(const Issue &issue)
sends an issue to the log stream
void fatal(const Issue &issue)
sends an issue to the fatal stream
void add_receiver(const std::string &stream, const std::string &filter, ers::IssueReceiver *receiver)
void debug(const Issue &issue, int level)
sends an Issue to the debug stream
void information(const Issue &issue)
sends an issue to the information stream
std::shared_ptr< OutputStream > m_out_streams[ers::Fatal+1]
array of pointers to streams per severity
void remove_receiver(ers::IssueReceiver *receiver)
int main(int argc, char *argv[])
#define ERS_INTERNAL_ERROR(message)
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message_, attributes)
std::string to_string(severity s)
std::ostream & operator<<(std::ostream &, const ers::Configuration &)