Analyzing log files in the ColdFusion folder

The problem is that there is a ./log/ folder containing files such as:

 jan2010.xml, feb2010.xml, mar2010.xml, jan2009.xml, feb2009.xml, mar2009.xml ... 

every xml file would like to:

 <root><record name="bob" spend="20"></record>...(more records)</root> 

I want to write a piece of ColdFusion code ( log.cfm ) that simply parses these XML files. To start, I would let the user select the year, and then the send button. All content this year will be displayed in a separate table by month. Each table shows the total money spent on each person. as:

 person cost bob 200 mike 300 Total 500 

Thanks.

+3
source share
3 answers

The short answer is that if your XML is formatted correctly, you can use the XMLParse () function to get the XML into the CF data object.

Sergius noted that XMLParse cna has a path, so you can just read the file directly in it and assign the results to a variable.

The data should look like an array of structures. Use CFDUMP on a CF data object to view it and help you figure it out.

+2
source

I would urge you to check Microsoft "Log Parser" if you are on Windows. It provides an essentially SQL-like query interface to all log formats. There is an application called “Log Parser Lizard” that provides a graphical interface for testing “queries”, and then you can cfexecute logparser with the queries you came up with.

Not sure if there is an equivalent for linux.

If you are running Windows and want to know more, let me know. I connected it to the ANT task, which downloaded the log files every night, analyzed them, generated reports, etc. He worked very well.

0
source

Specific example:

 <CFSET year = 2011 /> <CFDIRECTORY directory="#expandpath("log")#" action="list" sort="name" name="logfiles" filter="*#year#.xml" /> <CFOUTPUT query="logfiles"> <CFSET singlelogfile = xmlparse(directory & "/" & name) /> <CFSET records = XmlSearch(singlelogfile, "//record") /> <table> <tr><td colspan="2">Month: #left(logfiles.name,3)#</td></tr> <CFLOOP array="#records#" index="record"> <tr><td>#record.XmlAttributes.name#</td><td>#record.XmlAttributes.spend#</td></tr> </CFLOOP> </table> </CFOUTPUT> 

Of course, you will need to change that year comes from FORM-Scope, summarize several records for each person and, possibly (if you can control it), change the name of the file from the logs to 01-2011 022.03 -2011, .. 12-2011 so that they are sorted correctly correctly.

0
source

Source: https://habr.com/ru/post/1310138/


All Articles