LogFile Class Reference

#include <LogFile.hpp>

Collaboration diagram for LogFile:

Collaboration graph
[legend]

List of all members.

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>
LogFileoperator<< (T message)

Static Public Member Functions

static LogFileInstance ()
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 LogFilempInstance = NULL
static const unsigned mMaxLoggingLevel = 2


Detailed Description

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):

// begining 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 (*LogFileInstance()) << "Info to be written to the log file\n";

Definition at line 68 of file LogFile.hpp.


Constructor & Destructor Documentation

LogFile::LogFile (  )  [private]

Constructor. Should never be called directly, call LogFile::Instance() instead.

Definition at line 38 of file LogFile.cpp.


Member Function Documentation

LogFile * LogFile::Instance (  )  [static]

Get the single instance of the LogFile object.

Definition at line 47 of file LogFile.cpp.

References mpInstance.

Referenced by CardiacElectroMechanicsProblem< DIM >::CardiacElectroMechanicsProblem(), and CardiacElectroMechanicsProblem< DIM >::Solve().

unsigned LogFile::Level (  )  [static]

Get the logging level.

Definition at line 56 of file LogFile.cpp.

References mLevel, and mpInstance.

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 (ie Close() wasn't called the last time a log was used).

The directory is never cleaned.

Parameters:
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 69 of file LogFile.cpp.

References EXCEPTION, mFileSet, mLevel, mMaxLoggingLevel, mpOutStream, and OutputFileHandler::OpenOutputFile().

Referenced by CardiacElectroMechanicsProblem< DIM >::CardiacElectroMechanicsProblem().

unsigned LogFile::MaxLoggingLevel (  )  [static]

Get the maximum allowed logging level.

Definition at line 93 of file LogFile.cpp.

References mMaxLoggingLevel.

void LogFile::SetPrecision ( unsigned  precision  ) 

Set the precision to write data (the 'decimal precision', look up documentation for std::setprecision()).

Parameters:
precision the precision

Definition at line 133 of file LogFile.cpp.

References mPrecision.

void LogFile::WriteHeader ( std::string  simulationType = ""  ) 

Write a header in the log file, stating the (given) type of simulation and the date and time

Parameters:
simulationType The type of simulation, eg "Bidomain" or "Crypt" or "Cardiac Electromechanics". Defaults to empty.

Definition at line 109 of file LogFile.cpp.

References mInitTime.

Referenced by CardiacElectroMechanicsProblem< DIM >::CardiacElectroMechanicsProblem().

void LogFile::WriteElapsedTime ( std::string  pre = ""  ) 

Write the elapsed time since the simulation began (since the log file was created).

Parameters:
pre a string (eg spacings) to write before the elapsed time line.

Definition at line 114 of file LogFile.cpp.

References mInitTime.

Referenced by CardiacElectroMechanicsProblem< DIM >::Solve().

void LogFile::Close (  )  [static]

Close the currently open file, and delete the single LogFile instance

Definition at line 99 of file LogFile.cpp.

References mpInstance, and mpOutStream.

Referenced by CardiacElectroMechanicsProblem< DIM >::~CardiacElectroMechanicsProblem().

bool LogFile::IsFileSet (  ) 

Whether Set() has been called

Definition at line 127 of file LogFile.cpp.

References mFileSet.

template<class T>
LogFile& LogFile::operator<< ( message  )  [inline]

Overloaded << operator, to write to the log file, if one has been set, and does nothing if not.

Parameters:
message the message to write to the log file

Definition at line 174 of file LogFile.hpp.

References mFileSet, and mPrecision.


Member Data Documentation

LogFile * LogFile::mpInstance = NULL [static, private]

The static single instance.

Definition at line 73 of file LogFile.hpp.

Referenced by Close(), Instance(), and Level().

bool LogFile::mFileSet [private]

Whether a directory and filename has been set.

Definition at line 76 of file LogFile.hpp.

Referenced by IsFileSet(), operator<<(), and Set().

out_stream LogFile::mpOutStream [private]

The file to be written to.

Definition at line 79 of file LogFile.hpp.

Referenced by Close(), and Set().

time_t LogFile::mInitTime [private]

The current current calendar time.

Definition at line 82 of file LogFile.hpp.

Referenced by WriteElapsedTime(), and WriteHeader().

unsigned LogFile::mLevel [private]

The level of logging required for this particular log file.

Definition at line 85 of file LogFile.hpp.

Referenced by Level(), and Set().

const unsigned LogFile::mMaxLoggingLevel = 2 [static, private]

The max level of logging.

Definition at line 88 of file LogFile.hpp.

Referenced by MaxLoggingLevel(), and Set().

unsigned LogFile::mPrecision [private]

The precision with which to output data.

Definition at line 91 of file LogFile.hpp.

Referenced by operator<<(), and SetPrecision().


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

Generated on Mon Apr 18 11:37:18 2011 for Chaste by  doxygen 1.5.5