Reference documentation for deal.II version Git 0096380e24 2020-08-06 21:03:09 -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 
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
304  memory_consumption() const;
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
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:335
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition: logstream.h:321
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:361
std::thread::id parent_thread
Definition: logstream.h:328
~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:351
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:363
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:343
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:366
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition: logstream.h:385
void push(const std::string &text)
Definition: logstream.cc:303
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
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:356
std::size_t memory_consumption() const