Class: Low::ScopedLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/low/scoped_logger.rb

Overview

‘Low::ScopedLogger` is a tiny extension to `Logger`. It allows `scope` to be specified, making it easy to grep any messages generated by a particular instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeObject

Returns the value of attribute scope.



8
9
10
# File 'lib/low/scoped_logger.rb', line 8

def scope
  @scope
end

Instance Method Details

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/low/scoped_logger.rb', line 10

def add(severity, message = nil, progname = nil, &block)
  if message.nil?
    if block_given?
      message = yield
    else
      message = progname
      progname = @progname
    end
  end

  formatted_message = message
  formatted_message = "[#{@scope}] #{formatted_message}" if @scope
  super severity, formatted_message, progname, &block
end