I for myself do such things when preparing the log message, i.e.:
if (myLog.isDebugEnabled())
{
myLog.debug( "received binary data:\n" + Conversions.byteArrayToHexDump(
myByteArray ) );
}
Annother apporach is to write your own renderer. In this case you would have
also to define an own class which transports the message and binary data
through the log4j layers until it reaches your renderer.
Configuration:
Code:
if (myLog.isDebugEnabled())
{
BinaryWrapper wrap = new BinaryWrapper( "received binary data", myByteArray
);
myLog.debug( wrap );
}
When log4j is about to convert the supplied Object to String, it will call your
BinaryRenderer supplying your BinaryWrapper instance. Remember: the formal
parameter of Logger.debug etc. is an Object and not a String. If no renderer
for a particular class is configured, log4j just calls toString() of the
supplied Object otherwise it calls the configured renderer.
Heri
> -Original Message-
> From: news [mailto:[EMAIL PROTECTED] Behalf Of teknokrat
> Sent: Monday, March 17, 2008 2:06 PM
> To: log4j-user@logging.apache.org
> Subject: [SPAM (Bayesain Analysis)] - How to log binary data
> - Bayesian
> Filter detected spam
>
>
> I have a requirement to log raw binary data. This will be
> mostly ASCII
> characters but will contain non-displayable control
> characters such as
> \0, etc. My first thought was to write an appender by extending the
> FileAppender class but I cannot see how to do this as I need
> access to
> an OutputStream and not a Writer. Does anyone have any good
> ideas of how
> this can be done witht he minimum of fuss in log4j?
>
> cheers
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]