Created
April 14, 2013 16:04
-
-
Save toretore/5383220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi-rzmq' | |
require 'json' | |
class ZMQLogger | |
attr_reader :context | |
def initialize | |
@context = ZMQ::Context.new | |
@logger = @context.socket(ZMQ::PAIR) | |
@logger.connect('ipc:///tmp/bajs') | |
end | |
def log(atts) | |
@logger.send_string(JSON.dump(atts)) | |
end | |
end | |
$LUGGER = ZMQLogger.new | |
Thread.abort_on_exception = true | |
Thread.new $LUGGER.context do |context| | |
logger = context.socket(ZMQ::PAIR) | |
logger.bind('ipc:///tmp/bajs') | |
pub = context.socket(ZMQ::PUB) | |
pub.bind('tcp://0.0.0.0:4455') | |
msg = '' | |
loop do | |
logger.recv_string(msg) | |
pub.send_string(msg) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment