RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
#include <logger.h>
Classes | |
struct | Output |
Single entry to output to. More... | |
struct | Outputs |
List of entries to output to. More... | |
Public Member Functions | |
Logger () | |
Logger (zmq::context_t &contextRef) | |
Logger (std::shared_ptr< zmq::context_t > &context) | |
void | init () |
void | subscribe (const std::string &uri, const std::vector< std::string > &channels, const std::string &identity="") |
void | logTo (const std::string &uri, const boost::regex &allowChannels=boost::regex(), const boost::regex &denyChannels=boost::regex(), double logProbability=1.0) |
void | addOutput (std::shared_ptr< LogOutput > output, const boost::regex &allowChannels=boost::regex(), const boost::regex &denyChannels=boost::regex(), double logProbability=1.0) |
void | addCallback (boost::function< void(std::string, std::string)> callback, const boost::regex &allowChannels=boost::regex(), const boost::regex &denyChannels=boost::regex(), double logProbability=1.0) |
void | clearOutputs () |
template<typename... Args> | |
void | operator() (const std::string &channel, Args...args) |
template<typename... Args> | |
void | logMessage (const std::string &channel, Args...args) |
template<typename... Args> | |
void | logMessageNoTimestamp (const std::string &channel, Args...args) |
void | logMessageNoTimestamp (const std::vector< std::string > &message) |
template<typename GetEl > | |
void | logMessage (const std::string &channel, int numElements, GetEl getElement) |
void | start (std::function< void()> onStop=0) |
void | waitUntilFinished () |
void | shutdown () |
std::map< std::string, size_t > | getStats () |
void | resetStats () |
void | replay (const std::string &filename, ssize_t maxEvents=-1) |
Replay the events in the given filename through the logger. | |
void | replayDirect (const std::string &filename, ssize_t maxEvents=-1) const |
uint64_t | numMessagesSent () const |
uint64_t | numMessagesDone () const |
void | handleListenerMessage (std::vector< std::string > const &message) |
void | handleRawListenerMessage (std::vector< std::string > const &message) |
void | handleMessage (std::vector< zmq::message_t > &&message) |
Public Attributes | |
MessageLoop | messageLoop |
This is a class that: 1. Accepts log messages from any thread; 2. Forwards the messages to a single destination.
Everything is entirely thread-safe and in normal operation, logging a message will not block. This allows it to be used in contexts where logging happens in a time-critical loop, for example.
void Datacratic::Logger::addCallback | ( | boost::function< void(std::string, std::string)> | callback, |
const boost::regex & | allowChannels = boost::regex() , |
||
const boost::regex & | denyChannels = boost::regex() , |
||
double | logProbability = 1.0 |
||
) |
void Datacratic::Logger::addOutput | ( | std::shared_ptr< LogOutput > | output, |
const boost::regex & | allowChannels = boost::regex() , |
||
const boost::regex & | denyChannels = boost::regex() , |
||
double | logProbability = 1.0 |
||
) |
Set the output to the given object. Note that this is complicated by the necessity to stop the logging thread until the operation has been completed.
ONLY ONE THREAD AT A TIME MUST BE IN ADDOUTPUT OR CLEAROUTPUTS. There is no locking to avoid them causing problems for each other, just enough locking to stop them interfering with the event loop.
void Datacratic::Logger::clearOutputs | ( | ) |
void Datacratic::Logger::logTo | ( | const std::string & | uri, |
const boost::regex & | allowChannels = boost::regex() , |
||
const boost::regex & | denyChannels = boost::regex() , |
||
double | logProbability = 1.0 |
||
) |
Tell where to log to. The place it goes depends upon the URI:
void Datacratic::Logger::operator() | ( | const std::string & | channel, |
Args... | args | ||
) | [inline] |
void Datacratic::Logger::replayDirect | ( | const std::string & | filename, |
ssize_t | maxEvents = -1 |
||
) | const |
void Datacratic::Logger::subscribe | ( | const std::string & | uri, |
const std::vector< std::string > & | channels, | ||
const std::string & | identity = "" |
||
) |
Subscribe to the given stream to get log messages from. Optionally, a filter can also be set up to limit the messages to a given subset.
The identity argument sets the zeromq identity of the connecting socket. If this is set, then messages for the logger will be queued until it reconnects so that no messages are lost. If no identity is given then messages that are sent while the socket is down will be lost.