DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ers::FormattedStandardStream< Device > Struct Template Reference

#include <FormattedStandardStream.hpp>

Inheritance diagram for ers::FormattedStandardStream< Device >:
[legend]
Collaboration diagram for ers::FormattedStandardStream< Device >:
[legend]

Classes

struct  Fields
 

Public Member Functions

 FormattedStandardStream ()=default
 
 FormattedStandardStream (const std::string &format)
 
void write (const Issue &issue) override
 
- Public Member Functions inherited from ers::OutputStream
virtual ~OutputStream ()
 Sends the issue into this stream.
 

Private Member Functions

void report (std::ostream &out, const Issue &issue)
 

Static Private Member Functions

static std::string get_file_name (const std::string &param)
 
static std::string get_format (const std::string &param)
 

Private Attributes

std::vector< format::Tokenm_tokens
 

Static Private Attributes

static Fields s_supported_fields
 

Additional Inherited Members

- Protected Member Functions inherited from ers::OutputStream
 OutputStream ()
 
OutputStreamchained ()
 
virtual bool isNull () const
 

Detailed Description

template<class Device>
struct ers::FormattedStandardStream< Device >

Definition at line 36 of file FormattedStandardStream.hpp.

Constructor & Destructor Documentation

◆ FormattedStandardStream() [1/2]

template<class Device >
ers::FormattedStandardStream< Device >::FormattedStandardStream ( )
default

◆ FormattedStandardStream() [2/2]

template<class Device >
ers::FormattedStandardStream< Device >::FormattedStandardStream ( const std::string & format)
explicit

This constructor creates a new formatted output stream. The format parameter is a comma separated list of tokens that defines the which attributes of the issues will be printed as well as their order. Here is the list of supported tokens: "severity, time, position, context, pid, tid, cwd, function, line, cause, stack, parameters, qualifiers, user"

Parameters
formata list of issue attributes that have to be printed for each issue

Definition at line 65 of file FormattedStandardStream.hxx.

66 : Device( get_file_name( param ) )
67{
68 std::string format = get_format( param );
69
70 size_t offset = 0;
71 size_t index = std::string::npos;
72 do {
73 index = format.find( DELIMITER, offset );
74 std::string token = format.substr( offset, index - offset );
75 std::map<std::string,ers::format::Token>::iterator it = s_supported_fields.find( token );
76 if ( it != s_supported_fields.end() )
77 m_tokens.push_back( it->second );
78
79 offset += token.size() + 1;
80 } while ( index != std::string::npos );
81}
#define DELIMITER
double offset
std::vector< format::Token > m_tokens
static std::string get_file_name(const std::string &param)
static std::string get_format(const std::string &param)

Member Function Documentation

◆ get_file_name()

template<class Device >
std::string ers::FormattedStandardStream< Device >::get_file_name ( const std::string & param)
staticprivate

Definition at line 42 of file FormattedStandardStream.hxx.

43{
44 std::string first_token = param.substr( 0, param.find( ',' ) );
45 std::map<std::string,ers::format::Token>::iterator it = s_supported_fields.find( first_token );
46 if ( it != s_supported_fields.end() )
47 return "";
48 else
49 return first_token;
50}

◆ get_format()

template<class Device >
std::string ers::FormattedStandardStream< Device >::get_format ( const std::string & param)
staticprivate

Definition at line 54 of file FormattedStandardStream.hxx.

55{
56 std::string first_token = param.substr( 0, param.find( ',' ) );
57 std::map<std::string,ers::format::Token>::iterator it = s_supported_fields.find( first_token );
58 if ( it != s_supported_fields.end() )
59 return param;
60 else
61 return param.substr( first_token.size() < param.size() ? first_token.size() + 1 : param.size() );
62}

◆ report()

template<class Device >
void ers::FormattedStandardStream< Device >::report ( std::ostream & out,
const Issue & issue )
private

