30 "The stream configuration string \"" << config <<
"\" has syntax errors.",
31 ((std::string)config) )
38 const char SEPARATOR =
',';
40 const char *
const DefaultOutputStreams[] =
55 std::string env_name(
"DUNEDAQ_ERS_" );
57 const char * env = ::getenv( env_name.c_str() );
58 return env ? env : DefaultOutputStreams[severity];
62 parse_stream_definition(
const std::string & text,
63 std::vector<std::string> & result )
65 std::string::size_type start_p = 0, end_p = 0;
66 short brackets_open = 0;
67 while ( end_p < text.length() )
69 switch ( text[end_p] )
80 result.push_back( text.substr( start_p, end_p - start_p ) );
91 throw ers::BadConfiguration(
ERS_HERE, text );
93 if ( start_p != end_p )
95 result.push_back( text.substr( start_p, end_p - start_p ) );
115 std::scoped_lock lock(
m_mutex );
124 std::cout << issue << std::endl;
126 std::cerr << issue << std::endl;
167 m_init_streams[ss] = std::make_shared<StreamInitializer>( *
this );
181 if ( head && !head->isNull() )
198 const std::string & filter,
201 InputStream * in = ers::StreamFactory::instance().create_in_stream( stream, filter );
204 std::scoped_lock lock(
m_mutex );
205 m_in_streams.push_back( std::shared_ptr<InputStream>( in ) );
210 const std::initializer_list<std::string> & params,
213 InputStream * in = ers::StreamFactory::instance().create_in_stream( stream, params );
216 std::scoped_lock lock(
m_mutex );
217 m_in_streams.push_back( std::shared_ptr<InputStream>( in ) );
223 std::scoped_lock lock(
m_mutex );
224 for( std::list<std::shared_ptr<InputStream> >::iterator it =
m_in_streams.begin();
227 if ( (*it) -> m_receiver == receiver )
237 std::string config = get_stream_description(
severity );
238 std::vector<std::string> streams;
241 parse_stream_definition( config, streams );
243 catch ( ers::BadConfiguration & ex )
246 "Default configuration will be used." );
253 std::vector<std::string> default_streams;
256 parse_stream_definition( DefaultOutputStreams[
severity], default_streams );
259 catch ( ers::BadConfiguration & ex )
262 <<
"\" stream because of the following issue {" << ex <<
"}" );
273 for ( ; cnt < streams.size(); ++cnt )
275 main = ers::StreamFactory::instance().create_out_stream( streams[cnt] );
286 for ( ++cnt; cnt < streams.size(); ++cnt )
288 ers::OutputStream * chained = ers::StreamFactory::instance().create_out_stream( streams[cnt] );
378 << get_stream_description( (
ers::severity)ss ) <<
"\"" << std::endl;
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
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
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)
#define ERS_INTERNAL_ERROR(message)
int main(int argc, char **argv)
std::string to_string(severity s)
std::ostream & operator<<(std::ostream &, const ers::Configuration &)