Created
October 14, 2015 16:55
-
-
Save evagoras/016b1be64e4576579b98 to your computer and use it in GitHub Desktop.
CFScript version of this: http://wirebox.ortusbooks.com/content/aop/methodlogger_aspect.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.