You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Tim Nguyen <ti...@yahoo.com> on 2008/01/28 20:24:42 UTC

Write a bean to a file

Hi,

I am a newbie of Log4j. I wonder if anyone has an example or an utility of how to write a bean to a file using Log4j. Thank you!




      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

Re: Write a bean to a file

Posted by Curt Arnold <ca...@apache.org>.
On Jan 28, 2008, at 1:24 PM, Tim Nguyen wrote:

> Hi,
>
> I am a newbie of Log4j. I wonder if anyone has an example or an  
> utility of how to write a bean to a file using Log4j. Thank you!
>
>

Not quite sure what you are asking.  You can pass any Object as the  
message parameter.  Unless you register an ObjectRenderer for that  
specific type, then that Object's toString() method will be called to  
get a rendered string for formatting.  If you register an  
ObjectRenderer, then that class will be used to create the text  
representation of the object.


That is:

SomeBean bean = ....
logger.info(bean);

is typically equivalent to:

SomeBean bean = ....
logger.info(String.toString(bean));

You can specify an class implementing  
org.apache.log4j.or.ObjectRenderer to be used to render a specific  
class by configuring it in the configuration file or  
programmatically.  Programmatically, should look something like:

((org.apache.log4j.or.RendererSupport)  
logger.getRepository()).addRenderer("com.example.MyBean", new  
MyBeanRenderer());

I'm not sure how it would look in a configuration file and can't find  
a ready example, but I'm not going to dig on it unless that is what  
you want to do and nobody else speaks up.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org