Class: Needle::LoggingInterceptor

Inherits:
Object
  • Object
show all
Includes:
IncludeExclude
Defined in:
lib/needle/logging-interceptor.rb

Overview

A LoggingInterceptor is an interceptor object that logs method invocations and exceptions. It includes the IncludeExclude functionality.

Constant Summary

Constants included from IncludeExclude

IncludeExclude::PATTERN

Instance Method Summary collapse

Constructor Details

#initialize(point, parms) ⇒ LoggingInterceptor

Create a new LoggingInterceptor for the given service point, with the given list of include and exclude patterns. The logger object will be created as well, named with the service point’s full name.



29
30
31
32
33
34
# File 'lib/needle/logging-interceptor.rb', line 29

def initialize( point, parms )
  @log = point.container.logs.get( point.fullname )

  @includes = build_map( parms[ :include ] )
  @excludes = build_map( parms[ :exclude ] )
end

Instance Method Details

#process(chain, context) ⇒ Object

Processes a method invocation context. If the current log has debugging activated, and the requested method is not excluded by the interceptor’s exclude and include patterns, then a message will be written for the method’s invocation, its return code, and any exception that is thrown.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/needle/logging-interceptor.rb', line 41

def process( chain, context )
  if @log.debug? && match( context )
    args = context.args.map { |i| i.inspect } .join( ', ' )
    @log.debug "#{context.sym}( #{args} )"

    begin
      result = chain.process_next( context )
    rescue Exception => e
      @log.debug "#{context.sym} raised #{e.message.inspect} (#{e.class})"
      raise
    end

    @log.debug "#{context.sym} => #{result.inspect}"
    return result
  else
    return chain.process_next( context )
  end
end