Hello Kevin,

At 15:22 26.01.2001 -0800, you wrote:
>What is the prefered way to add an Object Renderer?

The preferred way is to use a configuration file. See PropertyConfigurator 
or DOMConfigurator for details.

The javadoc of PropertyConfigurator reads:

ObjectRenderers:

     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:

     
log4j.renderer.fully.qualified.name.of.rendered.class=fully.qualified.name.of.rendering.class

     As in,

     log4j.renderer.my.Fruit=my.FruitRenderer

>As far as I can tell from the javadoc:
>
>{
>     ObjectRenderer myRenderer = new MyRenderer();
>     Object myObject = new MyClass();
>
>     Category root = Category.getRoot();
>     Hierarchy rootH = root.getHierarchy();
>     RendererMap rMap = rootH.getRendererMap();
>     rMap.put(myObject.getClass(), myRenderer);
>}
>
>yet the javadoc also says that most users don't need to deal with
>Hierarchy so I wanted to be sure I'm not missing something.
>
>Why does Category.forcedLog(...) convert the message to a string?  It
>would be nice to have a LoggingEvent holding an Object message rather
>than a String.  Then the appender or LoggingEvent could call either the
>rendering map or .toString() if it needs a string, and preform Object
>storage and output where that is appropriate.
>
>For example, I am logging audit events.  An audit has a number of
>components.  An audit event can be converted to a string, but I am also
>storing these audit events in a database where the components of the
>event are handled separately.  If the appender was sent the Object
>rather than a string this would work great.

This is a know complaint about the log4j design. It has been fixed in the 
code which is in our CVS repository and will be available in log4j version 
1.1. The fixed code gives any appedner/layout access to the raw message 
object. I hope this helps, Ceki

ps: The code in our CVS rep is not guaranteed to be well tested but I 
believe it to work well.

----
Ceki Gülcü - Independent IT Consultant

av. de Rumine 5            Tel: ++41 21 351 23 15
CH-1005 Lausanne        e-mail: [EMAIL PROTECTED]  or
Switzerland                     [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to