3

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.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
Florin Vistig
  • 1,639
  • 2
  • 22
  • 31
  • Are you "debugging" as in responding to an error or trying to get a dump of everything available on the page? `writeDump()` requires an object that you are trying to dump, and you can't place `` tags around the things you want to dump. It doesn't work like that. And `cfdump` or `writedump` both can severely impact the performance of the page. – Shawn Oct 22 '18 at 15:15
  • @Shawn I'm referring to the case where I'm debugging locally to investigate an error that would appear in production. The logging of method calls would be disabled in production for sure. And I would dump only the current method's name. – Florin Vistig Oct 22 '18 at 15:25
  • ColdFusion itself has a pretty robust error handling system. http://www.learncfinaweek.com/week1/Error_Handling/ When you say "legacy" do you mean "The site uses Application.cfm", "The site doesn't use cfscript" or something else? – Shawn Oct 22 '18 at 15:35
  • 1
    And more specifically, what version of ColdFusion are you using? – Shawn Oct 22 '18 at 15:52
  • For some more info on basic debugging see this - http://www.learncfinaweek.com/week1/Debugging/ Coming from a Java background you are probably used to debugging with Eclipse. You can do that with ColdFusion too. See this - https://helpx.adobe.com/coldfusion/using-coldfusion-builder/debugging-applications.html – Miguel-F Oct 22 '18 at 16:02
  • If your legacy application uses some kind of framework, it will probably have logging facilities. If not, I supposed you could put a logging mechanism on `onRequestEnd()` but that would be quite heavy. – James A Mohler Oct 22 '18 at 16:22
  • It uses Flexbox, and CF 2018 . But there's a lot of CFMs as well. I meant it's legacy in the sense that I cannot modify the files too much, and that there are many... I think I didn't explain myself that well regarding the error investigation, what I meant is that I want to log all method calls for a request when something is behaving badly, but not necessarily throwing an error. We do have logging in place, but not everywhere... – Florin Vistig Oct 22 '18 at 17:05

2 Answers2

4

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.

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
  • Thank you for the suggestions. We also use Fusion Reactor which is a great tool in production. On top of that, I also want the possibility to investigate bugs that don't generate an error. So when running a request, I want to see all the methods that were called for it... – Florin Vistig Oct 22 '18 at 17:10
  • All of that data is in the stack trace portion of the CF debugging output. It's also in the stack trace tab in Fusion Reactor. If the code was in a `.cfm` file, you'll see the file name and line number. If the code was in a `.cfc`, you'll see the file name, method name and line number. – Adrian J. Moreno Oct 22 '18 at 20:07
0

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.

BKBK
  • 484
  • 2
  • 9