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.



24
25
26
# File 'lib/rollbar/logger.rb', line 24

def initialize
  @level = ERROR
end

Instance Method Details

#<<(message) ⇒ Object



38
39
40
# File 'lib/rollbar/logger.rb', line 38

def <<(message)
  error(message)
end

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



28
29
30
31
32
33
34
35
36
# 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

#datetime_formatObject



54
55
56
# File 'lib/rollbar/logger.rb', line 54

def datetime_format
  raise(DatetimeFormatNotSupported)
end

#datetime_format=(_) ⇒ Object



50
51
52
# File 'lib/rollbar/logger.rb', line 50

def datetime_format=(_)
  raise(DatetimeFormatNotSupported)
end

#formatterObject



46
47
48
# File 'lib/rollbar/logger.rb', line 46

def formatter
  raise(FormatterNotSupported)
end

#formatter=(_) ⇒ Object



42
43
44
# File 'lib/rollbar/logger.rb', line 42

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.



61
62
63
64
65
66
# File 'lib/rollbar/logger.rb', line 61

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

  notifier
end