quick and dirty scripting job that should convert all .log files to plain text in DAY HOUR NAME: MESSAGE format (files are created next to the .log files). In case you want some other format, point out which fields from that xml you want.
If you need something more specific eg clumping all files of a given contact into 1 big file or moving converted files somewhere i can upgrade it but i would need more info about the directory structure and naming conventions to figure out proper solution.
empathy_logs.sh:
Code:
#!/bin/bash
logpath=. # put proper path here
while read -rd $'\0' f
do
echo "converting $f"
python empathy_logs.py "$f" > "$f.txt"
done < <( find "$logpath" -iname '*.log' -print0 )
empathy_logs.py:
Code:
#!/usr/bin/env python
import sys
from xml.etree.ElementTree import parse
xmldoc = parse( sys.argv[1] )
root = xmldoc.getroot()
for child in root:
time = child.attrib["time"]
time = time[0:4]+"-"+time[4:6]+"-"+time[6:8]+" "+time[9:17]
name = child.attrib["name"]
msg = child.text
print "%s %s: %s" % ( time, name, msg )
bash script is just a wrapper around the python script
example with 2 dummy log files:
Code:
$ cat test*.log
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="log-store-xml.xsl"?>
<log>
<message time='20110611T11:55:33' id='[id]' name='[name1]' token='[string of characters]' isuser='false' type='normal'>some message</message>
<message time='20110611T11:55:36' id='[id]' name='[name4]' token='[string of characters]' isuser='false' type='normal'>some other message &<'</message>
</log>
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="log-store-xml.xsl"?>
<log>
<message time='20110611T11:55:33' id='[id]' name='[name1]' token='[string of characters]' isuser='false' type='normal'>abc</message>
<message time='20110611T11:55:34' id='[id]' name='[name2]' token='[string of characters]' isuser='false' type='normal'>def</message>
<message time='20110611T11:55:35' id='[id]' name='[name3]' token='[string of characters]' isuser='false' type='normal'>ghi</message>
<message time='20110611T11:55:36' id='[id]' name='[name4]' token='[string of characters]' isuser='false' type='normal'>jkl</message>
</log>
$ ./empathy_logs.sh
converting ./test1.log
converting ./test2.log
$ cat test*.log.txt
2011-06-11 11:55:33 [name1]: some message
2011-06-11 11:55:36 [name4]: some other message &<'
2011-06-11 11:55:33 [name1]: abc
2011-06-11 11:55:34 [name2]: def
2011-06-11 11:55:35 [name3]: ghi
2011-06-11 11:55:36 [name4]: jkl
Bookmarks