Skip navigation
Currently Being Moderated

Querying a CFFILE read

Jul 11, 2012 6:47 AM

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.

 
Replies
  • Currently Being Moderated
    Jul 11, 2012 7:07 AM   in reply to BreakawayPaul

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 11:12 AM   in reply to Adam Cameron.

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 12, 2012 7:07 AM   in reply to BreakawayPaul

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2012 7:02 AM   in reply to BreakawayPaul

    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. "

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2012 7:31 AM   in reply to BreakawayPaul

    Perhaps you could post the relavent code to go with the sample data.  This would help in troubleshooting your problem.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2012 12:11 PM   in reply to BreakawayPaul

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 14, 2012 12:37 AM   in reply to BreakawayPaul

    Your code looks all right to me. Does this solve your problem:

     

    delimiters="#chr(10)##chr(13)#"

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2012 8:35 AM   in reply to BreakawayPaul

    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>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points