deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
logstream.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1998 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_logstream_h
14#define dealii_logstream_h
15
16#include <deal.II/base/config.h>
17
22
23#include <cmath>
24#include <memory>
25#include <sstream>
26#include <stack>
27#include <string>
28
29
31
79{
80public:
98 class Prefix
99 {
100 public:
105 Prefix(const std::string &text);
106
111 Prefix(const std::string &text, LogStream &stream);
112
116 ~Prefix();
117
118 private:
124 };
125
126
132 LogStream();
133
134
138 ~LogStream() override;
139
140
151 void
152 attach(std::ostream &o,
153 const bool print_job_id = true,
154 const std::ios_base::fmtflags flags = std::ios::showpoint |
155 std::ios::left);
156
157
162 void
163 detach();
164
165
169 std::ostream &
170 get_console();
171
172
176 std::ostream &
178
179
184 bool
185 has_file() const;
186
187
191 const std::string &
192 get_prefix() const;
193
194
207 void
208 push(const std::string &text);
209
210
214 void
215 pop();
216
217
228 unsigned int
229 depth_console(const unsigned int n);
230
231
240 unsigned int
241 depth_file(const unsigned int n);
242
243
247 bool
248 log_thread_id(const bool flag);
249
250
256 std::streamsize
257 precision(const std::streamsize prec);
258
259
265 std::streamsize
266 width(const std::streamsize wide);
267
268
274 std::ios::fmtflags
275 flags(const std::ios::fmtflags f);
276
277
292 LogStream &
293 operator<<(std::ostream &(*p)(std::ostream &));
294
295
301 std::size_t
303
304private:
312 std::stack<std::string> &
313 get_prefixes() const;
314
320
326 std::thread::id parent_thread;
327
333 std::ostream *std_out;
334
341 std::ostream *file;
342
349 unsigned int std_depth;
350
354 unsigned int file_depth;
355
360
365
369 void
371
376 std::ostringstream &
377 get_stream();
378
384
385 template <typename T>
386 friend LogStream &
387 operator<<(LogStream &log, const T &t);
388};
389
390
391/* ----------------------------- Inline functions and templates ----------------
392 */
393
394
402template <typename T>
403inline LogStream &
404operator<<(LogStream &log, const T &t)
405{
406 // print to the internal stringstream
407 log.get_stream() << t;
408 return log;
409}
410
411
412
454extern LogStream deallog;
455
456
457
459
460#endif
ObserverPointer< LogStream, LogStream::Prefix > stream
Definition logstream.h:123
std::thread::id parent_thread
Definition logstream.h:326
std::streamsize width(const std::streamsize wide)
Definition logstream.cc:341
std::ostream & get_console()
Definition logstream.cc:239
unsigned int std_depth
Definition logstream.h:349
friend LogStream & operator<<(LogStream &log, const T &t)
Definition logstream.h:404
unsigned int file_depth
Definition logstream.h:354
std::size_t memory_consumption() const
std::ostream * std_out
Definition logstream.h:333
void push(const std::string &text)
Definition logstream.cc:302
bool print_thread_id
Definition logstream.h:359
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition logstream.h:383
std::ios::fmtflags flags(const std::ios::fmtflags f)
Definition logstream.cc:325
void attach(std::ostream &o, const bool print_job_id=true, const std::ios_base::fmtflags flags=std::ios::showpoint|std::ios::left)
Definition logstream.cc:218
bool at_newline
Definition logstream.h:364
std::streamsize precision(const std::streamsize prec)
Definition logstream.cc:333
std::ostream & get_file_stream()
Definition logstream.cc:270
unsigned int depth_console(const unsigned int n)
Definition logstream.cc:349
std::ostringstream & get_stream()
Definition logstream.cc:247
bool has_file() const
Definition logstream.cc:281
unsigned int depth_file(const unsigned int n)
Definition logstream.cc:360
bool log_thread_id(const bool flag)
Definition logstream.cc:371
std::ostream * file
Definition logstream.h:341
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition logstream.h:319
void print_line_head()
Definition logstream.cc:402
std::stack< std::string > & get_prefixes() const
Definition logstream.cc:382
const std::string & get_prefix() const
Definition logstream.cc:289
void detach()
Definition logstream.cc:231
void pop()
Definition logstream.cc:316
~LogStream() override
Definition logstream.cc:88
A class that provides a separate storage location on each thread that accesses the object.
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
LogStream & operator<<(LogStream &log, const T &t)
Definition logstream.h:404
LogStream deallog
Definition logstream.cc:36