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::Token > m_tokens

Static Private Attributes

static Fields s_supported_fields

Additional Inherited Members

Protected Member Functions inherited from ers::OutputStream
 OutputStream ()
OutputStream & chained ()
virtual bool isNull () const

Detailed Description

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

Definition at line 51 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 77 of file FormattedStandardStream.hxx.

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

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

◆ get_format()

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

Definition at line 66 of file FormattedStandardStream.hxx.

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

◆ report()

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

Definition at line 97 of file FormattedStandardStream.hxx.

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

177{
179 chained().write(issue);
180}
OutputStream & chained()

Member Data Documentation

◆ m_tokens

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

Definition at line 82 of file FormattedStandardStream.hpp.

◆ s_supported_fields

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

Definition at line 81 of file FormattedStandardStream.hpp.


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