Skip to content
neoneo edited this page Jan 26, 2012 · 9 revisions

Debugging is an integral part of developing software, and it should be made as easy as possible. CFlow includes a nice debug output, that makes a few things available for you to gain insight quickly. It includes:

  • The task hierarchy of the request, grouped into the execution phases (start, before, event, after, and end). If an event is canceled or dispatched, the corresponding tasks are displayed as children of the originating task. Laid out from top to bottom, you can follow the order of task execution easily.
  • Execution times of all tasks, making locating bottlenecks easy. Since well-designed tasks are atomic, this gives you a very detailed idea of the performance of your application.
  • Exception details, displayed within the task where the error occurred.
  • Clear indication where an event is canceled.
  • Custom messages, with or without some data you want to see displayed.

This output is enabled if you use a DebugContext object instead of a Context object. So in onApplicationStart(), you write:

application.context = new cflow.request.DebugContext();

Custom messages

Often you will want to display intermediate results. To display those results, you put a message on the event. In debug mode, your controller receives a DebugEvent instance, which is a regular Event with an additional method record(). It accepts a string (the message, required) and a struct (optional). In the debug output, your message will appear at the position where you invoked record(). The struct you passed in will be dumped at the same spot.
An advantage of this approach is that you don't have to output those results in your view template, or even stop execution altogether, using <cfabort>. Displaying data in a loop used to be a hassle. This feature ensures that this information is now nicely laid out.

Unfortunately, views have no access to the event object and can therefore not put messages in the debug output. The need for that should be little though, because views shouldn't contain much logic. However, debugging a view will be necessary sometimes, and you may have to resort to old tactics here. As a tip, use <cfexit> instead of <cfabort> when you need to stop the rendering process for some reason. This will leave the debug output available.

Clone this wiki locally