Skip to content

Instantly share code, notes, and snippets.

@evagoras
Created October 14, 2015 16:55
Show Gist options
  • Save evagoras/016b1be64e4576579b98 to your computer and use it in GitHub Desktop.
Save evagoras/016b1be64e4576579b98 to your computer and use it in GitHub Desktop.
<cfscript>
/**
* @hint A simple interceptor that logs method calls and their results
*/
component implements="coldbox.system.aop.MethodInterceptor" {
property name="log" inject="logbox:logger:{this}";
/**
* @hint Constructor
* @logResults Do we log results or not?
*/
function init
(
boolean logResults=true
)
{
instance = {
logResults = arguments.logResults
};
return this;
}
/**
* @hint Invoke an AOP method invocation
* @invocation The method invocation object: wirebox.system.aop.MethodInvocation
*/
function invokeMethod
(
required any invocation
)
{
var refLocal = {};
var debugString = "target: #arguments.invocation.getTargetName()#, "
& "method: #arguments.invocation.getMethod()#, "
& "arguments:#serializeJSON(arguments.invocation.getArgs())#";
// log incoming call
log.debug(debugString);
// proceed execution
refLocal.results = arguments.invocation.proceed();
// result logging and returns
if( structKeyExists(refLocal,"results") ){
if( instance.logResults ){
log.debug("#debugString#, results:", refLocal.results);
}
return refLocal.results;
}
return true;
}
}
</cfscript>
@evagoras
Copy link
Author

The reason this was failing was because I needed to add an output=false in the functions as well. This was defined in the interface, and it does make a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment