Adobe ColdFusion 8

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>

If you use cfdump tags frequently for debugging, put 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.