Re: Logging Question
On Sun, 1 Jan 2012, Arved Sandstrom wrote:
On 12-01-01 08:59 AM, Jeff Higgins wrote:
On 01/01/2012 06:33 AM, Stefan Ram wrote:
Novice<novice@example..com> writes:
Yes! I simply copied XMLFormatter from the Java source file, added one
A log file should remain usable even when the process was terminated
abnormally. But an XML file needs to have one single root element
that has an end tag at its end. A process that is being terminated
abnormally might not write such an end tag. So, one has no guarantee
that the log output is well-formed XML. Or did I miss something?
Only that there are no guarantees.
<http://docs.oracle.com/javase/7/docs/technotes/guides/logging/overview.html#a1.12>
And let's face it, the <log> document element in this case is useless.
It conveys zero information. It would better to regard each record as a
separate well-formed XML document, and the file is merely physical
storage for a bunch of log records.
What happens if you throw such a file into a normal XML parser?
I would imagine that if you're using StAX, you can stop parsing when you
hit the end of a root element, and then either carry on to the next one,
or perhaps wrap a fresh parser round the underlying input stream.
I have no idea what a SAX parser would do; i don't know how much
well-formedness checking they do.
What would a DOM parser do?
You might need to interpolate a layer between the parser and the
FileInputStream to notionally split the file into substreams, one per
document. That would require some sort of framing format for the file, i
think.
This kind of XML "wrapper" element, as in <log> in this case, happens
when folks think that 1 XML document == 1 physical file. An XML document
entity is a logical, not a physical storage, concept.
Well, it is physical (quoth the spec: "Each XML document has both a
logical and a physical structure."), but it's a physical thing distinct
from a file, and doesn't have to map directly on to it. The spec says "A
data object is an XML document if ..." and "A textual object is a
well-formed XML document if ...", but never gets any more specific than
that.
tom
--
I heard this from two different reliable sources on newsgroups. --
Peter Olcott