versatile-mcmc  0.1.7
Classes | Public Types | Public Member Functions | List of all members
vmcmc::Logger Class Reference

A simple MACRO-focussed logging facility. More...

#include <logger.hpp>

Classes

struct  Location
 A simple struct used by the Logger macros to pass information about the filename and line number. More...
 

Public Types

enum  ELevel {
  Trace, Debug, Info, Warn,
  Error, Fatal, Undefined
}
 

Public Member Functions

 Logger (const std::string &name="")
 Standard constructor assigning a name to the logger instance. More...
 
std::mutex & GetMutex ()
 
bool IsLevelEnabled (ELevel level) const
 Check whether a certain log-level is enabled. More...
 
ELevel GetLevel () const
 Get a loggers minimum logging level. More...
 
void SetLevel (ELevel level)
 Set a loggers minimum logging level. More...
 
void SetColoured (bool coloured)
 Set whether the output should be coloured or not. More...
 
void StartMessage (ELevel level, const Location &loc=Location())
 Start a message with the specified level. More...
 
std::ostream & Log ()
 Get an output stream for log messages to append. More...
 
void EndMessage ()
 End and flush the last message. More...
 

Detailed Description

A simple MACRO-focussed logging facility.

It should primarily be accessed by the user through the use of MACROs:

// define a static logger instance:
LOG_DEFINE("some.logger.name");
// log an expression with given log-level
LOG(Info, "Some example log: " << someVariable << " more text ...");
// log an expression only once during execution
LOG_ONCE(Info, "This is displayed only once.");
// make an assertion and abort if false:
LOG_ASSERT( someCondition, "That assertion just failed." );

Available log levels are: Trace, Debug, Info, Warn, Error, Fatal

By default, if the library is compiled in release-mode, Trace and Debug outputs are silenced, as well as assertions. No external configuration mechanisms (yet).

This facility might possibly be replaced by boost log - or extended to accept user defined formatting and alternative output like log files.

Constructor & Destructor Documentation

vmcmc::Logger::Logger ( const std::string &  name = "")

Standard constructor assigning a name to the logger instance.

Parameters
nameThe logger name.

Member Function Documentation

void vmcmc::Logger::EndMessage ( )

End and flush the last message.

Do not use directly.

ELevel vmcmc::Logger::GetLevel ( ) const
inline

Get a loggers minimum logging level.

Returns
level enum item identifying the log level
bool vmcmc::Logger::IsLevelEnabled ( ELevel  level) const
inline

Check whether a certain log-level is enabled.

Parameters
levelThe log level as string representation.
Returns
std::ostream& vmcmc::Logger::Log ( )
inline

Get an output stream for log messages to append.

Do not use directly.

Returns
void vmcmc::Logger::SetColoured ( bool  coloured)
inline

Set whether the output should be coloured or not.

Parameters
coloured
void vmcmc::Logger::SetLevel ( ELevel  level)
inline

Set a loggers minimum logging level.

Parameters
levelenum item identifying the log level
void vmcmc::Logger::StartMessage ( ELevel  level,
const Location loc = Location() 
)

Start a message with the specified level.

Do not use this method directly. Use the macro LOG(logger, level, message) instead.

Parameters
levelThe log level.
locSource code location (set automatically by the corresponding macro).

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