class Needle::LoggingInterceptor

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

Public Class Methods

new( point, parms ) click to toggle source

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.

# 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

Public Instance Methods

process( chain, context ) click to toggle source

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.

# 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