Global static Log class. More...
#include <ored/utilities/log.hpp>
Public Member Functions | |
void | registerLogger (const QuantLib::ext::shared_ptr< Logger > &logger) |
Add a new Logger. More... | |
void | registerIndependentLogger (const QuantLib::ext::shared_ptr< IndependentLogger > &logger) |
void | clearAllIndependentLoggers () |
const bool | hasLogger (const std::string &name) const |
Check if logger exists. More... | |
const bool | hasIndependentLogger (const std::string &name) const |
QuantLib::ext::shared_ptr< Logger > & | logger (const std::string &name) |
Retrieve a Logger. More... | |
QuantLib::ext::shared_ptr< IndependentLogger > & | independentLogger (const std::string &name) |
void | removeLogger (const std::string &name) |
Remove a Logger. More... | |
void | removeIndependentLogger (const std::string &name) |
void | removeAllLoggers () |
Remove all loggers. More... | |
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, not thread safe More... | |
std::ostream & | logStream () |
macro utility function - do not use directly, not thread safe More... | |
void | log (unsigned m) |
macro utility function - do not use directly, not thread safe More... | |
boost::shared_mutex & | mutex () |
mutex to acquire locks More... | |
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 () |
bool | writeSuppressedMessagesHint () |
void | setPid (const int pid) |
if a PID is set for the logger, messages are tagged with [1234] if pid = 1234 More... | |
Private Member Functions | |
Log () | |
std::string | source (const char *filename, int lineNo) const |
Private Attributes | |
std::map< std::string, QuantLib::ext::shared_ptr< Logger > > | loggers_ |
std::map< std::string, QuantLib::ext::shared_ptr< IndependentLogger > > | independentLoggers_ |
bool | enabled_ |
unsigned | mask_ |
boost::filesystem::path | rootPath_ |
std::ostringstream | ls_ |
int | maxLen_ = 45 |
std::size_t | sameSourceLocationSince_ = 0 |
bool | writeSuppressedMessagesHint_ = true |
std::size_t | sameSourceLocationCutoff_ = 1000 |
std::string | lastFileName_ |
int | lastLineNo_ = 0 |
int | pid_ = 0 |
boost::shared_mutex | mutex_ |
std::map< std::string, std::function< bool(const std::string &)> > | excludeFilters_ |
Friends | |
class | QuantLib::Singleton< Log, std::integral_constant< bool, true > > |
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(QuantLib::ext::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(QuantLib::ext::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; QuantLib::ext::shared_ptr<BufferLogger> bl = QuantLib::ext::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;
|
private |
Definition at line 272 of file log.cpp.
void registerLogger | ( | const QuantLib::ext::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.
logger | the logger to add |
Definition at line 278 of file log.cpp.
void registerIndependentLogger | ( | const QuantLib::ext::shared_ptr< IndependentLogger > & | logger | ) |
Definition at line 285 of file log.cpp.
void clearAllIndependentLoggers | ( | ) |
const bool hasLogger | ( | const std::string & | name | ) | const |
const bool hasIndependentLogger | ( | const std::string & | name | ) | const |
QuantLib::ext::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)
QuantLib::ext::shared_ptr<Logger> slogger = Log::instance().logger(StderrLogger::name);
Definition at line 303 of file log.cpp.
QuantLib::ext::shared_ptr< IndependentLogger > & independentLogger | ( | const std::string & | name | ) |
Definition at line 314 of file log.cpp.
void removeLogger | ( | const std::string & | name | ) |
void removeIndependentLogger | ( | const std::string & | name | ) |
Definition at line 330 of file log.cpp.
void removeAllLoggers | ( | ) |
Remove all loggers.
Removes all loggers. If called, all subsequent log messages will be ignored.
Definition at line 341 of file log.cpp.
void addExcludeFilter | ( | const std::string & | key, |
const std::function< bool(const std::string &)> | func | ||
) |
Definition at line 372 of file log.cpp.
void removeExcludeFilter | ( | const std::string & | key | ) |
Definition at line 377 of file log.cpp.
bool checkExcludeFilters | ( | const std::string & | msg | ) |
void header | ( | unsigned | m, |
const char * | filename, | ||
int | lineNo | ||
) |
macro utility function - do not use directly, not thread safe
Definition at line 391 of file log.cpp.
std::ostream & logStream | ( | ) |
void log | ( | unsigned | m | ) |
macro utility function - do not use directly, not thread safe
Definition at line 449 of file log.cpp.
boost::shared_mutex & mutex | ( | ) |
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 | ( | ) |
bool writeSuppressedMessagesHint | ( | ) |
void setPid | ( | const int | pid | ) |
|
private |
Definition at line 348 of file log.cpp.
|
private |
|
private |