-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathModuleConfig.cfc
382 lines (347 loc) · 13.3 KB
/
ModuleConfig.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component {
// Module Properties
this.title = "ColdBox Debugger";
this.author = "Ortus Solutions";
this.version = "@build.version@[email protected]@";
this.webURL = "https://www.ortussolutions.com";
this.description = "The ColdBox Debugger Module";
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = true;
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = true;
// Module Entry Point
this.entryPoint = "cbdebugger";
// CF Mapping
this.cfMapping = "cbdebugger";
// Model Namespace
this.modelNamespace = "cbdebugger";
// App Helpers
this.applicationHelper = [ "helpers/Mixins.cfm" ];
/**
* Module Registration
*/
function configure(){
/**
* Settings
*/
variables.settings = {
// Internal engine flags
engine : {
isLucee : server.keyExists( "lucee" ),
isBoxLang : server.keyExists( "boxlang" ),
isAdobe : server.keyExists( "coldfusion" ) && server.coldfusion.productName.findNoCase(
"ColdFusion"
)
},
// This flag enables/disables the tracking of request data to our storage facilities
// To disable all tracking, turn this master key off
enabled : true,
// This setting controls if you will activate the debugger for visualizations ONLY
// The debugger will still track requests even in non debug mode.
debugMode : controller.getSetting( name = "environment", defaultValue = "production" ) == "development",
// The URL password to use to activate it on demand
// if set to cb:null, will generate random password
// to enable debugger in dev environment set to empty or custom password
// in live environment leave cb:null or set your own password
debugPassword : "cb:null",
// This flag enables/disables the end of request debugger panel docked to the bottem of the page.
// If you disable i, then the only way to visualize the debugger is via the `/cbdebugger` endpoint
requestPanelDock : true,
// Request Tracker Options
requestTracker : {
// Store the request profilers in heap memory or in cachebox, default is memory
storage : "memory",
// Which cache region to store the profilers in
cacheName : "template",
// Track all cbdebugger events, by default this is off, turn on, when actually profiling yourself :) How Meta!
trackDebuggerEvents : false,
// Slow request threshold in milliseconds, if execution time is above it, we mark those transactions as red
slowExecutionThreshold : 1000,
// How many tracking profilers to keep in stack
maxProfilers : 50,
// If enabled, the debugger will monitor the creation time of CFC objects via WireBox
profileWireBoxObjectCreation : false,
// Profile model objects annotated with the `profile` annotation
profileObjects : false,
// If enabled, will trace the results of any methods that are being profiled
traceObjectResults : false,
// Profile Custom or Core interception points
profileInterceptions : false,
// By default all interception events are excluded, you must include what you want to profile
includedInterceptions : [],
// Control the execution timers
executionTimers : {
expanded : true,
// Slow transaction timers in milliseconds, if execution time of the timer is above it, we mark it
slowTimerThreshold : 250
},
// Control the coldbox info reporting
coldboxInfo : { expanded : false },
// Control the http request reporting
httpRequest : {
expanded : false,
// If enabled, we will profile HTTP Body content, disabled by default as it contains lots of data
profileHTTPBody : false
}
},
// ColdBox Tracer Appender Messages
tracers : { enabled : true, expanded : false },
// Request Collections Reporting
collections : {
// Enable tracking
enabled : false,
// Expanded panel or not
expanded : false,
// How many rows to dump for object collections
maxQueryRows : 50,
// How many levels to output on dumps for objects
maxDumpTop : 5
},
// CacheBox Reporting
cachebox : { enabled : false, expanded : false },
// Modules Reporting
modules : { enabled : false, expanded : false },
// Quick and QB Reporting
qb : {
enabled : false,
expanded : false,
// Log the binding parameters
logParams : true
},
// cborm Reporting
cborm : {
enabled : false,
expanded : false,
// Log the binding parameters
logParams : true
},
// Adobe ColdFusion SQL Collector
acfSql : { enabled : false, expanded : false, logParams : true },
// Lucee SQL Collector
luceeSQL : { enabled : false, expanded : false, logParams : true },
// Async Manager Collector
async : { enabled : true, expanded : false },
// Hyper Collector
hyper : {
enabled : false,
expanded : false,
logResponseData : false,
logRequestBody : false
}
};
// Visualizer Route
router
.route( "/" )
.to( "Main.index" )
// Conventions
.route( "/:action" )
.toHandler( "Main" );
;
/**
* Custom Interception Points
*/
variables.interceptorSettings = {
customInterceptionPoints : [
// Before the debugger panel is rendered
"beforeDebuggerPanel",
// After the last debugger panel is rendered
"afterDebuggerPanel",
// Before any individual profiler report panels are rendered
"beforeProfilerReportPanels",
// After any individual profiler report panels are rendered
"afterProfilerReportPanels",
// Fires after the module has fully loaded and been configured with all runtime settings
"onDebuggerLoad",
// Fires after the module is unloaded
"onDebuggerUnload",
// When the request tracker has been created and placed in request scope
"onDebuggerRequestTrackerCreation",
// Before the request tracker is saved in the profiler, last chance to influence the recording
"onDebuggerProfilerRecording"
]
};
/******************** LOAD AOP MIXER ************************************/
// Verify if the AOP mixer is loaded, if not, load it
if ( !isAOPMixerLoaded() ) {
loadAOPMixer();
}
}
/**
* Load the module
*/
function onLoad(){
// Only activate interceptions and collectors if master switch is on or in test mode disable it
// And you must not be in testing mode
if ( !structKeyExists( controller, "mockController" ) && variables.settings.enabled ) {
var interceptorService = controller.getInterceptorService();
/******************** REQUEST COLLECTOR ************************************/
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.RequestCollector",
interceptorName = "RequestCollector@cbdebugger"
);
/******************** OBJECT PROFILING ************************************/
if ( variables.settings.requestTracker.profileObjects ) {
// Object Profiler Aspect
binder
.mapAspect( "ObjectProfiler" )
.to( "#moduleMapping#.aspects.ObjectProfiler" )
.initArg( name = "traceResults", value = variables.settings.requestTracker.traceObjectResults );
// Bind Object Aspects to monitor all a-la-carte profilers via method and component annotations
binder.bindAspect(
classes = binder.match().any(),
methods = binder.match().annotatedWith( "profile" ),
aspects = "ObjectProfiler"
);
binder.bindAspect(
classes = binder.match().annotatedWith( "profile" ),
methods = binder.match().any(),
aspects = "ObjectProfiler"
);
}
/******************** WIREBOX COLLECTOR ************************************/
if ( variables.settings.requestTracker.profileWireBoxObjectCreation ) {
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.WireBoxCollector",
interceptorName = "WireBoxCollector@cbdebugger"
);
}
/******************** PROFILE INTERCEPTIONS ************************************/
if ( variables.settings.requestTracker.profileInterceptions ) {
// Register our interceptor profiler
binder
.mapAspect( "InterceptorProfiler" )
.to( "#moduleMapping#.aspects.InterceptorProfiler" )
.initArg(
name = "excludedInterceptions",
value = controller.getInterceptorService().getInterceptionPoints()
)
.initArg(
name = "includedInterceptions",
value = variables.settings.requestTracker.includedInterceptions
);
// Intercept all announcements
binder.bindAspect(
classes = binder.match().mappings( "coldbox.system.services.InterceptorService" ),
methods = binder.match().methods( "announce" ),
aspects = "InterceptorProfiler"
);
// Apply AOP
wirebox.autowire(
target = controller.getInterceptorService(),
targetID = "coldbox.system.services.InterceptorService"
);
}
/******************** QB COLLECTOR ************************************/
if ( variables.settings.qb.enabled && controller.getModuleService().isModuleRegistered( "qb" ) ) {
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.QBCollector",
interceptorName = "QBCollector@cbdebugger"
);
}
/******************** QUICK COLLECTOR ************************************/
if ( variables.settings.qb.enabled && controller.getModuleService().isModuleRegistered( "quick" ) ) {
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.QuickCollector",
interceptorName = "QuickCollector@cbdebugger"
);
}
/******************** CBORM COLLECTOR ************************************/
if ( variables.settings.cborm.enabled && controller.getModuleService().isModuleRegistered( "cborm" ) ) {
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.CBOrmCollector",
interceptorName = "CBOrmCollector@cbdebugger"
);
}
/******************** ACFSQL COLLECTOR ************************************/
if ( variables.settings.acfSql.enabled && !server.keyExists( "lucee" ) ) {
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.ACFSqlCollector",
interceptorName = "ACFSqlCollector@cbdebugger"
);
} else {
variables.settings.acfSql.enabled = false;
}
/******************** Lucee SQL COLLECTOR ************************************/
if ( variables.settings.luceeSQL.enabled && server.keyExists( "lucee" ) ) {
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.LuceeSqlCollector",
interceptorName = "LuceeSqlCollector@cbdebugger"
);
} else {
variables.settings.luceeSQL.enabled = false;
}
/******************** Hyper COLLECTOR ************************************/
if ( variables.settings.hyper.enabled ) {
param variables.settings.hyper.logResponseData = false;
param variables.settings.hyper.logRequestBody = false;
interceptorService.registerInterceptor(
interceptorClass = "#moduleMapping#.interceptors.HyperCollector",
interceptorName = "HyperCollector@cbdebugger"
);
}
// Announce debugger loaded
interceptorService.announce( "onDebuggerLoad" );
}
// end master switch
}
/**
* Unloading
*/
function onUnload(){
// Only if we are enabled
if ( !structKeyExists( controller, "mockController" ) && variables.settings.enabled ) {
var interceptorService = controller.getInterceptorService();
interceptorService.announce( "onDebuggerUnload" );
interceptorService.unregister( "RequestCollector@cbdebugger" );
interceptorService.unregister( "WireBoxCollector@cbdebugger" );
interceptorService.unregister( "QBCollector@cbdebugger" );
interceptorService.unregister( "QuickCollector@cbdebugger" );
interceptorService.unregister( "CBOrmCollector@cbdebugger" );
interceptorService.unregister( "ACFSqlCollector@cbdebugger" );
}
}
/**
* Register our tracer appender after the configuration loads
*/
function afterConfigurationLoad(){
if ( variables.settings.enabled && variables.settings.tracers.enabled ) {
var logBox = controller.getLogBox();
logBox.registerAppender( "tracer", "cbdebugger.appenders.TracerAppender" );
var appenders = logBox.getAppendersMap( "tracer" );
// Register the appender with the root loggger, and turn the logger on.
var root = logBox.getRootLogger();
root.addAppender( appenders[ "tracer" ] );
root.setLevelMax( 4 );
root.setLevelMin( 0 );
}
}
/**
* Loads the AOP mixer if not loaded in the application
*/
private function loadAOPMixer(){
// register it
controller
.getInterceptorService()
.registerInterceptor(
interceptorObject: new coldbox.system.aop.Mixer().configure( wirebox, {} ),
interceptorName : "AOPMixer"
);
}
/**
* Verify if wirebox aop mixer is loaded
*/
private boolean function isAOPMixerLoaded(){
return wirebox
.getBinder()
.getListeners()
.filter( function( thisListener ){
return thisListener.class eq "coldbox.system.aop.Mixer";
} )
.len() > 0 ? true : false;
}
}