Module: Logplexer
- Extended by:
- Logplexer
- Included in:
- Logplexer
- Defined in:
- lib/logplexer.rb,
lib/logplexer/railtie.rb,
lib/logplexer/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
Instance Method Details
#log(exception, log_type, opts = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/logplexer.rb', line 18 def log( exception, log_type, opts = {}) # We wrap the Honeybadger notify call so that in development, # we actually see the errors. Then we can unwrap the REST errors # if need be return if exception.nil? logfile = opts.delete( :logfile ) logger = Logger.new( logfile || STDOUT ) # Override the verbosity if LOG_VERBOSE is unset verbose = ENV["LOG_VERBOSE"] == "true" ? true : opts.delete( :verbose ) if ENV['LOG_TO_HB'] == "true" #TODO: Maybe extend this to include other kinds of notifiers. if exception.is_a? String exception = { error_class: "Exception", error_message: exception } end Honeybadger.notify( exception, opts ) else # Make sure that the exception is an actual exception and # not just a hash since Honeybadger accepts both if exception.is_a? Exception logger.send( log_type, exception. ) if verbose exception.backtrace.each do |entry| logger.send( log_type, "> #{entry}" ) end end elsif exception.is_a? String # Log just the string if thats what the user wants logger.send( log_type, exception ) else # Default kind of log for an object or whatevs logger.send( log_type, exception.inspect ) end end end |