Flow123d
3.9.0-c2ae2d0a8
|
Class for storing logger messages. More...
#include <logger.hh>
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... | |
Logger & | set_context (const char *file_name, const char *function, const int line) |
Stores values for printing out line number, function, etc. More... | |
Logger & | every_proc () |
Set flag every_process_ to true. More... | |
template<class... T> | |
Logger & | fmt (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::stringstream &scr_stream) |
Print header to screen stream, helper method called from print_to_screen . More... | |
void | print_file_header (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 > | |
Logger & | operator<< (Logger &log, const T &x) |
template<class T > | |
Logger & | operator<< (Logger &log, const std::vector< T > &vec) |
Logger & | operator<< (Logger &log, std::ostream &(*pf)(std::ostream &)) |
Logger & | operator<< (Logger &log, StreamMask mask) |
Class for storing logger messages.
Allow define different levels of log messages and distinguish output streams for individual leves. These output streams are -
LoggerOptions
class)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:
See that output of vectors of printable objects is supported. Implementation of Logger does not support manipulator std::endl. Please, use "\n" instead. New line character "\n" can be used multiple times.
Logger allow using fmtlib functionality for simpler formatting of message:
Messages are printed only on the zero MPI process by default. Parallel output on all processes must be required explicitly:
enum Logger::MsgType |
Enum of types of Logger messages.
Rules:
Enumerator | |
---|---|
warning | |
message | |
log | |
debug | |
error |
|
private |
Logger & Logger::every_proc | ( | ) |
|
inline |
|
static |
|
private |
|
private |
|
private |
|
private |
Logger & Logger::set_context | ( | const char * | file_name, |
const char * | function, | ||
const int | line | ||
) |
|
private |
|
friend |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |