Class: Wildcloud::Logger::Middleware::Logeen
- Inherits:
-
Object
- Object
- Wildcloud::Logger::Middleware::Logeen
- Defined in:
- lib/wildcloud/logger/middleware/logeen.rb
Defined Under Namespace
Classes: Connection
Instance Method Summary collapse
- #call(msg) ⇒ Object
-
#initialize(app, options = {}) ⇒ Logeen
constructor
A new instance of Logeen.
- #reconnect ⇒ Object
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 = @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 |
#reconnect ⇒ Object
36 37 38 |
# File 'lib/wildcloud/logger/middleware/logeen.rb', line 36 def reconnect @socket = EventMachine.connect(@options[:address], @options[:port], Connection, self) end |