The following sections describe how you can use CFML tags and functions to display or hide debugging and tracing information.

Generating debugging information for an individual query

In the Administrator, the cfquery tag debug attribute overrides the Database Activity setting on the Debugging Settings page. The debug attribute has an effect only when debugging output is enabled on the Debugging Settings page, as follows:

  • If Database Activity is selected in the Administrator, specify debug="No" to prevent ColdFusion from displaying the query's SQL and statistics in the debugging output.
  • If Database Activity is not selected in the Administrator, specify debug="Yes" or debug to have ColdFusion display the query's SQL and statistics in the debugging output.
    For example, if Database Activity is not selected in the Administrator, you can use the following code to show the query execution time, number of records returned, ColdFusion page, timestamp, and the SQL statement sent to the data source for this query only:

<cfquery name="TestQuery" datasource="cfdocexamples" debug>
SELECT * FROM TestTable
</cfquery>

The debug attribute can be useful to disable query debugging information generated by queries in custom tags that you call frequently, so that you only see the debugging information for queries in pages that call the tags.
You can also view stored procedure-specific debugging information by specifying the debug attribute in the cfstoredproc tag.

Controlling debugging output with the cfsetting tag

Use the cfsetting tag showDebugOutput attribute to turn off debugging output for a specific page. The attribute controls debugging output only if the Debugging Settings page in the ColdFusion Administrator enables debugging output. The default value of the attribute is Yes. The following tag suppresses all debugging output for the current page:

<cfsetting showDebugOutput="No">

You can put this tag in the initialization code of the Application.cfc file or on your Application.cfm page to suppress all debugging output for an application, and override it on specific pages by setting showDebugOutput="Yes" in cfsetting tags on those pages. Conversely, you can leave debugging on for the application, and use the cfsetting showDebugOutput="No" tag to suppress debugging on individual pages where the output could cause errors or confusion.
You can also use the showDebugOutput attribute to control debugging output if you do not have access to the ColdFusion Administrator, but only if the Administrator enables debugging.

Using the IsDebugMode function to run code selectively

The IsDebugMode function returns True if debugging is enabled. You can use this function in a cfif tag condition to selectively run code only when debugging output is enabled. The IsDebugMode function lets you tell ColdFusion to run any code in debug mode, so it provides more flexibility than the cftrace tag for processing and displaying information.
You can use the IsDebugMode function to selectively log information only when debugging is enabled. Because you control the log output, you have the flexibility of silently logging information without displaying trace information in the browser. For example, the following code logs the application page, the current time, and the values of two variables to the log file MyAppSilentTrace.log when debugging is enabled:

<cfquery name="MyDBQuery" datasource="cfdocexamples">
SELECT *
FROM Employee
</cfquery>
<cfif IsDebugMode()>
<cflog file="MyAppSilentTrace" text="Page: #cgi.script_name#,
completed query MyDBQuery; Query Execution time:
#cfquery.ExecutionTime# Status: #Application.status#">
</cfif>

Note: If you use cfdump tags frequently for debugging, place them in <cfif IsDebugMode()> tags; for example <cfif IsDebugMode()><cfdump var=#myVar#></cfif>. This way you ensure that if you leave any cfdump_ tags in production code, they are not displayed when you disable debugging output._

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy