Reference documentation for deal.II version Git 2e98021fd4 2020-10-20 17:25:20 -0400
\(\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\}}\)
logstream.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_logstream_h
17 #define dealii_logstream_h
18 
19 #include <deal.II/base/config.h>
20 
25 
26 #include <cmath>
27 #include <map>
28 #include <memory>
29 #include <sstream>
30 #include <stack>
31 #include <string>
32 
33 
35 
82 class LogStream : public Subscriptor
83 {
84 public:
102  class Prefix
103  {
104  public:
109  Prefix(const std::string &text);
110 
115  Prefix(const std::string &text, LogStream &stream);
116 
120  ~Prefix();
121 
122  private:
128  };
129 
130 
136  LogStream();
137 
138 
142  ~LogStream() override;
143 
144 
155  void
156  attach(std::ostream & o,
157  const bool print_job_id = true,
158  const std::ios_base::fmtflags flags = std::ios::showpoint |
159  std::ios::left);
160 
161 
166  void
167  detach();
168 
169 
173  std::ostream &
174  get_console();
175 
176 
180  std::ostream &
181  get_file_stream();
182 
183 
188  bool
189  has_file() const;
190 
191 
195  const std::string &
196  get_prefix() const;
197 
198 
211  void
212  push(const std::string &text);
213 
214 
218  void
219  pop();
220 
221 
232  unsigned int
233  depth_console(const unsigned int n);
234 
235 
243  unsigned int
244  depth_file(const unsigned int n);
245 
246 
250  bool
251  log_thread_id(const bool flag);
252 
253 
259  std::streamsize
260  precision(const std::streamsize prec);
261 
262 
268  std::streamsize
269  width(const std::streamsize wide);
270 
271 
277  std::ios::fmtflags
278  flags(const std::ios::fmtflags f);
279 
280 
295  LogStream &
296  operator<<(std::ostream &(*p)(std::ostream &));
297 
298 
304  std::size_t
305  memory_consumption() const;
306 
307 private:
315  std::stack<std::string> &
316  get_prefixes() const;
317 
323 
329  std::thread::id parent_thread;
330 
336  std::ostream *std_out;
337 
344  std::ostream *file;
345 
352  unsigned int std_depth;
353 
357  unsigned int file_depth;
358 
363 
368 
372  void
373  print_line_head();
374 
379  std::ostringstream &
380  get_stream();
381 
387 
388  template <typename T>
389  friend LogStream &
390  operator<<(LogStream &log, const T &t);
391 };
392 
393 
394 /* ----------------------------- Inline functions and templates ----------------
395  */
396 
397 
405 template <typename T>
406 inline LogStream &
407 operator<<(LogStream &log, const T &t)
408 {
409  // print to the internal stringstream
410  log.get_stream() << t;
411  return log;
412 }
413 
414 
415 
419 extern LogStream deallog;
420 
421 
422 
424 
425 #endif
void pop()
Definition: logstream.cc:317
std::streamsize precision(const std::streamsize prec)
Definition: logstream.cc:334
LogStream deallog
Definition: logstream.cc:37
A class that provides a separate storage location on each thread that accesses the object...
std::ostream * std_out
Definition: logstream.h:336
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition: logstream.h:322
const std::string & get_prefix() const
Definition: logstream.cc:290
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:219
bool print_thread_id
Definition: logstream.h:362
std::thread::id parent_thread
Definition: logstream.h:329
~LogStream() override
Definition: logstream.cc:89
unsigned int depth_file(const unsigned int n)
Definition: logstream.cc:361
unsigned int std_depth
Definition: logstream.h:352
std::streamsize width(const std::streamsize wide)
Definition: logstream.cc:342
bool log_thread_id(const bool flag)
Definition: logstream.cc:372
std::ostream & get_file_stream()
Definition: logstream.cc:271
std::ios::fmtflags flags(const std::ios::fmtflags f)
Definition: logstream.cc:326
bool has_file() const
Definition: logstream.cc:282
static const char T
std::stack< std::string > & get_prefixes() const
Definition: logstream.cc:383
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:369
unsigned int depth_console(const unsigned int n)
Definition: logstream.cc:350
void print_line_head()
Definition: logstream.cc:403
std::ostream * file
Definition: logstream.h:344
SmartPointer< LogStream, LogStream::Prefix > stream
Definition: logstream.h:127
Prefix(const std::string &text)
Definition: logstream.cc:41
std::ostream & get_console()
Definition: logstream.cc:240
bool at_newline
Definition: logstream.h:367
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition: logstream.h:386
void push(const std::string &text)
Definition: logstream.cc:303
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:368
LogStream & operator<<(std::ostream &(*p)(std::ostream &))
Definition: logstream.cc:126
void detach()
Definition: logstream.cc:232
std::ostringstream & get_stream()
Definition: logstream.cc:248
unsigned int file_depth
Definition: logstream.h:357
std::size_t memory_consumption() const