Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How can I read and write ColdFusion .log files?

ColdFusion log files are a form of text files that end in the .log extension and must be saved inside of the ColdFusion log directory. Although you can use <cffile> to read and write ColdFusion log files by hand, ColdFusion provides tools designed just for this specific task. To read the files, use the ColdFuson administrator (under Debugging & Logging), and to write/update the files, use the <cflog> tag . These handy shortcuts will save you most of the work associated with manipulating ColdFusion log files.

Using <cflog> is easy. You set the contents of the message to be written to the log file by way of the required text attribute. If you wish to use one of the default ColdFusion log files, you set the log attribute equal to either application or scheduler, depending on which of the two logs you wish to write to. If you wish to write to a custom log file, then you set the file attribute to the name (not including the .log extension) of the log file you wish to use. The type attribute is used to set the severity of the log entry. Valid values for this attribute include: information (default), warning, error, and fatal Information. Finally, the Optional application attribute can be set to either yes (default), or no. If application is set to yes, then the application name will be added to the log file.

The following sample code could be used to add a dynamic entry (based on form data) to a custom log file every time a new member registered on your site:

<cflog file="newUserLog"
application="No"
text="User #form.userName# joined the site.">


This question was written by Jeremy Petersen.
It was last updated on February 2, 2006 at 5:28:20 PM EST.

CFML Referenced

<cffile>
<cflog>

Categories

File and Directory Access

Comments

Comment made by Jason Fill on February 2, 2006 at 5:15 PM
I believe the attribute should read "application" not "spplication". Pretty obvious but just wanted to point it out.


Comment made by Jeremy on February 2, 2006 at 5:37 PM
Fixed. Thanks!


Comment made by Chad on February 11, 2006 at 11:23 PM
Has anyone found a good way to maintain the cfusion-out.log file? I have some processes setup to stop cf, delete the log (or rename it) and then start cf again. That comes with a cost however.