Class: ExceptionLog::Handler
- Inherits:
-
Object
- Object
- ExceptionLog::Handler
- Defined in:
- lib/exception_log/handler.rb
Instance Method Summary collapse
- #default_log_path ⇒ Object
- #do ⇒ Object
- #generate_text ⇒ Object
-
#initialize(env, exception, options = {}) ⇒ Handler
constructor
A new instance of Handler.
- #send_mail ⇒ Object
- #write_file ⇒ Object
Constructor Details
#initialize(env, exception, options = {}) ⇒ Handler
Returns a new instance of Handler.
7 8 9 10 11 12 13 |
# File 'lib/exception_log/handler.rb', line 7 def initialize(env,exception,={}) @exception = exception @request = ActionDispatch::Request.new(env) @controller = env['action_controller.instance'] @options = @body = generate_text end |
Instance Method Details
#default_log_path ⇒ Object
41 42 43 |
# File 'lib/exception_log/handler.rb', line 41 def default_log_path "#{Rails.root}/log/exception.log" end |
#do ⇒ Object
56 57 58 59 |
# File 'lib/exception_log/handler.rb', line 56 def do write_file send_mail end |
#generate_text ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/exception_log/handler.rb', line 15 def generate_text org_str = if @controller.respond_to? :current_orgnization org = @controller.send(:current_orgnization) "orgnization: #{org.try(:id)} #{org.try(:name)}" end user_str = if @controller.respond_to? :current_user user = @controller.send(:current_user) "user: #{user.try(:id)} #{user.try(:name)}" end error =<<HERE \n\n\n========================================= EXCEPTION ============================================================== #{org_str} #{user_str} time: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')} method: #{@request.method} url: #{@request.url} user-agent: #{@request.user_agent} referer: #{@request.headers["Referer"]} params: #{@controller.params} exception: #{@exception.class} message: #{@exception.} backtace: \n#{@exception.backtrace.join("\n")} HERE return error end |
#send_mail ⇒ Object
52 53 54 |
# File 'lib/exception_log/handler.rb', line 52 def send_mail ExceptionLog::Mailer.exception_mail(@body,:from=>@options[:from],:to=>@options[:to]).deliver end |
#write_file ⇒ Object
45 46 47 48 49 50 |
# File 'lib/exception_log/handler.rb', line 45 def write_file log_path = @options[:log_path] || default_log_path File.open(log_path,"a+") do |f| f.puts @body end end |