Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
|
#include <LogFile.hpp>
Public Member Functions | |
void | Set (unsigned level, const std::string &rDirectory, const std::string &rFileName="log.txt") |
void | SetPrecision (unsigned precision) |
void | WriteHeader (std::string simulationType="") |
void | WriteElapsedTime (std::string pre="") |
bool | IsFileSet () |
template<class T > | |
LogFile & | operator<< (T message) |
Static Public Member Functions | |
static LogFile * | Instance () |
static unsigned | Level () |
static unsigned | MaxLoggingLevel () |
static void | Close () |
Private Member Functions | |
LogFile () | |
Private Attributes | |
bool | mFileSet |
out_stream | mpOutStream |
time_t | mInitTime |
unsigned | mLevel |
unsigned | mPrecision |
Static Private Attributes | |
static LogFile * | mpInstance = nullptr |
static const unsigned | mMaxLoggingLevel = 2 |
A singleton log file class. Allows the user to define log file in the test, which can be written to (without being passed around in the code).
Usage (in test):
// beginning of test LogFile* p_log = LogFile::Instance(); p_log->Set(level, "dir","file"); p_log->WriteHeader("type_of_sim"); // optional // at end of simulation LogFile::Close(); *
Here 'level' is a number between 0 and LogFile::MaxLoggingLevel, with zero meaning no logging and MaxLoggingLevel meaning full logging.
Usage (in source) - use the macro 'LOG'
LOG(1, "Info to be written to the log file\n" << "More info\n"); LogFile::Instance()->WriteElapsedTime(); // optional *
This checks whether the given level (here '1') is greater or equal to the given logging level, in which case it writes to the current log file. If there is no log file set up it does nothing.
Note the log file can be written to directly, without any level-checking, using
(*LogFile::Instance()) << "Info to be written to the log file\n"; *
Definition at line 80 of file LogFile.hpp.
|
private |
Constructor. Should never be called directly, call LogFile::Instance() instead.
Definition at line 44 of file LogFile.cpp.
Referenced by Instance().
|
static |
Close the currently open file, and delete the single LogFile instance.
Definition at line 101 of file LogFile.cpp.
References mpInstance, and mpOutStream.
Referenced by CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::~CardiacElectroMechanicsProblem().
|
static |
Definition at line 52 of file LogFile.cpp.
References LogFile(), and mpInstance.
Referenced by CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Initialise(), and CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve().
bool LogFile::IsFileSet | ( | ) |
Definition at line 129 of file LogFile.cpp.
References mFileSet.
|
static |
Definition at line 61 of file LogFile.cpp.
References mLevel, and mpInstance.
|
static |
Definition at line 96 of file LogFile.cpp.
References mMaxLoggingLevel.
|
inline |
message | the message to write to the log file |
Definition at line 187 of file LogFile.hpp.
References mFileSet, and mPrecision.
void LogFile::Set | ( | unsigned | level, |
const std::string & | rDirectory, | ||
const std::string & | rFileName = "log.txt" |
||
) |
Set the logging level, the directory (relative to TEST_OUTPUT) and the file the log should be written to (file defaults to "log.txt").
The level should be a number between 0 and LogFile::MaxLoggingLevel() (which is the same as LogFile::mMaxLoggingLevel)
Note: we intentionally do NOT check or throw an exception if a file has already been set (i.e. Close() wasn't called the last time a log was used).
The directory is never cleaned.
level | the logging level |
rDirectory | the directory in which to write the data to file |
rFileName | the name of the file to write to, relative to the output directory |
Definition at line 73 of file LogFile.cpp.
References EXCEPTION, mFileSet, mLevel, mMaxLoggingLevel, mpOutStream, and OutputFileHandler::OpenOutputFile().
Referenced by CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Initialise().
void LogFile::SetPrecision | ( | unsigned | precision | ) |
Set the precision to write data (the 'decimal precision', look up documentation for std::setprecision()).
precision | the precision |
Definition at line 134 of file LogFile.cpp.
References mPrecision.
void LogFile::WriteElapsedTime | ( | std::string | pre = "" | ) |
Write the elapsed time since the simulation began (since the log file was created).
pre | a string (eg spacings) to write before the elapsed time line. |
Definition at line 116 of file LogFile.cpp.
References mInitTime.
Referenced by CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Solve().
void LogFile::WriteHeader | ( | std::string | simulationType = "" | ) |
Write a header in the log file, stating the (given) type of simulation and the date and time.
simulationType | The type of simulation, eg "Bidomain" or "Crypt" or "Cardiac Electromechanics". Defaults to empty. |
Definition at line 111 of file LogFile.cpp.
References mInitTime.
Referenced by CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::Initialise().
|
private |
Whether a directory and filename has been set.
Definition at line 88 of file LogFile.hpp.
Referenced by IsFileSet(), operator<<(), and Set().
|
private |
The current current calendar time.
Definition at line 94 of file LogFile.hpp.
Referenced by WriteElapsedTime(), and WriteHeader().
|
private |
The level of logging required for this particular log file.
Definition at line 97 of file LogFile.hpp.
|
staticprivate |
The max level of logging.
Definition at line 100 of file LogFile.hpp.
Referenced by MaxLoggingLevel(), and Set().
|
staticprivate |
The static single instance.
Definition at line 85 of file LogFile.hpp.
Referenced by Close(), Instance(), and Level().
|
private |
The file to be written to.
Definition at line 91 of file LogFile.hpp.
|
private |
The precision with which to output data.
Definition at line 103 of file LogFile.hpp.
Referenced by operator<<(), and SetPrecision().