Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ok, I sort of have things working using <cffile>, <cfloop>, and listgetat(). A few bugs (like listgetat(list,5,"|") reads the beginning item of the next like) but I'm working on them.
Copy link to clipboard
Copied
Regardiing:
I am kinda puzzled why you were using <cfhttp> in the first place
Using cfhttp with a name attribute gives you a query object. Depending on what you intend to do next, it might be simpler to do so with a query object.
Copy link to clipboard
Copied
Well if I do it, there's probably a better way (or three).
<cfhttp> has a columns attribute that makes it easy to convery a file read into a query. That's really the only reason I was using it. It made it easy to limit the number of columns I was displaying in the HTML table.
Copy link to clipboard
Copied
Go ahead. Do your cffile-read. Output the result. Bring it to the forum, and I am sure you will get tips on how to display it using HTML.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Your code sounds sort of ok in theory but if it isn't giving the expected results it obviously isn't, Please post this part:
"I have it somewhat working using <cfloop> with a chr(10) for the delimiter, and listgetat ising the | as the delimiter. "
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Your code looks all right to me. Does this solve your problem:
delimiters="#chr(10)##chr(13)#"
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Not a bad idea. I'll try that tomorrow when I get in to the office, thanks.
Copy link to clipboard
Copied
Perhaps you could post the relavent code to go with the sample data. This would help in troubleshooting your problem.