Reference documentation for deal.II version GIT 194dd8bb02 2022-12-03 08:20: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\}}\)
logstream.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2020 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 <memory>
28 #include <sstream>
29 #include <stack>
30 #include <string>
31 
32 
34 
81 class LogStream : public Subscriptor
82 {
83 public:
101  class Prefix
102  {
103  public:
108  Prefix(const std::string &text);
109 
114  Prefix(const std::string &text, LogStream &stream);
115 
119  ~Prefix();
120 
121  private:
127  };
128 
129 
135  LogStream();
136 
137 
141  ~LogStream() override;
142 
143 
154  void
155  attach(std::ostream & o,
156  const bool print_job_id = true,
157  const std::ios_base::fmtflags flags = std::ios::showpoint |
158  std::ios::left);
159 
160 
165  void
166  detach();
167 
168 
172  std::ostream &
173  get_console();
174 
175 
179  std::ostream &
180  get_file_stream();
181 
182 
187  bool
188  has_file() const;
189 
190 
194  const std::string &
195  get_prefix() const;
196 
197 
210  void
211  push(const std::string &text);
212 
213 
217  void
218  pop();
219 
220 
231  unsigned int
232  depth_console(const unsigned int n);
233 
234 
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 
306 private:
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
372  print_line_head();
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 
404 template <typename T>
405 inline LogStream &
406 operator<<(LogStream &log, const T &t)
407 {
408  // print to the internal stringstream
409  log.get_stream() << t;
410  return log;
411 }
412 
413 
414 
418 extern LogStream deallog;
419 
420 
421 
423 
424 #endif
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition: operator.h:165
SmartPointer< LogStream, LogStream::Prefix > stream
Definition: logstream.h:126
Prefix(const std::string &text)
Definition: logstream.cc:41
std::thread::id parent_thread
Definition: logstream.h:328
std::streamsize width(const std::streamsize wide)
Definition: logstream.cc:342
std::ostream & get_console()
Definition: logstream.cc:240
unsigned int std_depth
Definition: logstream.h:351
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:303
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:326
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 at_newline
Definition: logstream.h:366
std::streamsize precision(const std::streamsize prec)
Definition: logstream.cc:334
std::ostream & get_file_stream()
Definition: logstream.cc:271
unsigned int depth_console(const unsigned int n)
Definition: logstream.cc:350
LogStream & operator<<(std::ostream &(*p)(std::ostream &))
Definition: logstream.cc:126
std::ostringstream & get_stream()
Definition: logstream.cc:248
bool has_file() const
Definition: logstream.cc:282
unsigned int depth_file(const unsigned int n)
Definition: logstream.cc:361
bool log_thread_id(const bool flag)
Definition: logstream.cc:372
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:403
std::stack< std::string > & get_prefixes() const
Definition: logstream.cc:383
const std::string & get_prefix() const
Definition: logstream.cc:290
void detach()
Definition: logstream.cc:232
void pop()
Definition: logstream.cc:317
~LogStream() override
Definition: logstream.cc:89
A class that provides a separate storage location on each thread that accesses the object.
VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &x)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
LogStream deallog
Definition: logstream.cc:37
static const char T