Class: Rollbar::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/rollbar/logger.rb

Overview

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))

Defined Under Namespace

Classes: DatetimeFormatNotSupported, Error, FormatterNotSupported

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



22
23
24
# File 'lib/rollbar/logger.rb', line 22

def initialize
  @level = ERROR
end

Instance Method Details

#<<(message) ⇒ Object



36
37
38
# File 'lib/rollbar/logger.rb', line 36

def <<(message)
  error(message)
end

#add(severity, message = nil, progname = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/rollbar/logger.rb', line 26

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

#datetime_formatObject



52
53
54
# File 'lib/rollbar/logger.rb', line 52

def datetime_format
  raise(DatetimeFormatNotSupported)
end

#datetime_format=(_) ⇒ Object



48
49
50
# File 'lib/rollbar/logger.rb', line 48

def datetime_format=(_)
  raise(DatetimeFormatNotSupported)
end

#formatterObject



44
45
46
# File 'lib/rollbar/logger.rb', line 44

def formatter
  raise(FormatterNotSupported)
end

#formatter=(_) ⇒ Object



40
41
42
# File 'lib/rollbar/logger.rb', line 40

def formatter=(_)
  raise(FormatterNotSupported)
end

#rollbarObject

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.



59
60
61
62
63
64
# File 'lib/rollbar/logger.rb', line 59

def rollbar
  notifier = Rollbar.scope
  notifier.configuration.logger = ::Logger.new('/dev/null')

  notifier
end