OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
FcstUtilities::FCSTLogStream Class Reference

The object FcstUtilities::log should be used throughout OpenFCST for console logging. More...

#include <logging.h>

Public Member Functions

 FCSTLogStream (std::ostream &stream)
 Standard constructor, since we intend to provide an object deallog in the library. More...
 
 ~FCSTLogStream ()
 Destructor. More...
 
void attach (std::ostream &o, const bool print_job_id=true)
 Enable output to a second stream, o, usually an output file. More...
 
void detach ()
 Disable output to the second stream. More...
 
std::ostream & get_file_stream ()
 Setup the logstream for regression test mode. More...
 
bool has_file () const
 
void push (const std::string &text)
 Push another prefix on the stack. More...
 
void pop ()
 Remove the last prefix added with push(). More...
 
unsigned int depth_console (const unsigned int n)
 Maximum number of levels to be printed on the console. More...
 
unsigned int depth_file (const unsigned int n)
 Maximum number of levels to be written to the log file. More...
 
template<typename T >
const FCSTLogStreamoperator<< (const T &t) const
 Output a constant something through this stream. More...
 
const FCSTLogStreamoperator<< (std::ostream &(*p)(std::ostream &)) const
 Treat ostream manipulators. More...
 

Private Attributes

std::ostream & output_stream
 Determine an estimate for the memory consumption (in bytes) of this object. More...
 
std::ostream * file
 Pointer to a stream, where a copy of the output is to go to. More...
 

Detailed Description

The object FcstUtilities::log should be used throughout OpenFCST for console logging.

When OpenFCST is compiled with PETSC/MPI the logging class is changed to accommodate logging from multiple processes.

Note
This class is inspired in LogStream from deal.II
Currently, the class does not implement the push and pop functions for adding prefixes
TODO I think I could remove all pre-compiler directives by storing a pointer to a number that is initialized in the appplication and that keeps track of the processor...
Author
M. Secanell

Constructor & Destructor Documentation

FcstUtilities::FCSTLogStream::FCSTLogStream ( std::ostream &  stream)

Standard constructor, since we intend to provide an object deallog in the library.

Set the standard output stream to std::cerr.

FcstUtilities::FCSTLogStream::~FCSTLogStream ( )

Destructor.

Member Function Documentation

void FcstUtilities::FCSTLogStream::attach ( std::ostream &  o,
const bool  print_job_id = true 
)

Enable output to a second stream, o, usually an output file.

The optional argument print_job_id is not used and it is maintained here to keep the same format as deal LogStream.

Usage

See SimulatorBuilder<dim>::open_logfile

unsigned int FcstUtilities::FCSTLogStream::depth_console ( const unsigned int  n)
inline

Maximum number of levels to be printed on the console.

This function allows to restrict console output to the upmost 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.

The previous value of this parameter is returned.

unsigned int FcstUtilities::FCSTLogStream::depth_file ( const unsigned int  n)
inline

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 spoile the value of a log file.

The previous value of this parameter is returned.

void FcstUtilities::FCSTLogStream::detach ( )

Disable output to the second stream.

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

std::ostream& FcstUtilities::FCSTLogStream::get_file_stream ( )
inline

Setup the logstream for regression test mode.

This sets the parameters #double_threshold, #float_threshold, and #offset to nonzero values. The exact values being used have been determined experimentally and can be found in the source code.

Called with an argument false, switches off test mode and sets all involved parameters to zero. Gives the default stream (std_out). Gives the file stream.

bool FcstUtilities::FCSTLogStream::has_file ( ) const
inline
Returns
true, if file stream has already been attached.
template<class T >
const FCSTLogStream & FcstUtilities::FCSTLogStream::operator<< ( const T &  t) const
inline

Output a constant something through this stream.

This function must be const so that member objects of this type can also be used from const member functions of the surrounding class.

const FCSTLogStream & FcstUtilities::FCSTLogStream::operator<< ( std::ostream &(*)(std::ostream &)  p) const
inline

Treat ostream manipulators.

This function must be const so that member objects of this type can also be used from const member functions of the surrounding class.

Note that compilers want to see this treated differently from the general template above since functions like std::endl are actually overloaded and can't be bound directly to a template type.

void FcstUtilities::FCSTLogStream::pop ( )
inline

Remove the last prefix added with push().

void FcstUtilities::FCSTLogStream::push ( const std::string &  text)
inline

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.

Member Data Documentation

std::ostream* FcstUtilities::FCSTLogStream::file
private

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.

std::ostream& FcstUtilities::FCSTLogStream::output_stream
private

Determine an estimate for the memory consumption (in bytes) of this object.

Since sometimes the size of objects can not be determined exactly (for example: what is the memory consumption of an STL std::map type with a certain number of elements?), this is only an estimate. however often quite close to the true value. Reference to the stream we want to write to.


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