Class: Copland::Implementation::LoggingInterceptor
- Inherits:
-
Object
- Object
- Copland::Implementation::LoggingInterceptor
- Includes:
- IncludeExclude
- Defined in:
- lib/copland/impl/logging-interceptor.rb
Overview
A LoggingInterceptor is an interceptor object that logs method invocations and exceptions. It includes the IncludeExclude functionality.
Instance Attribute Summary collapse
-
#excludes ⇒ Object
readonly
The array of patterns of methods to not log.
-
#includes ⇒ Object
readonly
The array of patterns of methods to log.
-
#log ⇒ Object
readonly
The log used by this interceptor to log messages.
Instance Method Summary collapse
-
#initialize(point, includes, excludes) ⇒ LoggingInterceptor
constructor
Create a new LoggingInterceptor for the given service point, with the given list of include and exclude patterns.
-
#process(chain, context) ⇒ Object
Processes a method invocation context.
Constructor Details
#initialize(point, includes, excludes) ⇒ 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.
73 74 75 76 77 |
# File 'lib/copland/impl/logging-interceptor.rb', line 73 def initialize( point, includes, excludes ) @log = point.owner.registry.logs.get( point.full_name ) @includes = includes @excludes = excludes end |
Instance Attribute Details
#excludes ⇒ Object (readonly)
The array of patterns of methods to not log.
68 69 70 |
# File 'lib/copland/impl/logging-interceptor.rb', line 68 def excludes @excludes end |
#includes ⇒ Object (readonly)
The array of patterns of methods to log.
65 66 67 |
# File 'lib/copland/impl/logging-interceptor.rb', line 65 def includes @includes end |
#log ⇒ Object (readonly)
The log used by this interceptor to log messages.
62 63 64 |
# File 'lib/copland/impl/logging-interceptor.rb', line 62 def log @log 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.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/copland/impl/logging-interceptor.rb', line 84 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..inspect} (#{e.class})" raise end @log.debug "#{context.sym} => #{result.inspect}" return result else return chain.process_next( context ) end end |