Reference documentation for deal.II version GIT relicensing-1304-g0b6601e2da 2024-07-24 19:10:02+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: 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// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_logstream_h
16#define dealii_logstream_h
17
18#include <deal.II/base/config.h>
19
24
25#include <cmath>
26#include <memory>
27#include <sstream>
28#include <stack>
29#include <string>
30
31
33
80class LogStream : public Subscriptor
81{
82public:
100 class Prefix
101 {
102 public:
107 Prefix(const std::string &text);
108
113 Prefix(const std::string &text, LogStream &stream);
114
118 ~Prefix();
119
120 private:
126 };
127
128
134 LogStream();
135
136
140 ~LogStream() override;
141
142
153 void
154 attach(std::ostream &o,
155 const bool print_job_id = true,
156 const std::ios_base::fmtflags flags = std::ios::showpoint |
157 std::ios::left);
158
159
164 void
165 detach();
166
167
171 std::ostream &
172 get_console();
173
174
178 std::ostream &
180
181
186 bool
187 has_file() const;
188
189
193 const std::string &
194 get_prefix() const;
195
196
209 void
210 push(const std::string &text);
211
212
216 void
217 pop();
218
219
230 unsigned int
231 depth_console(const unsigned int n);
232
233
242 unsigned int
243 depth_file(const unsigned int n);
244
245
249 bool
250 log_thread_id(const bool flag);
251
252
258 std::streamsize
259 precision(const std::streamsize prec);
260
261
267 std::streamsize
268 width(const std::streamsize wide);
269
270
276 std::ios::fmtflags
277 flags(const std::ios::fmtflags f);
278
279
294 LogStream &
295 operator<<(std::ostream &(*p)(std::ostream &));
296
297
303 std::size_t
305
306private:
314 std::stack<std::string> &
315 get_prefixes() const;
316
322
328 std::thread::id parent_thread;
329
335 std::ostream *std_out;
336
343 std::ostream *file;
344
351 unsigned int std_depth;
352
356 unsigned int file_depth;
357
362
367
371 void
373
378 std::ostringstream &
379 get_stream();
380
386
387 template <typename T>
388 friend LogStream &
389 operator<<(LogStream &log, const T &t);
390};
391
392
393/* ----------------------------- Inline functions and templates ----------------
394 */
395
396
404template <typename T>
405inline LogStream &
406operator<<(LogStream &log, const T &t)
407{
408 // print to the internal stringstream
409 log.get_stream() << t;
410 return log;
411}
412
413
414
456extern LogStream deallog;
457
458
459
461
462#endif
SmartPointer< LogStream, LogStream::Prefix > stream
Definition logstream.h:125
std::thread::id parent_thread
Definition logstream.h:328
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:351
friend LogStream & operator<<(LogStream &log, const T &t)
Definition logstream.h:406
unsigned int file_depth
Definition logstream.h:356
std::size_t memory_consumption() const
std::ostream * std_out
Definition logstream.h:335
void push(const std::string &text)
Definition logstream.cc:302
bool print_thread_id
Definition logstream.h:361
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition logstream.h:385
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:366
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:343
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition logstream.h:321
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:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
LogStream & operator<<(LogStream &log, const T &t)
Definition logstream.h:406
LogStream deallog
Definition logstream.cc:36