Skip to content

Instantly share code, notes, and snippets.

@supairish
Created February 16, 2015 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supairish/f090959aaf7035b96231 to your computer and use it in GitHub Desktop.
Save supairish/f090959aaf7035b96231 to your computer and use it in GitHub Desktop.
# in test.rb
require Rails.root.join('config/initializers/diagnostic')
config.middleware.use(MyApp::DiagnosticMiddleware)
# config/initializers/diagnostic.rb
module MyApp
class DiagnosticMiddleware
FILENAME = 'log/diagnostic.log' unless defined? FILENAME
def initialize(app)
@app = app
end
def call(env)
return @app.call(env)
rescue StandardError => e
trace = e.backtrace.select{ |l|l.start_with?(Rails.root.to_s) }.join("\n ")
msg = "#{e.class}\n#{e.message}\n#{trace}\n"
File.open(FILENAME, 'a') { |f| f.write msg }
raise e
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment