SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
smtk::io::Logger Class Reference

Log messages for later presentation to a user or a file. More...

#include <Logger.h>

Collaboration diagram for smtk::io::Logger:
[legend]

Classes

struct  Record
 

Public Types

enum  Severity {
  Debug, Info, Warning, Error,
  Fatal
}
 

Public Member Functions

 Logger (const Logger &logger)
 
Loggeroperator= (const Logger &logger)
 
std::size_t numberOfRecords () const
 
bool hasErrors () const
 
void clearErrors ()
 
void addRecord (Severity s, const std::string &m, const std::string &fname="", unsigned int line=0)
 
std::vector< Recordrecords () const
 Return a copy of all the records contained within the Logger. More...
 
Record record (std::size_t i) const
 Return a copy of the ith record in the logger.
 
std::string toString (std::size_t i, bool includeSourceLoc=false) const
 Convert the given log entry to a string.
 
std::string toString (std::size_t i, std::size_t j, bool includeSourceLoc=false) const
 Convert the given log entry range to a string.
 
std::string toHTML (std::size_t i, std::size_t j, bool includeSourceLoc) const
 
std::string convertToString (bool includeSourceLoc=false) const
 
std::string convertToHTML (bool includeSourceLoc=false) const
 
void reset ()
 
void append (const Logger &l)
 
void setFlushToStream (std::ostream *output, bool ownFile, bool includePast)
 Request all records be flushed to output as they are logged. More...
 
bool setFlushToFile (std::string filename, bool includePast)
 Request all records be flushed to a file with the given filename. More...
 
void setFlushToStdout (bool includePast)
 Request all records be flushed to the process's standard output. More...
 
void setFlushToStderr (bool includePast)
 Request all records be flushed to the process's standard error output. More...
 
void setCallback (std::function< void()> fn)
 Set a function to be called upon the destruction of the logger.
 

Static Public Member Functions

static Loggerinstance ()
 
static std::string toString (const Record &record, bool includeSourceLoc=false)
 Convert the given log entry to a string.
 
static std::string severityAsString (Severity s)
 

Protected Member Functions

void flushRecordsToStream (std::size_t beginRec, std::size_t endRec)
 This is a helper routine to write records to the stream (if one has been set).
 
std::string toStringInternal (std::size_t i, std::size_t j, bool includeSourceLoc=false) const
 

Protected Attributes

bool m_hasErrors { false }
 
std::vector< Recordm_records
 
std::ostream * m_stream { nullptr }
 
bool m_ownStream { false }
 
std::function< void()> m_callback
 

Detailed Description

Log messages for later presentation to a user or a file.

Logger has a singleton interface to a global logger, but is also constructible as a non-singleton object.

Member Function Documentation

◆ records()

std::vector< Logger::Record > smtk::io::Logger::records ( ) const

Return a copy of all the records contained within the Logger.

Note - the reason a copy of the records is returned instead of a reference is to make the call threadsafe

◆ setFlushToFile()

bool smtk::io::Logger::setFlushToFile ( std::string  filename,
bool  includePast 
)

Request all records be flushed to a file with the given filename.

If includePast is true, then all pre-existing records will be immediately written to the file (and future records as they are added/appended).

Returns true if the file was successfully created.

Note that only a single stream will be written at a time; calling this or other "setFlushTo" methods multiple times will only change where new records are written.

◆ setFlushToStderr()

void smtk::io::Logger::setFlushToStderr ( bool  includePast)

Request all records be flushed to the process's standard error output.

If includePast is true, then all pre-existing records will be immediately written to the file (and future records as they are added/appended).

This method is a convenience for Python users.

Note that only a single stream will be written at a time; calling this or other "setFlushTo" methods multiple times will only change where new records are written.

◆ setFlushToStdout()

void smtk::io::Logger::setFlushToStdout ( bool  includePast)

Request all records be flushed to the process's standard output.

If includePast is true, then all pre-existing records will be immediately written to the file (and future records as they are added/appended).

This method is a convenience for Python users.

Note that only a single stream will be written at a time; calling this or other "setFlushTo" methods multiple times will only change where new records are written.

◆ setFlushToStream()

void smtk::io::Logger::setFlushToStream ( std::ostream *  output,
bool  ownFile,
bool  includePast 
)

Request all records be flushed to output as they are logged.

If ownFile is true, then the Logger takes ownership of output and will delete it when the Logger is destructed. If output is nullptr, then this stops future log records from being appended to any file. If includePast is true, then all pre-existing records are written to the stream before this method returns (and future records are written as they are added/appended).

Note that only a single stream will be written at a time; calling this or other "setFlushTo" methods multiple times will only change where new records are written.


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