Writing XML Logs

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Wed Apr 11 10:43:19 EDT 2007


Hello Chaps,

 

I'm trying to write an application that will log to an XML file, that'll be
later parsed by another application. The proposed log file will look
something like this, listing different event elements and then a record for
each time that event occurs.

 

<?xml version="1.0" encoding="iso-8859-1"?>

<log>

                <event name="reboot">

                                <detail date="2007-01-01" time="12:00:00" />

                </event>

                <event name="calledhome">

                                <detail date="2007-01-01" time="12:00:00" />

                                <detail date="2007-01-01" time="13:00:00" />

                                <detail date="2007-01-01" time="14:00:00" />

                                <detail date="2007-01-01" time="15:00:00" />

                </event>

                <event name="spotted">

                                <detail address="00:45:GF:WE:3E:10"
date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
date="2007-01-01" time="12:00:00" />

                </event>

                <event name="discovered">

                                <detail address="00:45:GF:WE:3E:10"
channel="10" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
channel="10" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
channel="10" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
channel="10" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
channel="10" date="2007-01-01" time="12:00:00" />

                </event>

                <event name="posted">

                                <detail address="00:45:GF:WE:3E:10"
file="test.jpg" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
file="test.jpg" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
file="test.jpg" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
file="test.jpg" date="2007-01-01" time="12:00:00" />

                                <detail address="00:45:GF:WE:3E:10"
file="test.jpg" date="2007-01-01" time="12:00:00" />

                </event>

</log>

 

What I would really like to do is have a different function for each event,
so logReboot() or something like that which can be called when the
application starts, and it'll create and entry with the current date and
time. This must be a static file that is on the box, allot of the examples
I've seen seem to work using the 'print' function which is a little sketchy
as outputting to the screen isn't any use to me, this needs to be a file
that can be collected by another application.

 

Can anyone offer any advice on how best to get started with this kind of
thing? I'm running python 2.4.4 but when I've tried running any examples
with SAX involved they seem to say 'no module found: sax" or something to
that effect, I was under the impression that sax came bundled with python
2.0 and above?

 

Thanks guys,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070411/45c48d82/attachment.html>


More information about the Python-list mailing list