Class: Airbrake::AirbrakeLogger

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/airbrake/logger.rb

Overview

Decorator for Logger from stdlib. Endows loggers the ability to both log and report errors to Airbrake.

Examples:

# Create a logger like you normally do and decorate it.
logger = Airbrake::AirbrakeLogger.new(Logger.new($stdout))

# Just use the logger like you normally do.
logger.fatal('oops')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ AirbrakeLogger

Returns a new instance of AirbrakeLogger.



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

def initialize(logger)
  super

  __setobj__(logger)
  @airbrake_notifier = Airbrake
  self.level = logger.level
end

Instance Attribute Details

#airbrake_levelInteger

Returns:

  • (Integer)


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

def airbrake_level
  @airbrake_level
end

#airbrake_notifierAirbrake::Notifier

Returns notifier to be used to send notices.

Examples:

# Assign a custom Airbrake notifier
logger.airbrake_notifier = Airbrake::NoticeNotifier.new

Returns:

  • (Airbrake::Notifier)

    notifier to be used to send notices



21
22
23
# File 'lib/airbrake/logger.rb', line 21

def airbrake_notifier
  @airbrake_notifier
end

Instance Method Details

#error(progname = nil, &block) ⇒ Object

See Also:

  • Logger#error


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

def error(progname = nil, &block)
  notify_airbrake(Logger::ERROR, progname)
  super
end

#fatal(progname = nil, &block) ⇒ Object

See Also:

  • Logger#fatal


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

def fatal(progname = nil, &block)
  notify_airbrake(Logger::FATAL, progname)
  super
end

#level=(value) ⇒ Object

See Also:

  • Logger#level=


59
60
61
62
# File 'lib/airbrake/logger.rb', line 59

def level=(value)
  self.airbrake_level = value < Logger::WARN ? Logger::WARN : value
  super
end

#unknown(progname = nil, &block) ⇒ Object

See Also:

  • Logger#unknown


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

def unknown(progname = nil, &block)
  notify_airbrake(Logger::UNKNOWN, progname)
  super
end

#warn(progname = nil, &block) ⇒ Object

See Also:

  • Logger#warn


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

def warn(progname = nil, &block)
  notify_airbrake(Logger::WARN, progname)
  super
end