logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Muller" <...@online.no>
Subject RE: log4j ObjectRenderer.
Date Mon, 14 Jul 2003 12:02:10 GMT
>From the PropertyConfigurator javadoc:

"You can customize the way message objects of a given type are converted to
String before being logged. This is done by specifying an ObjectRenderer for
the object type would like to customize.
The syntax is:

As in,

This means that for your ResultObject class you need to write a
ResultObjectRenderer class implemeting the
org.apache.log4j.or.ObjectRenderer interface, and register the renderer in
the config file in order for Log4j to recognize it, e.g:


This will instruct Log4j to use an instance of ResultObjectRenderer to
stringify ResultObject instances instead of using the default toString()
method. Note that ResultObjectRenderer must have a public default

Hope this helps.



| -----Original Message-----
| From: write2vishu [mailto:write2vishu@tatanova.com]
| Sent: 01 January 1601 00:00
| To: log4j-user@jakarta.apache.org
| Subject: log4j ObjectRenderer.
| Hi,
| I am working on log4j for some project.
| Currently in the project,the outgoing and incoming messages are logged
| as Strings via 'resultObject.toString()'.This doesn't allow the use of
| Log4J Object Renderers.I want to log the message as
| 'resultObject' Object itself so that
| ObjectRenderers can be used to format the output as required.
| I have done the following changes in the java file.
| Note :- This is a patch of java code specific to log4j from the source
| code.
| ------------------------------------------------------------------
| ------------// File : example.java
| package com.core.client;
| //Following package i have imported for log4j.
| import org.apache.log4j.Category;
| import org.apache.log4j.PropertyConfigurator;
| import org.apache.log4j.or.RendererMap;
| import org.apache.log4j.or.ObjectRenderer;
| private static Category log = Category.getInstance(example.class);
| //Changed the log.debug( resultObject.toString() ) statements to
| log.debug(resultObject);
| ------------------------------------------------------------------
| ------------Do i need to make any more changes in the java file
| to use Object
| Renderer ?
| I found in the log4j document that we need to make following entry in
| the log4j.properties file :-
| log4j.renderer.my.package.name.MyClassToLog=my.otherpackage.name.M
| yRendererClass
| But i couldn't understand what should be 'my.package.name.MyClassToLog'
| and 'my.otherpackage.name.MyRendererClass' for the above given java file?
| Any help on this will be appreciated.
| Thanks & Regards,
| Vishweshwar.
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: log4j-user-help@jakarta.apache.org

Copyright ERA Technology Ltd. 2003. (www.era.co.uk). All rights reserved. 
The information supplied in this Commercial Communication should be treated
in confidence.
No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit

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

View raw message