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 67 of file LogFile.hpp.


Constructor & Destructor Documentation

LogFile::LogFile (  )  [private]

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

Definition at line 37 of file LogFile.cpp.


Member Function Documentation

void LogFile::Close (  )  [static]

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

Definition at line 94 of file LogFile.cpp.

References mpInstance, and mpOutStream.

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

LogFile * LogFile::Instance (  )  [static]

Get the single instance of the LogFile object.

Definition at line 45 of file LogFile.cpp.

References mpInstance.

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

bool LogFile::IsFileSet (  ) 

Whether Set() has been called.

Definition at line 122 of file LogFile.cpp.

References mFileSet.

unsigned LogFile::Level (  )  [static]

Get the logging level.

Definition at line 54 of file LogFile.cpp.

References mLevel, and mpInstance.

unsigned LogFile::MaxLoggingLevel (  )  [static]

Get the maximum allowed logging level.

Definition at line 89 of file LogFile.cpp.

References mMaxLoggingLevel.

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 173 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.

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 66 of file LogFile.cpp.

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

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

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 127 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).

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

Definition at line 109 of file LogFile.cpp.

References mInitTime.

Referenced by CardiacElectroMechanicsProblem< 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.

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

Definition at line 104 of file LogFile.cpp.

References mInitTime.

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


Member Data Documentation

Whether a directory and filename has been set.

Definition at line 75 of file LogFile.hpp.

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

time_t LogFile::mInitTime [private]

The current current calendar time.

Definition at line 81 of file LogFile.hpp.

Referenced by WriteElapsedTime(), and WriteHeader().

The level of logging required for this particular log file.

Definition at line 84 of file LogFile.hpp.

Referenced by Level(), and Set().

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

The max level of logging.

Definition at line 87 of file LogFile.hpp.

Referenced by MaxLoggingLevel(), and Set().

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

The static single instance.

Definition at line 72 of file LogFile.hpp.

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

out_stream LogFile::mpOutStream [private]

The file to be written to.

Definition at line 78 of file LogFile.hpp.

Referenced by Close(), and Set().

The precision with which to output data.

Definition at line 90 of file LogFile.hpp.

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


The documentation for this class was generated from the following files:
Generated on Thu Dec 22 13:05:49 2011 for Chaste by  doxygen 1.6.3