module Egalite::ErrorLogger
Public Class Methods
admin_emails=(t)
click to toggle source
# File lib/egalite.rb, line 105 def admin_emails=(t) @@admin_emails=t end
catch_exception(sendmail = false, hash = {}) { || ... }
click to toggle source
# File lib/egalite.rb, line 136 def catch_exception(sendmail = false, hash = {}) begin yield rescue Exception => e ErrorLogger.write_exception(e, hash, sendmail) if @@do_not_catch raise e end end end
create_table(db, opts = {})
click to toggle source
# File lib/egalite.rb, line 88 def create_table(db, opts = {}) table = opts[:table_name] || :logs db.create_table(table) { primary_key :id, :integer, :auto_increment => true column :severity, :varchar column :ipaddress, :varchar column :text, :varchar column :url, :varchar column :md5, :varchar column :created_at, :timestamp column :checked_at, :timestamp } end
do_not_catch=(t)
click to toggle source
# File lib/egalite.rb, line 111 def do_not_catch=(t) @@do_not_catch=t end
email_from=(t)
click to toggle source
# File lib/egalite.rb, line 108 def email_from=(t) @@email_from=t end
table=(t)
click to toggle source
# File lib/egalite.rb, line 102 def table=(t) @@table=t end
write(hash, sendmail = false)
click to toggle source
# File lib/egalite.rb, line 114 def write(hash, sendmail = false) hash[:md5] = Digest::MD5.hexdigest(hash[:text]) unless hash[:md5] if (hash[:severity] == 'critical' or sendmail) and @@admin_emails Sendmail.send(hash[:text],{ :from => @@email_from || "egalite@example.com", :to => @@admin_emails, :subject => "Exception report from Egalite framework." }) end if @@table @@table.insert(hash) rescue nil end end
write_exception(e, hash, sendmail = false)
click to toggle source
# File lib/egalite.rb, line 127 def write_exception(e, hash, sendmail = false) severity = 'exception' severity = 'security' if e.is_a?(SecurityError) severity = 'critical' if e.is_a?(CriticalError) text = "#{e.to_s}\n#{e.backtrace.join("\n")}" ErrorLogger.write({:severity => severity, :text => text}.merge(hash),sendmail) end