diff options
author | Azul <azul@riseup.net> | 2016-09-23 15:54:56 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-09-23 15:54:56 +0200 |
commit | 35433792f9fa23f7b8d9c771d1d3676286a48870 (patch) | |
tree | bc9582a8b83f1a8ce22c16e614073dff7aebd9a4 | |
parent | 906724ff074710c7078b2d8423edd2477283b2e1 (diff) |
basic logging and recovery from exceptions raised
-rw-r--r-- | lib/nickserver/daemon.rb | 1 | ||||
-rw-r--r-- | lib/nickserver/reel_server.rb | 14 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/nickserver/daemon.rb b/lib/nickserver/daemon.rb index 9cc1af7..0f9e7bf 100644 --- a/lib/nickserver/daemon.rb +++ b/lib/nickserver/daemon.rb @@ -176,6 +176,7 @@ module Nickserver $stdout.reopen(log_path, 'a') $stderr.reopen $stdout $stdout.sync = true + $stderr.sync = true else # redirect to /dev/null $stdin.reopen '/dev/null' diff --git a/lib/nickserver/reel_server.rb b/lib/nickserver/reel_server.rb index d2a95ba..9a7053b 100644 --- a/lib/nickserver/reel_server.rb +++ b/lib/nickserver/reel_server.rb @@ -23,14 +23,24 @@ module Nickserver def on_connection(connection) connection.each_request do |request| - handler = handler_for(request) - handler.respond_to params(request), request.headers + handle_request(request) end end protected + def handle_request(request) + puts "#{request.method} #{request.uri}" + puts " #{params(request)}" + handler = handler_for(request) + handler.respond_to params(request), request.headers + rescue StandardError => e + puts e + puts e.backtrace.join "\n " + request.respond 500, "{}" + end + def handler_for(request) # with reel the request is the responder Dispatcher.new(request) |