Module: ErrorLog::ClassMethods
- Included in:
- ErrorLog
- Defined in:
- lib/error_log/class_methods.rb
Instance Method Summary collapse
- #current_revision ⇒ Object
- #init ⇒ Object
-
#log(level, error, options = {}) ⇒ Object
Log error, exception, or whatever you have on your mind.
-
#logger ⇒ Object
Errors log, may be useful when you’re facing some db related problems.
- #options ⇒ Object
Instance Method Details
#current_revision ⇒ Object
57 58 59 |
# File 'lib/error_log/class_methods.rb', line 57 def current_revision @current_revision end |
#init ⇒ Object
52 53 54 55 |
# File 'lib/error_log/class_methods.rb', line 52 def init @current_revision = Vcs.revision Migrations.auto_migrate! end |
#log(level, error, options = {}) ⇒ Object
Log error, exception, or whatever you have on your mind
Args:
* level - error level {:debug, :info, :warn, :error, :fatal}
* error - error string itself
* options
Possible options:
* :backtrace
* :params - params that can help you recreate this error, Hash
* :category - error category, helps you to group them later
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/error_log/class_methods.rb', line 22 def log(level,error,={}) backtrace = [:backtrace] unless backtrace begin # I'm raising an exception just to get the current backtrace # If there is any more clever way to do that, please share. raise "wat?!" rescue Exception => e backtrace = e.backtrace[1..-1] end end # Silent rescues may not be optimal, for now they seem better than creating more mess logger.error "\n\n\n#{Time.now}\n= #{error}\n#{backtrace.join("\n")}\n#{[:params]}" rescue nil ErrorLog::Model.create( :error => error, :backtrace => backtrace, :level => level, :params => [:params], :vcs_revision => current_revision, :category => [:category] || 'error_log' ) rescue nil end |
#logger ⇒ Object
Errors log, may be useful when you’re facing some db related problems
48 49 50 |
# File 'lib/error_log/class_methods.rb', line 48 def logger @logger = Logger.new(File.join(Rails.root,'log','error.log')) end |