Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11073

Re: Logging Question

From Arved Sandstrom <asandstrom3minus1@eastlink.ca>
Newsgroups comp.lang.java.programmer
Subject Re: Logging Question
References (4 earlier) <Xns9FCD791489D5jpnasty@94.75.214.39> <XML-logger-20120101123319@ram.dialup.fu-berlin.de> <jdpkvp$jgd$1@dont-email.me> <QF5Mq.54294$cN1.19557@newsfe12.iad> <alpine.DEB.2.00.1201031525230.2163@urchin.earth.li>
Message-ID <N86Nq.17333$d52.16770@newsfe22.iad> (permalink)
Organization Public Usenet Newsgroup Access
Date 2012-01-04 20:28 -0400

Show all headers | View raw


On 12-01-03 11:33 AM, Tom Anderson wrote:
> 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.

One thing that works with stream parsing is to fool the parser with a
fake starting document element tag...like <log>. :-) Given that, SAX or
StAX will parse forever, or until end of file/stream anyway.

If you didn't fake out the parser it would choke with a well-formedness
error after the first "record".

You can get quite innovative (read hackish) by doing stuff like:

final ByteArrayInputStream bsBegin =
  new ByteArrayInputStream("<wrapper>".getBytes());
URL fileUrl = new URL(...);
final InputStream in = fileUrl.openStream();
final ByteArrayInputStream bsEnd =
  new ByteArrayInputStream("</wrapper>".getBytes());

SequenceInputStream sis = new SequenceInputStream(new Enumeration() {

  int index = 0;
  InputStream streams[] = new InputStream[] {bsBegin, in, bsEnd};
			
  @Override
  public boolean hasMoreElements() {
    return index < streams.length;
  }

  @Override
  public Object nextElement() {
    return streams[index++];
  }
			
});

XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader parser = factory.createXMLStreamReader(sis);

**********
The point here being is that the "real" input wasn't well-formed at all,
but by the time the parser sees it, it's fine.

Any of your ideas would be cool, too. After all we are just trying to
get a job done.

> What would a DOM parser do?

It fails when the underlying stream parsing fails, I would think.

> 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
> 
Completely different approach, and it might even be the most "valid"
approach, would be to consider each log "record" to be an XML fragment.
But I wouldn't actually contemplate doing things that way, I'd
pre-process somehow, using the ideas we've already brought out.

AHS

-- 
...wherever the people are well informed they can be trusted with their
own government...
-- Thomas Jefferson, 1789

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Logging Question Novice <novice@example..com> - 2011-12-31 21:27 +0000
  Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2011-12-31 17:25 -0500
    Re: Logging Question Novice <novice@example..com> - 2012-01-01 01:46 +0000
  Re: Logging Question Lew <lewbloch@gmail.com> - 2011-12-31 14:53 -0800
    Re: Logging Question Novice <novice@example..com> - 2012-01-01 01:59 +0000
      Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2011-12-31 22:14 -0500
        Re: Logging Question Novice <novice@example..com> - 2012-01-01 05:44 +0000
          Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-01 07:59 -0500
            Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-01 08:14 -0500
            Re: Logging Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-01 19:06 -0400
              Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-01 18:24 -0500
              Re: Logging Question Tom Anderson <twic@urchin.earth.li> - 2012-01-03 15:33 +0000
                Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-03 11:21 -0500
                Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-03 11:35 -0500
                Re: Logging Question Tom Anderson <twic@urchin.earth.li> - 2012-01-04 14:42 +0000
                Re: Logging Question Jeff Higgins <jeff@invalid.invalid> - 2012-01-04 11:43 -0500
                Re: Logging Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-04 20:28 -0400
                Re: Logging Question Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-01-05 11:28 +0200
                Re: Logging Question Tom Anderson <twic@urchin.earth.li> - 2012-01-08 14:08 +0000
                Re: Logging Question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-09 19:47 -0400

csiph-web