Class: Celerbrake::CelerbrakeLogger

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

Overview

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

Examples:

# Create a logger like you normally do and decorate it.
logger = Celerbrake::CelerbrakeLogger.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) ⇒ CelerbrakeLogger

Returns a new instance of CelerbrakeLogger.



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

def initialize(logger)
  super

  __setobj__(logger)
  @celerbrake_notifier = Celerbrake
  self.level = logger.level
end

Instance Attribute Details

#celerbrake_levelInteger

Returns:

  • (Integer)


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

def celerbrake_level
  @celerbrake_level
end

#celerbrake_notifierCelerbrake::Notifier

Returns notifier to be used to send notices.

Examples:

# Assign a custom Celerbrake notifier
logger.celerbrake_notifier = Celerbrake::NoticeNotifier.new

Returns:

  • (Celerbrake::Notifier)

    notifier to be used to send notices



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

def celerbrake_notifier
  @celerbrake_notifier
end

Instance Method Details

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

See Also:

  • Logger#error


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

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

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

See Also:

  • Logger#fatal


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

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

#level=(value) ⇒ Object

See Also:

  • Logger#level=


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

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

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

See Also:

  • Logger#unknown


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

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

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

See Also:

  • Logger#warn


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

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