Class: Wildcloud::Logger::Middleware::Logeen

Inherits:
Object
  • Object
show all
Defined in:
lib/wildcloud/logger/middleware/logeen.rb

Defined Under Namespace

Classes: Connection

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Logeen

Returns a new instance of Logeen.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/wildcloud/logger/middleware/logeen.rb', line 40

def initialize(app, options = {})
  @options = options
  @queue = Queue.new
  @app = app
  reconnect
  @thread = Thread.new do
    loop do
      msg = @queue.pop.to_s
      msg = "#{msg.size}\n0#{msg}"
      @socket.send_data(msg)
    end
  end
end

Instance Method Details

#call(msg) ⇒ Object



54
55
56
57
# File 'lib/wildcloud/logger/middleware/logeen.rb', line 54

def call(msg)
  @queue << msg[:json_encoded]
  @app.call(msg)
end

#reconnectObject



36
37
38
# File 'lib/wildcloud/logger/middleware/logeen.rb', line 36

def reconnect
  @socket = EventMachine.connect(@options[:address], @options[:port], Connection, self)
end