Skip to content

Instantly share code, notes, and snippets.

@toretore
Created April 14, 2013 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toretore/5383220 to your computer and use it in GitHub Desktop.
Save toretore/5383220 to your computer and use it in GitHub Desktop.
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