The SKIRT project
advanced radiative transfer for astrophysics
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Log Class Referenceabstract

#include <Log.hpp>

Inheritance diagram for Log:
Inheritance graph
[legend]

Public Types

enum class  Level { Info , Warning , Success , Error }
 

Public Member Functions

void error (string message, bool store=true)
 
vector< string > errorsIssued ()
 
void info (string message)
 
void infoIfElapsed (string message, size_t numDone)
 
void infoSetElapsed (size_t numTotal, int seconds=5)
 
LoglinkedLog () const
 
Level lowestLevel () const
 
bool memoryLogging () const
 
void setLinkedLog (Log *log)
 
void setLowestLevel (Level level)
 
void setMemoryLogging (bool value)
 
void setVerbose (bool value)
 
void success (string message)
 
bool verbose () const
 
void warning (string message, bool store=true)
 
vector< string > warningsIssued ()
 
- Public Member Functions inherited from SimulationItem
template<class T >
T * find (bool setup=true) const
 
template<class T >
T * interface (int levels=-999999, bool setup=true) const
 
virtual string itemName () const
 
void setup ()
 
string typeAndName () const
 
- Public Member Functions inherited from Item
 Item (const Item &)=delete
 
virtual ~Item ()
 
void addChild (Item *child)
 
const vector< Item * > & children () const
 
virtual void clearItemListProperty (const PropertyDef *property)
 
void destroyChild (Item *child)
 
virtual bool getBoolProperty (const PropertyDef *property) const
 
virtual vector< double > getDoubleListProperty (const PropertyDef *property) const
 
virtual double getDoubleProperty (const PropertyDef *property) const
 
virtual string getEnumProperty (const PropertyDef *property) const
 
virtual int getIntProperty (const PropertyDef *property) const
 
virtual vector< Item * > getItemListProperty (const PropertyDef *property) const
 
virtual ItemgetItemProperty (const PropertyDef *property) const
 
virtual string getStringProperty (const PropertyDef *property) const
 
int getUtilityProperty (string name) const
 
virtual void insertIntoItemListProperty (const PropertyDef *property, int index, Item *item)
 
Itemoperator= (const Item &)=delete
 
Itemparent () const
 
virtual void removeFromItemListProperty (const PropertyDef *property, int index)
 
virtual void setBoolProperty (const PropertyDef *property, bool value)
 
virtual void setDoubleListProperty (const PropertyDef *property, vector< double > value)
 
virtual void setDoubleProperty (const PropertyDef *property, double value)
 
virtual void setEnumProperty (const PropertyDef *property, string value)
 
virtual void setIntProperty (const PropertyDef *property, int value)
 
virtual void setItemProperty (const PropertyDef *property, Item *item)
 
virtual void setStringProperty (const PropertyDef *property, string value)
 
void setUtilityProperty (string name, int value)
 
virtual string type () const
 

Protected Member Functions

 Log ()
 
virtual void output (string message, Level level)=0
 
string processName ()
 
void setupSelfBefore () override
 
- Protected Member Functions inherited from SimulationItem
 SimulationItem ()
 
virtual bool offersInterface (const std::type_info &interfaceTypeInfo) const
 
virtual void setupSelfAfter ()
 
virtual void setupSelfBefore ()
 
- Protected Member Functions inherited from Item
 Item ()
 

Private Member Functions

void setRank (int rank)
 

Private Attributes

vector< string > _errors
 
std::atomic< uint64_t > _interval
 
Log_link
 
bool _logmemory
 
Level _lowestLevel
 
std::mutex _mutex
 
std::atomic< size_t > _numDone
 
std::atomic< size_t > _numTotal
 
string _procNameLong
 
string _procNameShort
 
std::atomic< uint64_t > _started
 
bool _verbose
 
vector< string > _warnings
 

Detailed Description

Log is the abstract base class for a message logging mechanism. It offers convenience functions for logging messages at various levels (info, warning, success, error), adding a time-stamp along the way. All of these functions eventually call a single pure virtual function, which must be implemented in a subclass to actually output the message to a device such as the console or a file. The message-logging functions in this class are thread-safe.

Member Enumeration Documentation

◆ Level

enum class Log::Level
strong

This enum includes a constant for each logging level, in increasing order of importance.

Constructor & Destructor Documentation

◆ Log()

Log::Log ( )
protected

The default constructor is declared protected because this is an abstract class.

Member Function Documentation

◆ error()

void Log::error ( string  message,
bool  store = true 
)

Logs an informational message (i.e. at level Error). Each error message is logged, irrespective of which process invokes this function. The error message is prefixed with the process name, if multiprocessing mode is used. If the second argument is true or omitted, the warning message is also stored for later retrieval (e.g., at the end of the simulation). This function is thread-safe.

◆ errorsIssued()

vector< string > Log::errorsIssued ( )

This function returns a list of the error messages issued since this Log instance was constructed, limited to the first nine errors, or the empty list if no errors were issued. The messages are returned as they were passed to the error() function, i.e. without time stamp, process name or other embellishment. This list can be used, for example, to repeat the errors at the end of a simulation.

