Class: Rack::Timeout::StateChangeLoggingObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/timeout/logging-observer.rb

Constant Summary collapse

STATE_LOG_LEVEL =
{ :expired   => :error,
  :ready     => :info,
  :active    => :debug,
  :timed_out => :error,
  :completed => :info,
}
SIMPLE_FORMATTER =
->(severity, timestamp, progname, msg) { "#{msg} at=#{severity.downcase}\n" }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStateChangeLoggingObserver

Returns a new instance of StateChangeLoggingObserver.



11
12
13
# File 'lib/rack/timeout/logging-observer.rb', line 11

def initialize
  @logger = nil
end

Instance Attribute Details

#logger=(value) ⇒ Object

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



29
30
31
# File 'lib/rack/timeout/logging-observer.rb', line 29

def logger=(value)
  @logger = value
end

Class Method Details

.mk_logger(device, level = ::Logger::INFO) ⇒ Object



21
22
23
24
25
26
# File 'lib/rack/timeout/logging-observer.rb', line 21

def self.mk_logger(device, level = ::Logger::INFO)
  ::Logger.new(device).tap do |logger|
    logger.level     = level
    logger.formatter = SIMPLE_FORMATTER
  end
end

Instance Method Details

#callbackObject

returns the Proc to be used as the observer callback block



16
17
18
# File 'lib/rack/timeout/logging-observer.rb', line 16

def callback
  method(:log_state_change)
end