In developerWorks DataPower Forum thread "Reading log files in datapower"
the question was raised how to read log files in XSLT.
A colleague responded with a first hurdle:
While each log entry in file "logtemp:///default-log-xml" is XML, the whole file is Non-XML because an enclosing document element is missing.
Reason for this is that new log messages can just be appended this way, and even rolling the log does not hurt.
A second hurdle is this logged error when trying to open the log:
"Unsupported URL 'logtemp:///default-log-xml'
OK -- this is a solution to read default-log-xml anyway:
- define a local HTTP service listening on 127.0.0.1:8888 with base directory "logtemp:///"
- read default-log-xml via that HTTP service with <dp:url-open ... response="binaryNode"/>
- extract the Non-XML log "text" from the response and wrap it by "<wrap>...</wrap>"
- store the log messages in a nodeset by "dp:parse(...)/*"
That's all, see the stylesheet in action here:
$ coproc2 log.xsl empty.xml http://firestar:2223 ; echo
404 log entries in total, this is the first one
<date>Wed Jun 27 2012</date>
<message>Domain operational state is up.</message>
And this is the stylesheet log.1.xsl:
In the developerWorks posting it was asked how to read arbitrary log files, just add this here for completeness.
(here are both stylesheets: log.zip
The new stylesheet in action below -- reading the text log file requires parsing the lines, reading the XML log is preferable::
$ coproc2 log.2.xsl empty.xml http://firestar:2223; echo
407 log entries in total, this is the first one
20120627T174757Z [mgmt][notice] domain(default): tid(4911): Domain operational state is up.
And this is the stylesheet log.2.xsl: