Logo
Reference manual - version ored_version
Public Member Functions | Friends | List of all members
Log Class Reference

Global static Log class. More...

#include <ored/utilities/log.hpp>

+ Inheritance diagram for Log:

Public Member Functions

void registerLogger (const boost::shared_ptr< Logger > &logger)
 Add a new Logger. More...
 
void registerIndependentLogger (const boost::shared_ptr< IndependentLogger > &logger)
 
boost::shared_ptr< Logger > & logger (const std::string &name)
 Retrieve a Logger. More...
 
void removeLogger (const std::string &name)
 Remove a Logger. More...
 
void removeAllLoggers ()
 Remove all loggers. More...
 
std::string source (const char *filename, int lineNo)
 
void addExcludeFilter (const std::string &, const std::function< bool(const std::string &)>)
 
void removeExcludeFilter (const std::string &)
 
bool checkExcludeFilters (const std::string &)
 
void header (unsigned m, const char *filename, int lineNo)
 macro utility function - do not use directly
 
std::ostream & logStream ()
 macro utility function - do not use directly
 
void log (unsigned m)
 macro utility function - do not use directly
 
std::shared_mutex & mutex ()
 mutex to acquire locks
 
bool filter (unsigned mask)
 
unsigned mask ()
 
void setMask (unsigned mask)
 
const boost::filesystem::path & rootPath ()
 
void setRootPath (const boost::filesystem::path &pth)
 
int maxLen ()
 
void setMaxLen (const int n)
 
bool enabled ()
 
void switchOn ()
 
void switchOff ()
 
void setPid (const int pid)
 if a PID is set for the logger, messages are tagged with [1234] if pid = 1234
 

Friends

class QuantLib::Singleton< Log, std::integral_constant< bool, true > >
 

Detailed Description

Global static Log class.

The Global Log class gets registered with individual loggers and receives application log messages. Once a message is received, it is immediately dispatched to each of the registered loggers, the order in which the loggers are called is not guaranteed.

Logging is done by the calling thread and the LOG call blocks until all the loggers have returned.

At start up, the Log class has no loggers and so will ignore any LOG() messages until it is configured.

To configure the Log class to log to a file "/tmp/my_log.txt"

    Log::instance().removeAllLoggers();
    Log::instance().registerLogger(boost::shared_ptr<Logger>(new FileLogger("/tmp/my_log.txt")));

To change the Log class to only use a BufferLogger the user must call

    Log::instance().removeAllLoggers();
    Log::instance().registerLogger(boost::shared_ptr<Logger>(new BufferLogger));

and then to retrieve log messages from the buffer and print them to stdout the user must call:

    std::cout << "Begin Log Messages:" << std::endl;

    boost::shared_ptr<BufferLogger> bl = boost::dynamic_pointer_cast<BufferLogger>
      (Log::instance().logger(BufferLogger::name));

    while (bl.hasNext())
        std::cout << bl.next() << std::endl;
    std::cout << "End Log Messages." << std::endl;

Member Function Documentation

◆ registerLogger()

void registerLogger ( const boost::shared_ptr< Logger > &  logger)

Add a new Logger.

Adds a new logger to the Log class, the logger will be stored by it's Logger::name(). This method will throw if a logger with the same name is already registered.

Parameters
loggerthe logger to add

◆ logger()

boost::shared_ptr<Logger>& logger ( const std::string &  name)

Retrieve a Logger.

Retrieve a Logger by it's name, for example to retrieve the StderrLogger (assuming it is registered)

boost::shared_ptr<Logger> slogger = Log::instance().logger(StderrLogger::name);

◆ removeLogger()

void removeLogger ( const std::string &  name)

Remove a Logger.

Remove a logger by name

Parameters
namethe logger name

◆ removeAllLoggers()

void removeAllLoggers ( )

Remove all loggers.

Removes all loggers. If called, all subsequent log messages will be ignored.