Definition at line 85 of file FormattedStandardStream.hxx.

86{
87 for ( size_t i = 0; i < m_tokens.size(); i++ )
88 {
89 switch ( m_tokens[i] )
90 {
92 out << ers::to_string( issue.severity() );
93 break;
94 case format::Time:
95 out << issue.time<std::chrono::microseconds>() << " ";
96 break;
98 out << "[" << issue.context().position( ) << "]";
99 break;
100 case format::Function:
101 out << issue.context().function_name();
102 break;
103 case format::Line:
104 out << issue.context().line_number();
105 break;
106 case format::Text:
107 out << issue.message();
108 break;
110 {
111 out << FIELD_SEPARATOR << "Parameters = ";
112 for ( ers::string_map::const_iterator it = issue.parameters().begin(); it != issue.parameters().end(); ++it )
113 {
114 out << "'" << it->first << "=" << it->second << "' ";
115 }
116 }
117 break;
119 {
120 out << FIELD_SEPARATOR << "Qualifiers = ";
121 for ( std::vector<std::string>::const_iterator it = issue.qualifiers().begin(); it != issue.qualifiers().end(); ++it )
122 {
123 out << "'" << *it << "' ";
124 }
125 }
126 break;
127 case format::Context:
128 out << FIELD_SEPARATOR << "host = " << issue.context().host_name()
129 << FIELD_SEPARATOR << "user = " << issue.context().user_name()
130 << " (" << issue.context().user_id() << ")"
131 << FIELD_SEPARATOR << "process id = " << issue.context().process_id()
132 << FIELD_SEPARATOR << "thread id = " << issue.context().thread_id()
133 << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
134 break;
135 case format::Host:
136 out << FIELD_SEPARATOR << "host = " << issue.context().host_name();
137 break;
138 case format::User:
139 out << FIELD_SEPARATOR << "user = " << issue.context().user_name()
140 << " (" << issue.context().user_id() << ")";
141 break;
142 case format::PID:
143 out << FIELD_SEPARATOR << "process id = " << issue.context().process_id();
144 break;
145 case format::TID:
146 out << FIELD_SEPARATOR << "thread id = " << issue.context().thread_id();
147 break;
148 case format::CWD:
149 out << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
150 break;
151 case format::Stack:
152 {
153 std::vector<std::string> stack = issue.context().stack();
154 for( size_t i = 0; i < stack.size(); i++ )
155 {
156 out << FIELD_SEPARATOR << "#" << std::setw(3) << std::left << i << stack[i];
157 }
158 }
159 break;
160 case format::Cause:
161 if ( issue.cause() )
162 {
163 out << FIELD_SEPARATOR << "was caused by: ";
164 report( out, *issue.cause() );
165 }
166 break;
167 default:
168 break;
169 }
170 out << " ";
171 }
172 out << std::endl;
173}
#define FIELD_SEPARATOR
FELIX Initialization std::string initerror FELIX queue timed out
std::string to_string(severity s)
void report(std::ostream &out, const Issue &issue)

◆ write()

template<class Device >
void ers::FormattedStandardStream< Device >::write ( const Issue & issue)
overridevirtual

Implements ers::OutputStream.

Definition at line 177 of file FormattedStandardStream.hxx.

178{
179 report( device().stream(), issue );
180 chained().write( issue );
181}
virtual void write(const Issue &issue)=0
OutputStream & chained()

Member Data Documentation

◆ m_tokens

template<class Device >
std::vector<format::Token> ers::FormattedStandardStream< Device >::m_tokens
private

Definition at line 64 of file FormattedStandardStream.hpp.

◆ s_supported_fields

template<class Device >
ers::FormattedStandardStream< Device >::Fields ers::FormattedStandardStream< Device >::s_supported_fields
staticprivate

Definition at line 63 of file FormattedStandardStream.hpp.


The documentation for this struct was generated from the following files: