LogFile Class Reference

#include <LogFile.hpp>

Collaboration diagram for LogFile:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void Set (unsigned level, std::string directory, std::string fileName="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 is 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 36 of file LogFile.cpp.

References mFileSet, mLevel, and mPrecision.


Member Function Documentation

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 >::CardiacElectroMechanicsProblem(), and CardiacElectroMechanicsProblem< DIM >::Solve().

void LogFile::Set ( unsigned  level,
std::string  directory,
std::string  fileName = "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 
directory 
fileName 

Definition at line 67 of file LogFile.cpp.

References 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 91 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 

Definition at line 131 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 107 of file LogFile.cpp.

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

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

void LogFile::Close (  )  [static]

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

Definition at line 97 of file LogFile.cpp.

References mpInstance, and mpOutStream.

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

bool LogFile::IsFileSet (  ) 

Whether Set() has been called

Definition at line 125 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

Definition at line 161 of file LogFile.hpp.

References mFileSet, and mPrecision.


Member Data Documentation

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

the static single instance

Definition at line 71 of file LogFile.hpp.

Referenced by Close(), and Instance().

bool LogFile::mFileSet [private]

whether a directory and filename has been set

Definition at line 73 of file LogFile.hpp.

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

out_stream LogFile::mpOutStream [private]

the file to be written to

Definition at line 75 of file LogFile.hpp.

Referenced by Close(), and Set().

unsigned LogFile::mLevel [private]

the level of logging required for this particular log file

Definition at line 80 of file LogFile.hpp.

Referenced by LogFile(), and Set().

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

the max level of logging

Definition at line 83 of file LogFile.hpp.

Referenced by MaxLoggingLevel(), and Set().

unsigned LogFile::mPrecision [private]

the precision with which to output data

Definition at line 86 of file LogFile.hpp.

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


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

Generated on Wed Mar 18 12:52:34 2009 for Chaste by  doxygen 1.5.5