RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Classes | Public Member Functions | Public Attributes
Datacratic::Logger Struct Reference

#include <logger.h>

Inheritance diagram for Datacratic::Logger:
RTBKIT::DataLogger

List of all members.

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

Detailed Description

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.

Definition at line 81 of file logger.h.


Constructor & Destructor Documentation

Create a logger with its own zeromq context.

Definition at line 50 of file logger.cc.


Member Function Documentation

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 
)

Set up a callback that will call the given function when a message matching the filter is obtained.

Definition at line 272 of file logger.cc.

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.

Definition at line 252 of file logger.cc.

Clear all outputs.

Definition at line 283 of file logger.cc.

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:

  • file://path: log to the filename; if it finishes in "+" then it is appended;
  • ipc://path: publish to the given zeromq socket;
  • tcp://hostname: send over tcp/ip

Definition at line 233 of file logger.cc.

template<typename... Args>
void Datacratic::Logger::operator() ( const std::string &  channel,
Args...  args 
) [inline]

Log a given message to the given channel. Each of the arguments will be converted to a string and logged like that.

Definition at line 146 of file logger.h.

void Datacratic::Logger::replayDirect ( const std::string &  filename,
ssize_t  maxEvents = -1 
) const

Replay directly without going through zmq. start() cannot have been called.;

Definition at line 368 of file logger.cc.

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.

Definition at line 100 of file logger.cc.


The documentation for this struct was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator