My CMS logs application errors, and I used to use a <cfhttp> to create a queryable recordset that I would then build an HTML table out of.
Yesterday, our "security" department disabled <cfhttp>, so now I am stuck with only <cffile action="read">. I still want to read the contents of the log file and display them in an HTML table.
Any advice?
P.S. I don't put the errors into the database because we're still stuck using MS Access for our website's database, so I need to keep database hits to a minimum.
First things first, I'd be saying "OI: we're actually using <cfhttp> in our code, you muppets", to the "security" department. And find out from them what the rationale is for disabling it. Even if they do have grounds for disabling it, this should be done after you have refactored your code. Not beforehand.
That said, if they files are in your local system - which I infer they are given you can <cffile> them - I am kinda puzzled why you were using <cfhttp> in the first place:it's far better to use the local filesystem than your web server to fetch file data for you. Plus... it means your logs are web-browseable, which is something the security peeps really ought to be concerned about.
--
Adam
This is on an internal, restricted server that only people within the building have access to. None of it is live.
The reason <cfhttp> is disabled is because the "security" people changed the testing server so that you need to enter a username/password combo to view any pages (sort of like password protected directories in Apache). Since our instance of CF is running as a service (which is yet another discussion), <cfhttp> is denied access. So is our batch HTML validator. So is our link checker.
So that's the skinny.
The reason I was using <cfhttp> to grab the file contents is because it made it really easy to dump that into an HTML table. I'm just not totally sure how to dump a <cffile> read into that same HTML table.
Ok, here's a sample from my cffile read:
Batch contact update for livability|jsmith|{ts '2011-11-07 12:14:34'} Batch contact update for livability|jsmith|{ts '2011-11-07 12:15:14'} Batch title change: /creating_livable_communities/ to 1|jsmith|{ts '2011-11-07 12:16:27'} Edited page details for: Creating Livable Communities (ID: 400834)|jsmith|{ts '2011-11-07 12:17:58'} Edited page details for: Creating Livable Communities (ID: 400841)|jsmith|{ts '2011-11-07 12:18:15'} Edited page details for: Creating Livable Communities (ID: 400842)|jsmith|{ts '2011-11-07 12:18:47'} Edited page details for: Creating Livable Communities (ID: 400843)|jsmith|{ts '2011-11-07 12:19:04'}
It's basically a text file with three entries per line, delimited by a pipe |
I have it somewhat working using <cfloop> with a chr(10) for the delimiter, and listgetat ising the | as the delimiter. The only problem is the aforementioned bug with the last item picking up the date on the next line.
Oops, sorry! I'd meant to do that.
<cfset logpath = expandpath(".") & "\actionlog.txt">
<cffile action="read" file="#logpath#" variable="logfile">
<cfloop index="thisrow" list="#logfile#" delimiters="#chr(10)#">
<tr>
<cfoutput>
<td>#listgetat(thisrow,1,"|")#</td>
<td>#listgetat(thisrow,2,"|")#</td>
<td>#Dateformat(listgetat(thisrow,3,"|"),"dd/mm/yyyy")# #Timeformat(listgetat(thisrow,3,"|"),"h:mm:sstt")#</td>
</cfoutput>
</tr>
</cfloop>
I've left out the superfluous parts of the HTML table.
Your code and sample appear to work. I was able to get a basic sample to work correctly on my local machine. I suspect that the log file may have some empty fields and/or extra line breaks which are causing problems.
I assumed that a line breaks follows the closing curly brace for each record in you sample data.
Here is the code I used:
<!---
http://forums.adobe.com/message/4556466#4556466
--->
<cfset logpath = expandpath(".") & "\actionlog.txt">
<cffile action="read" file="#logpath#" variable="logfile">
<html>
<head>
<title>CFFORUM QUESTION</title>
</head>
<body>
<table border="1">
<cfloop index="thisrow" list="#logfile#" delimiters="#chr(10)#">
<tr>
<cfoutput>
<td>#listgetat(thisrow,1,"|")#</td>
<td>#listgetat(thisrow,2,"|")#</td>
<td>#Dateformat(listgetat(thisrow,3,"|"),"dd/mm/yyyy")# #Timeformat(listgetat(thisrow,3,"|"),"h:mm:sstt")#</td>
</cfoutput>
</tr>
</cfloop>
</table>
</body>
</html>
Sorry, I was away for the weekend and came back to a dozen fires to put out.
BKBK: I tried the #chr(10)##chr(13)# combo previously (and several different flavors of the chr10/13 combo with identical results each time. The third field seems to wrap around to the date.
When I write the file, I use the "addnewline" attribute of cffile:
<cfset errorstring = #error.dateTime# & " | " & #error.remoteAddress# & " | " & #error.template# & " | " & #error.queryString# & " | " & #error.message#>
<cffile action="append"
file="#outputdir##default_topic#.txt"
output="#errorstring#"
addnewline="yes">
Perhaps that's appending something unexpected. Or perhaps I should force my own end-of-line character when I write each line.
It just might be that one or more of the line-break delimiters were not written to file. To test this, mark the position of the line-breaks with "[end_of_line]<BR>", for example. Display the result, and examine whether the line-breaks are where you expect them to be.
I was thinking of something like
<cfset logpath = expandpath(".") & "\actionlog.txt">
<cffile action="read" file="#logpath#" variable="logfile">
<cfset newLog = replaceNoCase(logfile,chr(10),"[en_of_line]<BR>","all")>
<cfoutput>#newLog#</cfoutput>
North America
Europe, Middle East and Africa
Asia Pacific