If you’ve ever logged anything in “human readable” format from the OSX IRC client Colloquy, you’re probably used to seeing the logfiles in XML format, similar to this:
<event id="XXXXXXXXXXX" name="memberNewNickname" occurred="2013-01-02 12:00:00 -0500"> <message>user1 is now known as <span class="member">user1|afk</span>.</message> <old>user1</old> <who hostmask="user1@X">user1</who> </event>
Not bad when there’s only a few entries, but with multiple logfiles containing thousands of entries each, it can chew up time and eat away at system resources. Wouldn’t it be nice if it looked more like this?
[12:00pm] user1 is now known as user1|afk.
Well, tonight I needed to go back and look for something in an old log, and parsing through the format of the log made it difficult to do with a simple grep command (note: I said simple). After some poking around I ran across a pretty simple, yet elegant solution: xsltproc.
From the project description: “It takes as first argument the path or URL to an XSLT stylesheet, the next arguments are filenames or URIs of the inputs to be processed. The output of the processing is redirected on the standard output.“. Yep, that’s what we need.
I found a pretty good PlainText.xsl file in a Google cache copy of a defunct add-ons page for Colloquy (it could use some improvements though, it only displays the time – no date. I’ll work on that), you can grab it here.
xsltproc /path/to/PlainText.xsl /path/to/channel.colloquyTranscript
The result? A nicely displayed logfile.