class Rollbar::Logger
This class provides logger interface that can be used to replace the application logger and send all the log messages to Rollbar
Usage: require 'rollbar/logger' logger = Rollbar::Logger.new
logger.error('Error processing purchase')
If using Rails
, you can extend the Rails
logger so messages are logged normally and also to Rollbar:
Rails.logger.extend(ActiveSupport::Logger.broadcast(Rollbar::Logger.new
))
Public Class Methods
# File lib/rollbar/logger.rb, line 24 def initialize @level = ERROR end
Public Instance Methods
# File lib/rollbar/logger.rb, line 38 def <<(message) error(message) end
# File lib/rollbar/logger.rb, line 28 def add(severity, message = nil, progname = nil) return true if severity < @level message ||= block_given? ? yield : progname return true if blank?(message) rollbar.log(rollbar_level(severity), message) end
# File lib/rollbar/logger.rb, line 54 def datetime_format raise(DatetimeFormatNotSupported) end
# File lib/rollbar/logger.rb, line 50 def datetime_format=(_) raise(DatetimeFormatNotSupported) end
# File lib/rollbar/logger.rb, line 46 def formatter raise(FormatterNotSupported) end
# File lib/rollbar/logger.rb, line 42 def formatter=(_) raise(FormatterNotSupported) end
Returns a Rollbar::Notifier
instance with the current global scope and with a logger writing to /dev/null so we don't have a infinite loop when Rollbar.configuration
.logger is Rails.logger.
# File lib/rollbar/logger.rb, line 61 def rollbar notifier = Rollbar.scope notifier.configuration.logger = ::Logger.new('/dev/null') notifier end
Private Instance Methods
# File lib/rollbar/logger.rb, line 70 def blank?(message) return message.blank? if message.respond_to?(:blank?) message.respond_to?(:empty?) ? !!message.empty? : !message end
Find correct Rollbar
level to use using the indexes in Logger::Severity DEBUG = 0 INFO = 1 WARN = 2 ERROR = 3 FATAL = 4 UNKNOWN = 5
If not found we'll use 'error' as the used level
# File lib/rollbar/logger.rb, line 85 def rollbar_level(severity) [:debug, :info, :warning, :error, :critical, :error][severity] || :error end