There is also the rewriteappender in log4j 1.3 and the ReflectionRewritePolicy that will allow you to write arbitrary objects to the file (you don't have to specify which classes to render in the config file).
http://logging.apache.org/log4j/companions/receivers/apidocs/org/apache/ log4j/rewrite/package-summary.html Scott Deboy Principal Engineer COMOTIV SYSTEMS 111 SW Columbia Street Ste. 950 Portland, OR 97201 Office: 503.224.7496 Direct Line: 503.821.6482 Cell: 503.997.1367 Fax: 503.222.0185 [EMAIL PROTECTED] www.comotivsystems.com -----Original Message----- From: Tim Nguyen [mailto:[EMAIL PROTECTED] Sent: Monday, January 28, 2008 1:54 PM To: Log4J Users List Subject: Re: Write a bean to a file Thanks Curt! That's exactly what I am looking for. ----- Original Message ---- From: Curt Arnold <[EMAIL PROTECTED]> To: Log4J Users List <[email protected]> Sent: Monday, January 28, 2008 1:34:27 PM Subject: Re: Write a bean to a file 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] ________________________________________________________________________ ____________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
