Easy automatic debugging

In many web development situations, you are often only allowed to use the automatic ColdFusion debugging in the 
test and/or QA environments. With a little additional code, you can use the new <cf_dump> tag in CF5
to display any and all ColdFusion and CGI variables.

This can aid in both new development and problem identification/resolution since the cfdump tag automatically
displays complex variables (i.e. arrays, structures, etc.)

<!--- determine the values you want to display --->
  <cfloop list="FORM,URL,APPLICATION,SESSION,REQUEST,COOKIE,CGI" index="i">
    <h5>
      
<cfoutput>#i#</cfoutput> VARIABLES
    </h5>
    <cftry>
       <cfswitch expression=
"#i#">
           <cfcase value=
"session">
               <!--- lock the session scoped variables --->
               <cflock timeout="10" type="READONLY" scope="SESSION">
                    <cfdump var=
"#evaluate(i)#"
               </cflock>
           </cfcase>
           <cfcase value=
"application">
               <!--- also should lock the application scoped variables --->
               <cflock timeout="10" type="READONLY" scope="APPLICATION">
                    <cfdump var=
"#evaluate(i)#"
               </cflock> 
           </cfcase>
           <cfdefaultcase>
                <cfdump var=
"#evaluate(i)#">
           </cfdefaultcase>
        </cfswitch>
        <cfcatch>

            <p>An error occurred while trying to display <strong><cfoutput>#i#</cfoutput></strong> variables.</p>
        </cfcatch>
    </cftry>
  </cfloop>


You can add this code to your OnRequestEnd.cfm page to always show debugging output. You can also easily extend
this idea to only show the output for certain IP addresses or based on other variables that you set to turn the display on and off.

I have created a custom tag using these principles that allows the output variables to be specified and the display 
can be controlled based on a user's IP address. This can be downloaded at http://www.nmconsulting.us/tags/



All ColdFusion Tutorials By Author: Nathan Miller