Skip to content

Commit

Permalink
defer log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Mar 19, 2011
1 parent 84a68d4 commit 7f5a094
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions dashboard.rb
Expand Up @@ -37,18 +37,18 @@


@log = Logger.new(@options[:logfile]) @log = Logger.new(@options[:logfile])


def log_message(message)
if @options[:verbose]
puts message
end
@log.debug(message)
end

log_message('starting ...')

EventMachine.epoll if EventMachine.epoll? EventMachine.epoll if EventMachine.epoll?
EventMachine.kqueue = true if EventMachine.kqueue? EventMachine.kqueue = true if EventMachine.kqueue?
EventMachine.run do EventMachine.run do
def log_message(message)
if @options[:verbose]
puts message
end
EventMachine.defer(proc{@log.debug(message)})
end

log_message('starting ...')

class Dashboard < Sinatra::Base class Dashboard < Sinatra::Base
enable :logging enable :logging
get '/' do get '/' do
Expand All @@ -60,11 +60,11 @@ class Dashboard < Sinatra::Base
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8000) do |websocket| EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8000) do |websocket|
websocket.onopen do websocket.onopen do
websocket_connections.push websocket websocket_connections.push websocket
EventMachine.defer(proc {log_message('client connected to websocket')}) log_message('client connected to websocket')
end end
websocket.onclose do websocket.onclose do
websocket_connections.delete websocket websocket_connections.delete websocket
EventMachine.defer(proc{log_message('client disconnected from websocket')}) log_message('client disconnected from websocket')
end end
end end


Expand Down

0 comments on commit 7f5a094

Please sign in to comment.