Logging Errors in the Log File Using the cflog Tag


Logging Errors in the Log File Using the <cflog> Tag

ColdFusion allows you to use the <cflog> tag to log errors to the log file. This tag specifies

  • The standard ColdFusion log or custom file to write the error.

  • The text to be written to the log file. This text can take values of error and <cfcatch> variables.

You can control the writing of an error to the log file. By default, the system logs all the errors. You can specify the severity of the log message—that is, whether it's an information, fatal, warning, or error type.

These are the attributes of the <cflog> tag:

  • Type. Allows you to specify the severity type of the message. This can be information, warning, error, or fatal.

  • Text. Permits you to accept the data to be written to the log file. Text is the only required attribute; all others are optional.

  • File. Specifies the name of the file in which data is to be logged. If this file isn't specified, errors are logged in the standard log file. You cannot specify the directory path here. The file must reside in the default log directory. Alternately, it creates a file with the suffix .log.

  • Log. Allows you to specify the log type. Log type can be Application (used for application-specific messages) or Scheduler (used for scheduled tasks).

  • Application. Decides whether you can log the application name. You can assign Boolean values for this attribute.

The following is the syntax for the <cflog> tag:

 <CFLOG TYPE="fatal"        TEXT = "the text of the error message including error variable for                example Template: #error.template#"        Application ="yes or no"        Log = "Application"        FILE = "name of the error file" > 

Note

The thread, date, and time attributes of <cflog> are deprecated in ColdFusion MX. They might not work properly and may cause errors in later releases. In earlier releases, the thread, date, and time attributes determined whether the respective data items were written to the log. In ColdFusion MX, this data is always written.

The following code logs error details:

 <HTML> <HEAD><TITLE>Sample Site-wide template </TITLE></HEAD> </HTML> <BODY>     An error occurred while accessing this. We have informed the engineer,     please try later. Sorry for the inconvenience.     <!--- Send a mail to the developer notifying the problem and tell him to     correct it-- >     <CFMAIL TO="Developer@organisation.com" from=site-wide@org.net              subject="an error occurred while accessing the page">       Dear developer,       An error occurred while accessing this page. The error information is as       follows.       IP address of the client: #error.remoteaddress#       Date and time of the problem: #error.datetime#       The template that caused the error: #error.template#       Error text: #error.diagnostics#       <!--- You can log the same information using cflog tag --- >       <CFLOG text="The site wide error handler found and error the details of                    which are: IP address of the client: #error.remoteaddress#                    Date and Time of the problem: #error.datetime#                    The template that caused the error: #error.template#                    Error text: #error.diagnostics#"              TYPE="warning" file="webpageerrror"> </BODY> </HTML> 




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net