◆ info()

void Log::info ( string  message)

Logs an informational message (i.e. at level Info). In multiprocessing mode, only the info messages of the root processes are actually logged. If verbose mode is enabled, however, all processes log and the process name is attached to the info message. This function is thread-safe.

◆ infoIfElapsed()

void Log::infoIfElapsed ( string  message,
size_t  numDone 
)

Calls the info() function to log an informational message if a certain time interval (specified with the infoSetElapsed() function) has elapsed since the previous invocation of the infoIfElapsed() function (or of the infoSetElapsed() function). If the value of numTotal passed to infoSetElapsed() is nonzero, this function accumulates the values of numDone passed to the successive calls of infoIfElapsed() and uses this running subtotal to add a percentage of completion to the basic log message. This function is thread-safe.

◆ infoSetElapsed()

void Log::infoSetElapsed ( size_t  numTotal,
int  seconds = 5 
)

Resets the interval timer for progress messages issued through the infoIfElapsed() function. The first argument specifies the total number of tasks to be performed, which will be used to calculate a completion percentage in each progress message. Use a value of zero to disable this feature. The second argument optionally specifies the minimum time interval between messages in seconds; the default is 5 seconds. Call this function once before issuing a sequence of potentially frequent progress messages through the infoIfElapsed() function. This function should be called only from a single thread (for a given Log instance).

◆ linkedLog()

Log * Log::linkedLog ( ) const

Returns the Log instance that is linked into this one, so that it receives a copy of all messages.

◆ lowestLevel()

Level Log::lowestLevel ( ) const

Returns the lowest logging level that actually gets written to the output device.

◆ memoryLogging()

bool Log::memoryLogging ( ) const

Returns whether memory usage is logged or not.

◆ output()

virtual void Log::output ( string  message,
Level  level 
)
protectedpure virtual

This pure virtual function must be implemented in a subclass to actually output the specified message to a device such as the console or a file in a thread-safe way. The message does not yet contain a time stamp. The second argument specifies the logging level for the message (info, warning, success, error). The level is guaranteed to be at or above the current lowest level.

Implemented in ConsoleLog, and FileLog.

◆ processName()

string Log::processName ( )
protected

This function returns a string identifying this process of the form "Pnnn", where nnn is the rank of the process. In singleprocessing mode, this string is empty.

◆ setLinkedLog()

void Log::setLinkedLog ( Log log)

Sets the Log instance that is linked into this one. All messages received by this Log instance are also sent to the linked Log instance, regardless of the logging level set for this instance (i.e. each Log instance in the chain decides for itself which messages to display). The receiving Log instance assumes ownership of the linked Log instance.

◆ setLowestLevel()

void Log::setLowestLevel ( Level  level)

Sets the lowest logging level that actually gets written to the output device. In other words, any messages logged at a lower level are ignored. The default value is Info, so that all messages are logged.

◆ setMemoryLogging()

void Log::setMemoryLogging ( bool  value)

Sets or unsets the memory logging mode for this Log instance.

◆ setRank()

void Log::setRank ( int  rank)
private

This private function sets the process name used for logging based on the process rank passed as an argument to this function. This function makes sure that the same procedure is also applied for the linked Log instance, if present.

◆ setupSelfBefore()

void Log::setupSelfBefore ( )
overrideprotectedvirtual

The purpose of this function is setting the _procName attribute, using the rank of the process. This rank is obtained by using the find algorithm to search for an instance of a ProcessCommunicator subclass. If none is found, because for example the simulation or fitscheme hierarchy has not yet been created, the function returns and _procName retains its empty state. If the find algorithm does succeed, the find algorithm is applied again, this time to invoke the setup of the ProcessCommunicator object, if this is not yet done. Then, the rank is obtained from the ProcessCommunicator and passed as an argument to the setProcessName() function.

Reimplemented from SimulationItem.

◆ setVerbose()

void Log::setVerbose ( bool  value)

Sets or unsets the verbose mode for this Log instance.

◆ success()

void Log::success ( string  message)

Logs an informational message (i.e. at level Success). In multiprocessing mode, only the success messages of the root processes are actually logged. If verbose mode is enabled, however, all processes log and the process name is attached to the success message. This function is thread-safe.

◆ verbose()

bool Log::verbose ( ) const

Returns whether the Log is set in verbose mode or not.

◆ warning()

void Log::warning ( string  message,
bool  store = true 
)

Logs a warning message (i.e. at level Warning). Each warning message is logged, irrespective of which process invokes this function. The warning message is prefixed with the process name, if multiprocessing mode is used. If the second argument is true or omitted, the warning message is also stored for later retrieval (e.g., at the end of the simulation). This function is thread-safe.

◆ warningsIssued()

vector< string > Log::warningsIssued ( )

This function returns a list of the warning messages issued since this Log instance was constructed, limited to the first nine warnings, or the empty list if no warnings were issued. The messages are returned as they were passed to the warning() function, i.e. without time stamp, process name or other embellishment. This list can be used, for example, to repeat the warnings at the end of a simulation.


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