|
Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
|
#include <logger.h>
Public Member Functions | |
| Logger () | |
| ~Logger () | |
| void | clear () |
| bool | close () |
| bool | flush (bool verbose) |
| std::stringstream & | getStream () |
| bool | open (MPI_Comm comm, const int &MASTERRANK, const std::string &fname, const bool &append=false) |
| Open a logfile. | |
| bool | print (const std::string &s) |
| std::string | str () |
| template<typename T> | |
| Logger & | operator<< (const T &value) |
| Logger & | operator<< (Logger &(*pf)(Logger &)) |
| Logger & | operator<< (std::ostream &(*pf)(std::ostream &)) |
Private Attributes | |
| bool | fileOpen |
| int | mpiRank |
| int | masterRank |
| std::stringstream | outStream |
| std::fstream * | masterStream |
A class for writing log messages in parallel. Logger functions in the same way as standard C++ input streams, i.e. you insert values by using the stream input operator <<.
There is one major difference between Logger and standard C++ input streams: the contents of Logger are not flushed/written into the output file when endl or flush are inserted. Instead, one has to insert manipulator write, defined in logger.h, into the stream.
This is because Logger actually uses a stringstream buffer internally, and C++ standard manipulators are just passed on to the stringstream as-is. It is not possible to detect when endl or flush are inserted, because they have the same function signature as other manipulators (such as showpos). In principle it is possible to define new manipulators endl and flush here in the same manner as write, but then wrapper functions would need to be written for all standard C++ manipulators because compilers think that std::endl and user-defined endl as ambiguous, i.e. compilers cannot decide which function should be linked.
| Logger::Logger | ( | ) |
Default constructor for class Logger.
Definition at line 32 of file logger.cpp.

| Logger::~Logger | ( | ) |
Destructor for class Logger. Destructor only calls Logger::close.
Definition at line 39 of file logger.cpp.

| bool Logger::close | ( | ) |
Close a logfile which has been previously opened with Logger::open.
Definition at line 51 of file logger.cpp.

| bool Logger::flush | ( | bool | verbose | ) |
Write the Logger stream buffer into the output file. The stream buffer is emptied if the write succeeded. The rank of the writing MPI process and current time and date, as given by ctime, are written before the user-defined message.
Definition at line 67 of file logger.cpp.

| bool Logger::open | ( | MPI_Comm | comm, |
| const int & | MASTERRANK, | ||
| const std::string & | fname, | ||
| const bool & | append = false ) |
Open a logfile.
This class can be used to write out logfiles. Only master rank writes out anythin, all other processes will not do anything when they attempt to use the logger, but it is still perfectly legal for them to call it.
| [in] | comm | MPI communicator for processes that are able to call this logger |
| [in] | MASTERRANK | The rank that does all communication. |
| [in] | fname | The name of the logfile. |
| [in] | append | Is the file appended (true), or overwritten (false) |
Definition at line 117 of file logger.cpp.
|
inline |
Function which allows one to insert C++-style stream manipulators, defined inside Logger, to be used in the input stream. This function gets mainly called when manipulator write is inserted to the stream.
| pf | A pointer to a stream manipulator. |
Definition at line 151 of file logger.cpp.

| Logger & Logger::operator<< | ( | std::ostream &(* | pf )(std::ostream &) | ) |
Function which allows one to use C++ stream manipulators such as endl or showpos, with Logger. This is just a wrapper function which passes the manipulators to internal stream buffer as-is.
| pf | Function pointer to C++ stream manipulator. |
Definition at line 162 of file logger.cpp.

| bool Logger::print | ( | const std::string & | s | ) |
Definition at line 135 of file logger.cpp.
|
private |
|
private |
|
private |
|
private |