Flow123d  release_3.0.0-968-gc359144
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Logger Class Reference

Class for storing logger messages. More...

#include <logger.hh>

Inheritance diagram for Logger:
Inheritance graph
[legend]
Collaboration diagram for Logger:
Collaboration graph
[legend]

Public Types

enum  MsgType {
  warning = 0, message = 1, log = 2, debug = 3,
  error = 4
}
 Enum of types of Logger messages. More...
 

Public Member Functions

 Logger (MsgType type)
 Constructor. More...
 
Loggerset_context (const char *file_name, const char *function, const int line)
 Stores values for printing out line number, function, etc. More...
 
Loggerevery_proc ()
 Set flag every_process_ to true. More...
 
template<class... T>
Loggerfmt (T &&...t)
 Allow use functionality of fmtlib for formating message. More...
 
 ~Logger ()
 Destructor. More...
 

Static Public Member Functions

static const std::string msg_type_string (MsgType msg_type, bool full_format=true)
 Return string value of given MsgType in full or shorter format (e.g. "WARNING" of "Wrn") More...
 

Private Member Functions

void set_mask ()
 Set streams_mask_ according to the type of message. More...
 
void print_to_screen (std::ostream &stream, std::stringstream &scr_stream, StreamMask mask)
 Print formated message to given screen stream if mask corresponds with streams_mask_. More...
 
void print_to_file (std::ofstream &stream, std::stringstream &file_stream, StreamMask mask)
 Print formated message to given file stream if mask corresponds with streams_mask_. More...
 
bool print_screen_header (std::ostream &stream, std::stringstream &scr_stream)
 Print header to screen stream, helper method called from print_to_screen. More...
 
void print_file_header (std::ofstream &stream, std::stringstream &file_stream)
 Print header to file stream, helper method called from print_to_file. More...
 
std::string compact_file_name (std::string file_name)
 Return compact (relative) path to the given source file. More...
 

Private Attributes

std::stringstream cout_stream_
 Store messages printed to cout output stream. More...
 
std::stringstream cerr_stream_
 Store messages printed to cerr output stream. More...
 
std::stringstream file_stream_
 Store messages printed to file. More...
 
MsgType type_
 Type of message. More...
 
bool every_process_
 Flag marked if log message is printing for all processes or only for zero process. More...
 
std::string file_name_
 Actual file. More...
 
std::string function_
 Actual function. More...
 
int line_
 Actual line. More...
 
std::string date_time_
 Actual date and time. More...
 
int mpi_rank_
 Actual process (if MPI is supported) More...
 
StreamMask streams_mask_
 Mask of logger, specifies streams in actual time into which to be written. More...
 
StreamMask full_streams_mask_
 Mask of logger, specifies all streams into which to be written in logger message. More...
 

Friends

template<class T >
Loggeroperator<< (Logger &log, const T &x)
 
Loggeroperator<< (Logger &log, std::ostream &(*pf)(std::ostream &))
 
Loggeroperator<< (Logger &log, StreamMask mask)
 

Detailed Description

Class for storing logger messages.

Allow define different levels of log messages and distinguish output streams for individual leves. These output streams are -

Logger distinguishes four type of levels -

File output is optional. See LoggerOptions for setting this output stream.

Example of Logger usage:

For individual levels are defined macros -

Logger message is created by using an operator << and allow to add each type that has override this operator. Message is terminated with manipulator std::endl. Implicitly logger message is printed only in processor with rank zero. If necessary printed message for all process, it provides a method every_proc().

Examples of logger messages formating:

MessageOut() << "End of simulation at time: " << secondary_eq->solved_time() << "\n";
WarningOut() << "Unprocessed key '" << key_name << "' in Record '" << rec->type_name() << "'." << "\n";
LogOut() << "Write output to output stream: " << this->_base_filename << " for time: " << time << "\n";
DebugOut() << "Calling 'initialize' of empty equation '" << typeid(*this).name() << "'." << "\n";

Logger message can be created by more than one line ("\n" can be used multiple times):

MessageOut() << "Start time: " << this->start_time() << "\n" << "End time: " << this->end_time() << "\n";

Or Logger allow using fmtlib functionality for simpler formatting of message:

MessageOut() << fmt::format("Start time: {}\nEnd time: {}\n", this->start_time(), this->end_time());
MessageOut().fmt("Start time: {}\nEnd time: {}\n", this->start_time(), this->end_time());

In some cases message can be printed for all processes:

MessageOut().every_proc() << "Size distributed at process: " << distr->lsize() << "\n";

