Heikki,

Thanks for the suggestion - sounds an interesting option.

Was looking at the various *FileAppender* classes and wondered if I could just 
sub-class them, override requiresLayout() to return false, and override append() 
to just serialize the event to the open file/stream. If I get a chance, I may 
experiment along these lines and post the results.

-- Rob

> In my current project, we have a client application that needs to write all
> logging events to a file in serialized form. Later, that file is sent to the
> server that writes all the events from the file to a database.
> 
> I hacked together a Layout-class (attached), that serializes the event and
> base64-encodes it. That way, you can use it with any of the Appenders that
> accept a layout.
> 
> Feel free to use it, I hope you find it useful.
> 
> The serialized events are read in a loop in this method:
> 
> public void readAndLog(InputStream is) throws IOException,
> ClassNotFoundException {
>       byte[] b = decoder.decodeBuffer(is);
> 
>       ByteArrayInputStream bais = new ByteArrayInputStream(b);
> 
>       while(bais.available() > 0) {
>               ObjectInputStream ois = new ObjectInputStream(bais);
>               LoggingEvent event = (LoggingEvent) ois.readObject();
> 
>               logger.callAppenders(event);
>       }
> }
> 
> It would be nice to use XML for the serialization instead of the java
> serialization and base64 encoding. I didn't bother because this hack did the
> trick for us. The base64-encoded files look like gibberish, but you can add
> another appender to the logger with some human-readable layout if you want
> to.
> 
> - Heikki
> 
> -----Original Message-----
> From: Rob Walker [mailto:[EMAIL PROTECTED]] 
> Sent: 13. helmikuuta 2002 14:53
> To: [EMAIL PROTECTED]
> Subject: Serialized event logging
> 
> 
> There's probably an easy answer to this one. 
> 
> The preferred "file" format we'd like to use to log our events in is as
> serialized 
> LoggingEvent objects (since we're a server, and we'd like to leave 
> layout/formatting/filtering down to the viewer of the log when it's
> browsed).
> 
> It looks an easy task, but we'd also like similar facilities to the various 
> FileAppenders/RollingFileAppenders etc. in terms of buffered i/o and
> rollover. 
> Seems a shame to have to re-do all of this code, just to get an
> "unlayed-out" 
> object.
> 
> Anyone played with this area at all or got any thoughts?
> 
> -- Rob Walker
> SoftSell Business Systems, Ltd.
> ' testing solutions for a changing world '
>  
> +44 (20) 7488 3470
> www.softsell.com
> [EMAIL PROTECTED]
> 
> 
> 


SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to