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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to