SeeFusion Trace Tag

Posted by Dan on Feb 13, 2006 @ 5:19 PM

I was needing to do some debugging on a live server today. I had some code that was not performing the way it should have been, so I want to use SeeFusion's trace() method to dump out some information to the debug log so I could find out exactly what line was causing the problem.

Anyway, instead of invoking a reference to the SeeFusion Java object, and manually putting in trace() methods, I thought I'd write up a little CF tag that would manage the creation of the object in the Request scope and dump out the trace methods for me, as I felt this would speed up being able to quickly insert a SeeFusion trace.

There's nothing fancy going on here, but I thought I'd just share the tag in case it saves anyone some time. I'd recommend saving this file as "seefusion.cfm" in your default ColdFusion Custom Tag directory. That will make it available to any template without having to worry about any mappings.

Name: cf_seefusion
Author: Dan G. Switzer, II
Date: February 13, 2006

This tag will set up the SeeFusion trace object in the Request
scope and dump the contents of the trace attribute to the trace
log. You must have SeeFusion installed for this tag to work.

<cf_seefusion trace="Hello World!" />
This would output "Hello World! @10ms" (where @10ms in the
    milliseconds where the command ran) to the SeeFusion "Completed"
    column in the "running requests" section of the server output.

<cfif thisTag.executionMode eq "start">
    <cfparam name="attributes.trace" type="string" />

        <cfif not structKeyExists(request, "SeeFusionClass")>
            <cfset request.SeeFusionClass = createObject("java", "com.seefusion.SeeFusion") />

        <cfset request.SeeFusionClass.trace(attributes.trace)>

            <cfthrow message="<h1>
                An Error Occurred Using SeeFusion Trace Tag
                This tag requires that SeeFusion be installed on the
                server. If you've recieved this message than SeeFusion is
                most likely not installed on your system or you're using
                a version of SeeFusion that does not support the trace() method.



This code will only initiate the SeeFusion Java object once per page request. It'll also throw an error if the SeeFusion isn't found. To use the code, just put the following line in your code:

<cf_seefusion trace="Hello World!">

To view the trace information, you'll need to log in to the SeeFusion web page and click on one of the Debug links at the bottom of the page. Any calls to the <cf_seefusion> tag will now pop up in the Debug window.

This feature is very nice because the information is hidden from the users, but allows you to see what's going on. Plus, it allows you to monitor threads from other users—which is something you couldn't do if the trace information was only displayed to the active user.

So far SeeFusion has proved extremely useful.

Categories: HTML/ColdFusion, Source Code

Comments for this entry have been disabled.