Reference documentation for deal.II version Git 05e4468 2017-09-21 10:18:23 +0200
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
LogStream Class Reference

#include <deal.II/base/logstream.h>

Inheritance diagram for LogStream:


class  Prefix

Public Member Functions

 LogStream ()
 ~LogStream ()
void attach (std::ostream &o, const bool print_job_id=true)
void detach ()
std::ostream & get_console ()
std::ostream & get_file_stream ()
bool has_file () const
const std::string & get_prefix () const
void push (const std::string &text)
void pop ()
unsigned int depth_console (const unsigned int n)
unsigned int depth_file (const unsigned int n)
bool log_thread_id (const bool flag)
std::streamsize precision (const std::streamsize prec)
std::streamsize width (const std::streamsize wide)
std::ios::fmtflags flags (const std::ios::fmtflags f)
LogStreamoperator<< (std::ostream &(*p)(std::ostream &))
std::size_t memory_consumption () const
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 Subscriptor (const Subscriptor &)
 Subscriptor (Subscriptor &&)
virtual ~Subscriptor ()
Subscriptoroperator= (const Subscriptor &)
Subscriptoroperator= (Subscriptor &&)
void subscribe (const char *identifier=nullptr) const
void unsubscribe (const char *identifier=nullptr) const
unsigned int n_subscriptions () const
void list_subscribers () const
template<class Archive >
void serialize (Archive &ar, const unsigned int version)

Private Member Functions

std::stack< std::string > & get_prefixes () const
void print_line_head ()
std::ostringstream & get_stream ()

Private Attributes

Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
std::ostream * std_out
std::ostream * file
unsigned int std_depth
unsigned int file_depth
bool print_thread_id
bool at_newline
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams


template<typename T >
LogStreamoperator<< (LogStream &log, const T &t)

Additional Inherited Members

- Static Public Member Functions inherited from Subscriptor
static::ExceptionBase & ExcInUse (int arg1, char *arg2, std::string &arg3)
static::ExceptionBase & ExcNoSubscriber (char *arg1, char *arg2)

Detailed Description

A class that simplifies the process of execution logging. It does so by providing

The usual usage of this class is through the pregenerated object deallog. Typical setup steps are:

Before entering a new phase of your program, e.g. a new loop, a new prefix can be set via LogStream::Prefix p("loopname");. The destructor of the prefix will pop the prefix text from the stack.

Write via the << operator, deallog << "This is a log notice"; will be buffered thread locally until a std::flush or std::endl is encountered, which will trigger a writeout to the console and, if set up, the log file.

LogStream and thread safety

In the vicinity of concurrent threads, LogStream behaves in the following manner:

Guido Kanschat, Wolfgang Bangerth, 1999, 2003, 2011

Definition at line 81 of file logstream.h.

Constructor & Destructor Documentation

LogStream::LogStream ( )

Standard constructor. The standard output stream to std::cout.

Definition at line 67 of file

LogStream::~LogStream ( )


Definition at line 81 of file

Member Function Documentation

