Class: ZMQ::Logger
- Inherits:
-
Logger
- Object
- Logger
- ZMQ::Logger
- Defined in:
- lib/zmq/logger.rb
Overview
A logging class that sends its output to a ZMQ socket. This allows log messages to be sent asynchronously to another process and across a network if required. The receiving socket will receive messages, each with text of one log message.
Example usage:
socket = context.socket(ZMQ::PUSH)
socket.connect("tcp://logserver:5555")
logger = ZMQ::Logger.new(socket)
logger.debug("Hello logger")
Defined Under Namespace
Classes: InvalidSocketError, LogDevice
Constant Summary collapse
- VALID_SOCKET_CLASSES =
only these socket classes are allowed to be used for sending
[ Socket::Pub, Socket::Push, Socket::Pair ]
Instance Method Summary collapse
-
#initialize(socket) ⇒ Logger
constructor
Initialise a new logger object.
Constructor Details
#initialize(socket) ⇒ Logger
Initialise a new logger object. The logger sends log messages to a socket. The caller is responsible for connecting the socket before using the logger to send log output to the socket.
Supported socket types are a Socket::Pub, Socket::Push, and Socket::Pair
34 35 36 37 38 |
# File 'lib/zmq/logger.rb', line 34 def initialize(socket) raise InvalidSocketError unless VALID_SOCKET_CLASSES.any? { |klass| socket.is_a?(klass) } super(nil) @logdev = LogDevice.new(socket) end |