-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathMethodLogger.cfc
57 lines (49 loc) · 1.4 KB
/
MethodLogger.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* A simple interceptor that logs method calls and their results
*/
component implements="coldbox.system.aop.MethodInterceptor" accessors="true" {
// DI
property name="log" inject="logbox:logger:{this}";
/**
* Log results
*/
property
name ="logResults"
type ="boolean"
default="true";
/**
* Constructor
*
* @logResults Log results or not
*/
function init( boolean logResults = true ){
variables.logResults = arguments.logResults;
return this;
}
/**
* Invoke an AOP method invocation
*
* @invocation The invocation object
* @invocation.doc_generic coldbox.system.aop.methodInvocation
*/
function invokeMethod( required invocation ) output="false"{
var refLocal = {};
var debugString = "target: #arguments.invocation.getTargetName()#,method: #arguments.invocation.getMethod()#,arguments:#serializeJSON( arguments.invocation.getArgs() )#";
// log incoming call
if ( log.canDebug() ) {
log.debug( debugString );
}
// proceed execution
refLocal.results = arguments.invocation.proceed();
// result logging and returns
if ( structKeyExists( refLocal, "results" ) ) {
if ( variables.logResults and log.canDebug() ) {
log.debug( "#debugString#, results:", refLocal.results );
}
return refLocal.results;
}
}
}