Reference documentation for deal.II version GIT relicensing-214-g6e74dec06b 2024-03-27 18:10: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: LGPL-2.1-or-later
4// Copyright (C) 1998 - 2023 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
241 unsigned int
242 depth_file(const unsigned int n);
243
244
248 bool
249 log_thread_id(const bool flag);
250
251
257 std::streamsize
258 precision(const std::streamsize prec);
259
260
266 std::streamsize
267 width(const std::streamsize wide);
268
269
275 std::ios::fmtflags
276 flags(const std::ios::fmtflags f);
277
278
293 LogStream &
294 operator<<(std::ostream &(*p)(std::ostream &));
295
296
302 std::size_t
304
305private:
313 std::stack<std::string> &
314 get_prefixes() const;
315
321
327 std::thread::id parent_thread;
328
334 std::ostream *std_out;
335
342 std::ostream *file;
343
350 unsigned int std_depth;
351
355 unsigned int file_depth;
356
361
366
370 void
372
377 std::ostringstream &
378 get_stream();
379
385
386 template <typename T>
387 friend LogStream &
388 operator<<(LogStream &log, const T &t);
389};
390
391
392/* ----------------------------- Inline functions and templates ----------------
393 */
394
395
403template <typename T>
404inline LogStream &
405operator<<(LogStream &log, const T &t)
406{
407 // print to the internal stringstream
408 log.get_stream() << t;
409 return log;
410}
411
412
413
417extern LogStream deallog;
418
419
420
422
423#endif
SmartPointer< LogStream, LogStream::Prefix > stream
Definition logstream.h:125
std::thread::id parent_thread
Definition logstream.h:327
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:350
friend LogStream & operator<<(LogStream &log, const T &t)
Definition logstream.h:405
unsigned int file_depth
Definition logstream.h:355
std::size_t memory_consumption() const
std::ostream * std_out
Definition logstream.h:334
void push(const std::string &text)
Definition logstream.cc:302
bool print_thread_id
Definition logstream.h:360
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition logstream.h:384
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:365
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:342
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition logstream.h:320
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
LogStream & operator<<(LogStream &log, const T &t)
Definition logstream.h:405
LogStream deallog
Definition logstream.cc:36