Skip to content

Instantly share code, notes, and snippets.

@AdamT
Forked from steve9001/application.rb
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save AdamT/7a70d6a30a9f2ffaa39b to your computer and use it in GitHub Desktop.

Select an option

Save AdamT/7a70d6a30a9f2ffaa39b to your computer and use it in GitHub Desktop.

Revisions

  1. @steve9001 steve9001 revised this gist Dec 7, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion diagnostic.rb
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ 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 = "\n#{e.class}\n#{e.message}\n#{trace}"
    msg = "#{e.class}\n#{e.message}\n#{trace}\n"
    File.open(FILENAME, 'a') { |f| f.write msg }
    raise e
    end
  2. @steve9001 steve9001 created this gist Dec 7, 2011.
    8 changes: 8 additions & 0 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    module MyApp
    class Application < Rails::Application
    if Rails.env == 'test'
    require 'diagnostic'
    config.middleware.use(MyApp::DiagnosticMiddleware)
    end
    end
    end
    18 changes: 18 additions & 0 deletions diagnostic.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    module MyApp
    class DiagnosticMiddleware
    FILENAME = 'diagnostic.txt'

    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 = "\n#{e.class}\n#{e.message}\n#{trace}"
    File.open(FILENAME, 'a') { |f| f.write msg }
    raise e
    end
    end
    end