Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11104
| From | Tom Anderson <twic@urchin.earth.li> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Logging Question |
| Date | 2012-01-08 14:08 +0000 |
| Organization | Stack Usenet News Service |
| Message-ID | <alpine.DEB.2.00.1201081402300.20221@urchin.earth.li> (permalink) |
| References | (5 earlier) <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> <N86Nq.17333$d52.16770@newsfe22.iad> |
On Wed, 4 Jan 2012, Arved Sandstrom wrote:
> On 12-01-03 11:33 AM, Tom Anderson wrote:
>> On Sun, 1 Jan 2012, Arved Sandstrom wrote:
>>
>>> 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?
>> 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".
Okay.
> 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(
Always good to see 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++];
> }
>
> });
Perhaps easier to do Collections.enumeration(Arrays.asList(bsBegin, in, bsEnd)).
> 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.
Yes, good trick. As a general pattern (topping and tailing some stream of
items with start-container and end-container markers), it's useful in all
sorts of places. Admittedly most when dealing with XML.
> Completely different approach, and it might even be the most "valid"
> approach, would be to consider each log "record" to be an XML fragment.
Is there any support for getting parsers to parse multiple fragments from
a single stream? If not, we're back to needing to frame the stream in some
way, and then we might as well parse it as a sequence of documents. I'm
pretty hazy on what the point of document fragments is, really.
tom
--
music is a interesting thing, DUN COMPARE AND PUT IT TO BLAR BLAR GENRE,
THIS IS A STUPID ACT......MUSIC IS SAME TO EVERYONE -- sihamze
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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