How to log all method calls for debugging in a ColdFusion application

Viewed 383

I'm working on a bunch of legacy ColdFusion applications and coming from a Java background it's really hard to debug something. So I'm at a point where, in order to debug, I place writeDump() or <cfdump> calls around the place to first get the flow of the application (it's something huge) and secondly to get some information on variable values. It's a painful process, so I was thinking if there's a way to "automate" it, at least to some extent.

I know I could place a log/dump call at the beginning of each function, but it would be a huge task.

I know in Java I could use an Aspect Oriented Programming library (for example How to use AOP with AspectJ for logging?) so I can define pointcuts for all methods in a class, and based on that do my desired logging logic (log the method name).

Is there something like that in ColdFusion? My requirements would be to use it without modifying existing code, to be as broad as possible so that I don't need to tell it to log each method, and to be easy to configure so I can add/remove/change what components to track and log.

2 Answers

Have you turned on basic debugging in your local CF Admin? This will output the entire current stack request at the bottom of your rendered page. It'll show you which part of the request is running slow and what queries are part of the request. It'll also show you what line threw an error and which previous line of code called it.

You might also consider using Fusion Reactor in production to help recreate errors in production and find those that haven't even been reported yet. No code changes are needed to implement it and it's been well worth the cost with the legacy CF app I've been managing for the last year and a half.

What is your ColdFusion version? if you have a recent version, then you're almost there. The tool you're looking for is FusionReactor (Ultimate version).

You will be glad to know that FR Ultimate runs on Java, and communicates with the underlying Java engine on which ColdFusion runs. The specific FR functionality that you want is "Profiling". Profiling gives you the stack of methods in any request that runs for more than 2 seconds.

Have a look at Charlie Arehart's webinar on FusionReactor Ultimate on Youtube. It is instructive to watch the whole webinar. His explanation about profiling starts around 16 minutes into the video.

Related