Implementation of Logger does not support manipulator std::endl. Please, use "\n" instead.

Definition at line 137 of file logger.hh.

Member Enumeration Documentation

Enum of types of Logger messages.

Enumerator
warning 
message 
log 
debug 
error 

Definition at line 140 of file logger.hh.

Constructor & Destructor Documentation

Logger::Logger ( MsgType  type)

Constructor.

Definition at line 65 of file logger.cc.

Logger::~Logger ( )

Destructor.

Definition at line 76 of file logger.cc.

Member Function Documentation

std::string Logger::compact_file_name ( std::string  file_name)
private

Return compact (relative) path to the given source file.

Definition at line 223 of file logger.cc.

Here is the caller graph for this function:

Logger & Logger::every_proc ( )

Set flag every_process_ to true.

Definition at line 111 of file logger.cc.

template<class... T>
Logger& Logger::fmt ( T &&...  t)
inline

Allow use functionality of fmtlib for formating message.

See examples in description of Logger class.

Definition at line 166 of file logger.hh.

const std::string Logger::msg_type_string ( MsgType  msg_type,
bool  full_format = true 
)
static

Return string value of given MsgType in full or shorter format (e.g. "WARNING" of "Wrn")

Definition at line 86 of file logger.cc.

Here is the caller graph for this function:

void Logger::print_file_header ( std::ofstream &  stream,
std::stringstream &  file_stream 
)
private

Print header to file stream, helper method called from print_to_file.

Definition at line 257 of file logger.cc.

Here is the caller graph for this function:

bool Logger::print_screen_header ( std::ostream &  stream,
std::stringstream &  scr_stream 
)
private

Print header to screen stream, helper method called from print_to_screen.

Definition at line 233 of file logger.cc.

Here is the caller graph for this function:

void Logger::print_to_file ( std::ofstream &  stream,
std::stringstream &  file_stream,
StreamMask  mask 
)
private

Print formated message to given file stream if mask corresponds with streams_mask_.

Definition at line 195 of file logger.cc.

Here is the caller graph for this function:

void Logger::print_to_screen ( std::ostream &  stream,
std::stringstream &  scr_stream,
StreamMask  mask 
)
private

Print formated message to given screen stream if mask corresponds with streams_mask_.

Definition at line 169 of file logger.cc.

Here is the caller graph for this function:

Logger & Logger::set_context ( const char *  file_name,
const char *  function,
const int  line 
)

Stores values for printing out line number, function, etc.

Definition at line 100 of file logger.cc.

void Logger::set_mask ( )
private

Set streams_mask_ according to the type of message.

Definition at line 119 of file logger.cc.

Here is the caller graph for this function:

Friends And Related Function Documentation

template<class T >
Logger& operator<< ( Logger log,
const T &  x 
)
friend

Definition at line 226 of file logger.hh.

Logger& operator<< ( Logger log,
std::ostream &(*)(std::ostream &)  pf 
)
friend

Definition at line 289 of file logger.cc.

Logger& operator<< ( Logger log,
StreamMask  mask 
)
friend

implementation of operators

Definition at line 279 of file logger.cc.

Member Data Documentation

std::stringstream Logger::cerr_stream_
private

Store messages printed to cerr output stream.

Definition at line 199 of file logger.hh.

std::stringstream Logger::cout_stream_
private

Store messages printed to cout output stream.

Definition at line 198 of file logger.hh.

std::string Logger::date_time_
private

Actual date and time.

Definition at line 207 of file logger.hh.

bool Logger::every_process_
private

Flag marked if log message is printing for all processes or only for zero process.

Definition at line 203 of file logger.hh.

std::string Logger::file_name_
private

Actual file.

Definition at line 204 of file logger.hh.

std::stringstream Logger::file_stream_
private

Store messages printed to file.

Definition at line 200 of file logger.hh.

StreamMask Logger::full_streams_mask_
private

Mask of logger, specifies all streams into which to be written in logger message.

Definition at line 210 of file logger.hh.

std::string Logger::function_
private

Actual function.

Definition at line 205 of file logger.hh.

int Logger::line_
private

Actual line.

Definition at line 206 of file logger.hh.

int Logger::mpi_rank_
private

Actual process (if MPI is supported)

Definition at line 208 of file logger.hh.

StreamMask Logger::streams_mask_
private

Mask of logger, specifies streams in actual time into which to be written.

Definition at line 209 of file logger.hh.

MsgType Logger::type_
private

Type of message.

Definition at line 202 of file logger.hh.


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