Re: How to use log4r to generate xml format log file?

I want to use log4r to generate xml formatted log file

Aside: is there a standard way of using XML for log files? I had a need
for
writing structured data to a log a while ago, and considered XML, but
rejected it on the grounds that anything which appends is always going
to
generate invalid (i.e. not-well-formed) XML. For example:

foo bar

This is malformed because it has more than one root node, and therefore
will
be rejected by just about any XML parser. Similarly,

foo bar

is also malformed, until such time that you append the closing

tag (but at that point you can no longer append any more logs to that
file).

Regards,

Brian.

That’s a good point. Nevertheless log4j does offer an XMLAppender.

It logs in ‘XMLfragments’ though - its up to you to complete the XML doc
when you come to parse the log though.

The Jabber chat/messaging (xml-router in fact) has the same issue: it
also sends information back and forth as XML-frags - you have to put
them back together at some point to make valid XML.

Brian C. wrote:

I want to use log4r to generate xml formatted log file

Aside: is there a standard way of using XML for log files? I had a need
for
writing structured data to a log a while ago, and considered XML, but
rejected it on the grounds that anything which appends is always going
to
generate invalid (i.e. not-well-formed) XML. For example:

foo bar

This is malformed because it has more than one root node, and therefore
will
be rejected by just about any XML parser. Similarly,

foo bar

is also malformed, until such time that you append the closing

tag (but at that point you can no longer append any more logs to that
file).

Regards,

Brian.

That’s a good point. Nevertheless log4j does offer an XMLAppender.

It logs in ‘XMLfragments’ though - its up to you to complete the XML doc
when you come to parse the log though.

Does that mean it just appends fragments without a root element? So to
parse
it, you have to prepend a and append a first?

The Jabber chat/messaging (xml-router in fact) has the same issue

Not exactly: it sends a root element, and because it’s a stream, the
receiver blocks waiting for more data.

... ... <---- at this point a stream parser waits for either the closing or another

When the other side wants to close the connection it sends
then
disconnects.

So taking the entirety of the stream, from when it starts to when it is
finished, it is valid XML and it can be parsed using a normal parser.

Regards,

Brian.