class Cabin::Outputs::EM::StdlibLogger
Wrap Ruby stdlib’s logger and make it EventMachine friendly. This allows you to output to a normal ruby logger with Cabin
.
Public Class Methods
new(logger)
click to toggle source
# File lib/cabin/outputs/em/stdlib-logger.rb, line 8 def initialize(logger) @logger_queue = EM::Queue.new @logger = logger # Consume log lines from a queue and send them with logger consumer end
Public Instance Methods
<<(data)
click to toggle source
Receive an event
# File lib/cabin/outputs/em/stdlib-logger.rb, line 30 def <<(data) line = Hash.new line[:method] = data[:level] || "info" line[:message] = "#{data[:message]} #{data.inspect}" if EM::reactor_running? # Push line onto queue for later sending @logger_queue.push(line) else # This will call @logger.info(data) or something similar @logger.send(line[:method], line[:message]) end end
consumer()
click to toggle source
# File lib/cabin/outputs/em/stdlib-logger.rb, line 15 def consumer line_sender = Proc.new do |line| # This will call @logger.info(data) or something similar @logger.send(line[:method], line[:message]) EM::next_tick do # Pop another line off the queue and do it again @logger_queue.pop(&line_sender) end end # Pop a line off the queue and send it with logger @logger_queue.pop(&line_sender) end