View comments | RSS feed
Contents > Developing ColdFusion MX Applications > Handling Errors > Logging errors with the cflog tag PreviousNext

Logging errors with the cflog tag

ColdFusion provides extensive capabilities for generating, managing, and viewing log files, as described in Configuring and Administering ColdFusion MX. It also provides the cflog tag which adds entries to ColdFusion logs.

ColdFusion automatically logs errors to the default logs if you use the default error handlers. In all other cases, you must use the cflog tag in your error handling code to generate log entries.

The cflog tag lets you specify the following information:

For example, you could use a cflog tag in an exception error-handling page to log the error information to an application-specific log file, as in the following page:

<html>
<head>
<title>Products - Error</title>
</head>
<body>

<h2>Sorry</h2>

<p>An error occurred when you requested this page.
The error has been logged and we will work to correct the problem.
We apologize for the inconvenience. </p>

<cflog type="Error"
      file="myapp_errors"
      text="Exception error -- 
         Exception type: #error.type#
         Template: #error.template#,
         Remote Address: #error.remoteAddress#, 
         HTTP Reference: #error.HTTPReferer#
         Diagnostics: #error.diagnostics#">

</body>
</html>

Reviewing the code

The following table describes the highlighted code and its function:

Code

Description

<cflog     type="Error"
  file="myapp_errors"
  text="Exception error
  Exception type: #Error.type#
  Template: #Error.template#,
  Remote Address: #Error.remoteAddress#,
  HTTP Reference: #error.HTTPReferer#
  Diagnostics: #Error.diagnostics#">

When this page is processed, log an entry in the file myapp_errors.log file in the ColdFusion log directory. Identify the entry as an error message and include an error message that includes the exception type, the path of the page that caused the error, the remote address that called the page, and the error's diagnostic message.

A log file entry similar to the following is generated if you try to call a nonexistent custom tag and this page catches the error:

"Error","web-13","12/19/01","11:29:07",MYAPP,"Exception error -- 
      Exception type: coldfusion.runtime.CfErrorWrapper
      Template: /MYStuff/NeoDocs/exceptiontest.cfm,
      Remote Address: 127.0.0.1, 
      HTTP Reference: 
      Diagnostics: Cannot find CFML template for custom tag testCase. Cannot 
      find CFML template for custom tag testCase. ColdFusion attempted looking 
      in the tree of installed custom tags but did not find a custom tag with 
      this name."

The text consists of a comma delimited list of the following entries:


Contents > Developing ColdFusion MX Applications > Handling Errors > Logging errors with the cflog tag PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on May 12, 2004 at 5:40 PM :
I am unable to use the code example to have linefeeds appear in my logfile. The log text is written on one line in the logfile. This makes it quite hard to read. I'm using CFMX 6.1.

Is the code example incorrect?
halL said on May 14, 2004 at 7:02 AM :
This example is incorrect.
At the least, it should have indicated that the line breaks were added to the documentation for legibility and are not in the log file.

ColdFusion does not put return characters from cfolg text in the log file and replaces them with spaces.
Each cflog entry takes up a single line in the log file.

The workaround is to use a unique character or character combination in place of the return in your cflog text and replace the character with a return when you read the file.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/errors25.htm