void LogStream::attach ( std::ostream &  o,
const bool  print_job_id = true 

Enable output to a second stream o.

The optional argument print_job_id specifies whether

Definition at line 207 of file

void LogStream::detach ( )

Disable output to the second stream. You may want to call close on the stream that was previously attached to this object.

Definition at line 218 of file

std::ostream & LogStream::get_console ( )

Gives the default stream (std_out).

Definition at line 226 of file

std::ostream & LogStream::get_file_stream ( )

Gives the file stream.

Definition at line 257 of file

bool LogStream::has_file ( ) const
true, if file stream has already been attached.

Definition at line 268 of file

const std::string & LogStream::get_prefix ( ) const

Return the prefix string.

Definition at line 276 of file

void LogStream::push ( const std::string &  text)

Push another prefix on the stack. Prefixes are automatically separated by a colon and there is a double colon after the last prefix.

A simpler way to add a prefix (without the manual need to add the corresponding pop()) is to use the Prefix class.

Definition at line 289 of file

void LogStream::pop ( )

Remove the last prefix added with push().

Definition at line 302 of file

unsigned int LogStream::depth_console ( const unsigned int  n)

Maximum number of levels to be printed on the console. The default is 0, which will not generate any output. This function allows one to restrict console output to the highest levels of iterations. Only output with less than n prefixes is printed. By calling this function with n=0, no console output will be written. See step-3 for an example usage of this method.

The previous value of this parameter is returned.

Definition at line 335 of file

unsigned int LogStream::depth_file ( const unsigned int  n)

Maximum number of levels to be written to the log file. The functionality is the same as depth_console, nevertheless, this function should be used with care, since it may spoil the value of a log file.

The previous value of this parameter is returned.

Definition at line 346 of file

bool LogStream::log_thread_id ( const bool  flag)

Log the thread id.

Definition at line 357 of file

std::streamsize LogStream::precision ( const std::streamsize  prec)

set the precision for the underlying stream and returns the previous stream precision. This function mimics

Definition at line 319 of file

std::streamsize LogStream::width ( const std::streamsize  wide)

set the width for the underlying stream and returns the previous stream width. This function mimics

Definition at line 327 of file

std::ios::fmtflags LogStream::flags ( const std::ios::fmtflags  f)

set the flags for the underlying stream and returns the previous stream flags. This function mimics

Definition at line 311 of file

LogStream & LogStream::operator<< ( std::ostream &(*)(std::ostream &)  p)

Treat ostream manipulators. This passes on the whole thing to the template function with the exception of the std::endl manipulator, for which special action is performed: write the temporary stream buffer including a header to the file and std::cout and empty the buffer.

An overload of this function is needed anyway, since the compiler can't bind manipulators like std::endl directly to template arguments T like in the previous general template. This is due to the fact that std::endl is actually an overloaded set of functions for std::ostream, std::wostream, and potentially more of this kind. This function is therefore necessary to pick one element from this overload set.

Definition at line 118 of file

std::size_t LogStream::memory_consumption ( ) const

Return an estimate for the memory consumption, in bytes, of this object. This is not exact (but will usually be close) because calculating the memory usage of trees (e.g., std::map) is difficult.

std::stack< std::string > & LogStream::get_prefixes ( ) const

Internal wrapper around thread-local prefixes. This private function will return the correct internal prefix stack. More important, a new thread- local stack will be copied from the current stack of the "blessed" thread that created this LogStream instance (usually, in the case of deallog, the "main" thread).

Definition at line 368 of file

void LogStream::print_line_head ( )

Print head of line.

Definition at line 402 of file

std::ostringstream & LogStream::get_stream ( )

Internal wrapper around "thread local" outstreams. This private function will return the correct internal ostringstream buffer for operator<<.

Definition at line 234 of file

Friends And Related Function Documentation

template<typename T >
LogStream& operator<< ( LogStream log,
const T &  t 

Output a constant something through LogStream:

We declare this operator as a non-member function so that it is possible to overload it with more specialized templated versions under C++11 overload resolution rules

Definition at line 366 of file logstream.h.

Member Data Documentation

Threads::ThreadLocalStorage<std::stack<std::string> > LogStream::prefixes

Stack of strings which are printed at the beginning of each line to allow identification where the output was generated.

Definition at line 293 of file logstream.h.

std::ostream* LogStream::std_out

Default stream, where the output is to go to. This stream defaults to std::cout, but can be set to another stream through the constructor.

Definition at line 300 of file logstream.h.

std::ostream* LogStream::file

Pointer to a stream, where a copy of the output is to go to. Usually, this will be a file stream.

You can set and reset this stream by the attach function.

Definition at line 308 of file logstream.h.

unsigned int LogStream::std_depth

Value denoting the number of prefixes to be printed to the standard output. If more than this number of prefixes is pushed to the stack, then no output will be generated until the number of prefixes shrinks back below this number.

Definition at line 316 of file logstream.h.

unsigned int LogStream::file_depth

Same for the maximum depth of prefixes for output to a file.

Definition at line 321 of file logstream.h.

bool LogStream::print_thread_id

Flag for printing thread id.

Definition at line 326 of file logstream.h.

bool LogStream::at_newline

A flag indicating whether output is currently at a new line

Definition at line 331 of file logstream.h.

Threads::ThreadLocalStorage<std::shared_ptr<std::ostringstream> > LogStream::outstreams

We use tbb's thread local storage facility to generate a stringstream for every thread that sends log messages.

Definition at line 348 of file logstream.h.

The documentation for this class was generated from the following files: