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 76 of file FormattedStandardStream.hxx.

78{
80
81 size_t offset = 0;
82 size_t index = std::string::npos;
83 do {
84 index = format.find( DELIMITER, offset );
87 if ( it != s_supported_fields.end() )
88 m_tokens.push_back( it->second );
89
90 offset += token.size() + 1;
91 } while ( index != std::string::npos );
92}
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 53 of file FormattedStandardStream.hxx.

54{
55 std::string first_token = param.substr( 0, param.find( ',' ) );
57 if ( it != s_supported_fields.end() )
58 return "";
59 else
60 return first_token;
61}

◆ get_format()

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

Definition at line 65 of file FormattedStandardStream.hxx.

66{
67 std::string first_token = param.substr( 0, param.find( ',' ) );
69 if ( it != s_supported_fields.end() )
70 return param;
71 else
72 return param.substr( first_token.size() < param.size() ? first_token.size() + 1 : param.size() );
73}

◆ report()

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

Definition at line 96 of file FormattedStandardStream.hxx.

97{
98 for ( size_t i = 0; i < m_tokens.size(); i++ )
99 {
100 switch ( m_tokens[i] )
101 {
102 case format::Severity:
103 out << ers::to_string( issue.severity() );
104 break;
105 case format::Time:
106 out << issue.time<std::chrono::microseconds>() << " ";
107 break;
108 case format::Position:
109 out << "[" << issue.context().position( ) << "]";
110 break;
111 case format::Function:
112 out << issue.context().function_name();
113 break;
114 case format::Line:
115 out << issue.context().line_number();
116 break;
117 case format::Text:
118 out << issue.message();
119 break;
121 {
122 out << FIELD_SEPARATOR << "Parameters = ";
123 for ( ers::string_map::const_iterator it = issue.parameters().begin(); it != issue.parameters().end(); ++it )
124 {
125 out << "'" << it->first << "=" << it->second << "' ";
126 }
127 }
128 break;
130 {
131 out << FIELD_SEPARATOR << "Qualifiers = ";
132 for ( std::vector<std::string>::const_iterator it = issue.qualifiers().begin(); it != issue.qualifiers().end(); ++it )
133 {
134 out << "'" << *it << "' ";
135 }
136 }
137 break;
138 case format::Context:
139 out << FIELD_SEPARATOR << "host = " << issue.context().host_name()
140 << FIELD_SEPARATOR << "user = " << issue.context().user_name()
141 << " (" << issue.context().user_id() << ")"
142 << FIELD_SEPARATOR << "process id = " << issue.context().process_id()
143 << FIELD_SEPARATOR << "thread id = " << issue.context().thread_id()
144 << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
145 break;
146 case format::Host:
147 out << FIELD_SEPARATOR << "host = " << issue.context().host_name();
148 break;
149 case format::User:
150 out << FIELD_SEPARATOR << "user = " << issue.context().user_name()
151 << " (" << issue.context().user_id() << ")";
152 break;
153 case format::PID:
154 out << FIELD_SEPARATOR << "process id = " << issue.context().process_id();
155 break;
156 case format::TID:
157 out << FIELD_SEPARATOR << "thread id = " << issue.context().thread_id();
158 break;
159 case format::CWD:
160 out << FIELD_SEPARATOR << "process wd = " << issue.context().cwd();
161 break;
162 case format::Stack:
163 {
164 std::vector<std::string> stack = issue.context().stack();
165 for( size_t i = 0; i < stack.size(); i++ )
166 {
167 out << FIELD_SEPARATOR << "#" << std::setw(3) << std::left << i << stack[i];
168 }
169 }
170 break;
171 case format::Cause:
172 if ( issue.cause() )
173 {
174 out << FIELD_SEPARATOR << "was caused by: ";
175 report( out, *issue.cause() );
176 }
177 break;
178 default:
179 break;
180 }
181 out << " ";
182 }
183 out << std::endl;
184}
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 188 of file FormattedStandardStream.hxx.

189{
190 report( device().stream(), issue );
191 chained().write( issue );
192}
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: