How to read ColdFusion log files directly from your app

Written on 16 October 2011, 01:41am

Tagged with: ,

CFLOG is a very useful tool for debugging. Along with CFDUMP, it is probably one most used tags in development 🙂
Logging with CFLOG is extremely simple:

<cflog file="myLogFile" text="#TimeFormat(Now(),'hh:mm:ss.l')#: log message" />

I am usually prepending the timestamp to get the milliseconds (by default, CF only logs the time down to the seconds):

"Information","web-261","10/13/11","06:03:21","APP","06:03:21.319: log message"

About the other attribute of the CFLOG: file, the CF documentation says:

Message file. Specify only the main part of the filename. For example, to log to the Testing.log file, specify “Testing”.
The file must be located in the default log directory. You cannot specify a directory path. If the file does not exist, it is created automatically, with the extension .log.

The log file is created inside the ColdFusion default log directory. You can see the content of this file using the ‘Log files’ screen of your CF Admin interface:

But what do you do when you don’t have access to the CF Admin interface? Luckily, you can still see the contents of your log file. You just have to locate the log folder contents and then output the log file contens, as the following script shows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Read log</title>

<cfsetting showdebugoutput="no" requesttimeout="200" />
<!--- quick and dirty way of getting the file separator --->
<cfif find('/',Server.ColdFusion.RootDir)>
	<cfset s='/'>
	<cfset s='\'>
</cfif>   >
<cfset logsFile = Server.ColdFusion.RootDir & "#s#logs#s#yourFile.log">
<cfif not fileExists(logsFile)>
	<h3>Error: log file #logsFile# does not exist</h3>
	<cfabort />
	<h3>Showing contents of #logsFile#</h3>


myfile = FileRead(logsFile);

Comments (2)

  1. Ty Whalin — February 17, 2013 at 19:55

    After lots of research surrounding the onMissingTemplate function, cflog, and creating a custom error log, it became very event that the information you have would be great except for the fact that you must be on a server that is not shared. Hosting companies do not seem to allow for log file reading by the cffile tag.

    This is unfortunate since I am using the cflog tag in my application.cfc file and it does not allow me to read the .log file created during error logging. So my solution was to just write the errors to different errorlog files depending on the type of error and then outputting the error to the corresponding page such as 400, 401, 403, 404, 500 etc…

    This was the only solution I could create for getting around the issue concerning a shared hosting environment.


  2. Katie — March 22, 2014 at 00:32

    It also seals the blood vessels to reduce any bleeding that might occur.
    Some respond to certain types of treatment, while others are notoriously difficult to treat.
    In any case, the treatment of warts is necessary
    regardless of whether this is a cosmetic or much more
    dangerous problem.


Leave a response