DUNE PDELab (git)

logtag.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_COMMON_LOGTAG_HH
5#define DUNE_PDELAB_COMMON_LOGTAG_HH
6
7#include <memory>
8#include <ostream>
9#include <sstream>
10#include <string>
11
12namespace Dune {
13 namespace PDELab {
14
16
29 extern std::ostream &logtag(std::ostream &s);
30
33 extern std::ostream &hostPidWallUserLogtagFormatFunc(std::ostream &s);
34
37
42 extern std::ostream &hostRankWallUserLogtagFormatFunc(std::ostream &s);
43
45 extern std::ostream &nullFormatFunc(std::ostream &s);
46
48
58 extern void logtagSetupMPI(bool syncWidthes = true);
59
61
66
71 virtual void writeTag(std::ostream &s) const = 0;
72
73 virtual ~LogtagFormatterBase() = default;
74
75 };
76
78 template<class FormatFunc>
81 {
82 FormatFunc formatFunc;
83
84 public:
86
90 GeneralLogtagFormatter(const FormatFunc &formatFunc_) :
91 formatFunc(formatFunc_)
92 { }
94
97 virtual void writeTag(std::ostream &s) const override { formatFunc(s); }
98 };
100 template<class FormatFunc>
101 std::shared_ptr<LogtagFormatterBase>
102 makeGeneralLogtagFormatter(const FormatFunc &formatFunc)
103 { return std::make_shared<GeneralLogtagFormatter<FormatFunc> >(formatFunc); }
105 extern std::shared_ptr<LogtagFormatterBase>
106 makeGeneralLogtagFormatter(std::ostream &(&formatFunc)(std::ostream&));
107
109 extern const std::shared_ptr<LogtagFormatterBase> &getLogtagFormatter();
111
115 extern void
116 setLogtagFormatter(const std::shared_ptr<LogtagFormatterBase> &formatter
117 = std::shared_ptr<LogtagFormatterBase>());
119
123 template<class FormatFunc>
124 void setLogtagFormatFunc(const FormatFunc &formatFunc)
125 { setLogtagFormatter(makeGeneralLogtagFormatter(formatFunc)); }
126
128
134 std::shared_ptr<LogtagFormatterBase> savedFormatter;
135
136 public:
137 template<class FormatFunc>
138 WithLogtag(const FormatFunc &formatFunc) :
139 savedFormatter(getLogtagFormatter())
140 { setLogtagFormatFunc(formatFunc); }
141
142 ~WithLogtag();
143 };
144
146
172 class LocalTag {
173 std::string str_;
174
175 public:
177 inline const std::string &str() const { return str_; }
178
180 template<class V>
181 LocalTag &operator<<(const V &v) {
182 std::stringstream s;
183 s << v;
184 str_ += s.str();
185 return *this;
186 }
187 };
188
190 inline std::ostream &operator<<(std::ostream &s, const LocalTag &tag)
191 { return s << logtag << tag.str(); }
192
193 } // namespace PDELab
194} // namespace Dune
195
196#endif // DUNE_PDELAB_COMMON_LOGTAG_HH
A log tag formatter that wraps a unary formatting function or functor.
Definition: logtag.hh:81
virtual void writeTag(std::ostream &s) const override
write the tag to the stream
Definition: logtag.hh:97
GeneralLogtagFormatter(const FormatFunc &formatFunc_)
constructor
Definition: logtag.hh:90
Insert standard boilerplate into log messages.
Definition: logtag.hh:172
const std::string & str() const
extract the static boilerplate message
Definition: logtag.hh:177
LocalTag & operator<<(const V &v)
append something to the static boilerplate message
Definition: logtag.hh:181
temporarily use a different log tag format function
Definition: logtag.hh:133
Dune namespace.
Definition: alignedallocator.hh:13
virtual base class for logger formatters
Definition: logtag.hh:64
virtual void writeTag(std::ostream &s) const =0
function that writes the tag to a stream
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)