Reference documentation for deal.II version 9.2.0
\(\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 
83 class LogStream : public Subscriptor
84 {
85 public:
103  class Prefix
104  {
105  public:
110  Prefix(const std::string &text);
111 
116  Prefix(const std::string &text, LogStream &stream);
117 
121  ~Prefix();
122 
123  private:
129  };
130 
131 
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::ostream *std_out;
330 
337  std::ostream *file;
338 
345  unsigned int std_depth;
346 
350  unsigned int file_depth;
351 
356 
361 
365  void
366  print_line_head();
367 
372  std::ostringstream &
373  get_stream();
374 
380 
381  template <typename T>
382  friend LogStream &
383  operator<<(LogStream &log, const T &t);
384 };
385 
386 
387 /* ----------------------------- Inline functions and templates ----------------
388  */
389 
390 
398 template <typename T>
399 inline LogStream &
401 {
402  // print to the internal stringstream
403  log.get_stream() << t;
404  return log;
405 }
406 
407 
408 
414 extern LogStream deallog;
415 
416 
417 
419 
420 #endif
LogStream::get_prefixes
std::stack< std::string > & get_prefixes() const
Definition: logstream.cc:382
LogStream::at_newline
bool at_newline
Definition: logstream.h:360
LogStream::outstreams
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition: logstream.h:379
LogStream::Prefix
Definition: logstream.h:103
LogStream::print_line_head
void print_line_head()
Definition: logstream.cc:416
LogStream::file
std::ostream * file
Definition: logstream.h:337
LogStream::std_depth
unsigned int std_depth
Definition: logstream.h:345
LogStream::std_out
std::ostream * std_out
Definition: logstream.h:329
LogStream::prefixes
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition: logstream.h:322
VectorizedArray::log
VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &x)
Definition: vectorization.h:5390
thread_local_storage.h
deallog
LogStream deallog
Definition: logstream.cc:37
LogStream::log_thread_id
bool log_thread_id(const bool flag)
Definition: logstream.cc:371
LogStream::detach
void detach()
Definition: logstream.cc:231
LogStream::get_stream
std::ostringstream & get_stream()
Definition: logstream.cc:247
Subscriptor
Definition: subscriptor.h:62
LogStream::get_file_stream
std::ostream & get_file_stream()
Definition: logstream.cc:270
LogStream::Prefix::Prefix
Prefix(const std::string &text)
Definition: logstream.cc:41
LAPACKSupport::T
static const char T
Definition: lapack_support.h:163
LogStream::flags
std::ios::fmtflags flags(const std::ios::fmtflags f)
Definition: logstream.cc:325
LogStream::memory_consumption
std::size_t memory_consumption() const
subscriptor.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
LogStream::~LogStream
~LogStream() override
Definition: logstream.cc:88
LogStream::depth_file
unsigned int depth_file(const unsigned int n)
Definition: logstream.cc:360
LogStream::precision
std::streamsize precision(const std::streamsize prec)
Definition: logstream.cc:333
smartpointer.h
Threads::ThreadLocalStorage
A class that provides a separate storage location on each thread that accesses the object.
Definition: thread_local_storage.h:72
LogStream::get_console
std::ostream & get_console()
Definition: logstream.cc:239
exceptions.h
SmartPointer< LogStream, LogStream::Prefix >
LogStream::depth_console
unsigned int depth_console(const unsigned int n)
Definition: logstream.cc:349
LogStream::print_thread_id
bool print_thread_id
Definition: logstream.h:355
Algorithms::OutputOperator::operator<<
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition: operator.h:173
LogStream::Prefix::stream
SmartPointer< LogStream, LogStream::Prefix > stream
Definition: logstream.h:128
LogStream
Definition: logstream.h:83
LogStream::LogStream
LogStream()
Definition: logstream.cc:75
LogStream::pop
void pop()
Definition: logstream.cc:316
LogStream::Prefix::~Prefix
~Prefix()
Definition: logstream.cc:57
config.h
LogStream::operator<<
LogStream & operator<<(std::ostream &(*p)(std::ostream &))
Definition: logstream.cc:125
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
LogStream::attach
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
LogStream::get_prefix
const std::string & get_prefix() const
Definition: logstream.cc:289
LogStream::has_file
bool has_file() const
Definition: logstream.cc:281
LogStream::file_depth
unsigned int file_depth
Definition: logstream.h:350
LogStream::width
std::streamsize width(const std::streamsize wide)
Definition: logstream.cc:341
LogStream::push
void push(const std::string &text)
Definition: logstream.cc:302