logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <c...@qos.ch>
Subject Re: Adding an ObjectRenderer
Date Mon, 03 Mar 2003 16:33:35 GMT
Ollie,

You mean log4j 1.1.3 not 1.3.1?

In any case, the code add a renderer to a hierarchy is as follows:

import org.apache.log4j.LogManager;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.RendererSupport;
import org.apache.log4j.or.RendererMap;

...

LoggerRepository repo = LogManager.getLoggerRespository();
if(repo instanceof RendererSupport) {
           RendererMap.addRenderer((RendererSupport) repo, Node.class,
                                   nodeRenderer);
}

I hope this helps,

At 04:28 PM 3/3/2003 +0000, Ollie Brady wrote:
>Hi,
>
>I'm porting an application from Log4j 1.1.3 to 1.2.8 but am having a problem
>adding an ObjectRenderer that I wrote.
>
>The ObjectRenderer, NodeRenderer, is used to dump XML nodes to log without
>formatting/altering them.
>
>I would like to add the new renderer without using a config file, i.e. all
>in code.
>
>The old code looked like
>
>     static
>     {
>         Category catRoot = Category.getRoot();
>         catRoot.setPriority(Priority.INFO);
>         Layout layout = new PatternLayout("%d{dd MMM yyyy HH:mm:ss,SSS} %-5p
>%-30.30c %x - %m\n");
>         APPENDER = new ConsoleAppender();
>         ConsoleAppender ca = (ConsoleAppender)APPENDER;
>         ca.setLayout(layout);
>         ca.setName("Console Logger");
>         ca.setWriter(new java.io.OutputStreamWriter(System.out));
>         catRoot.addAppender(APPENDER);
>
>         // create renderer for XML messages
>         ObjectRenderer nodeRenderer = new ObjectRenderer()
>         {
>             public String doRender(Object obj)
>             {
>                 return XMLHelper.nodeToString((Node)obj);
>             }
>         };
>         catRoot.getHierarchy().addRenderer(Node.class, nodeRenderer);
>     }
>
>
>
>So in the new version I have created two classes..
>
>class NodeRenderSupport
>{
>     private RendererMap m_map=new RendererMap();
>
>     public RendererMap getRendererMap()
>     {
>         return m_map;
>     }
>
>     public void setRenderer(Class renderedClass, ObjectRenderer renderer)
>     {
>         m_map.put(renderedClass, renderer);
>     }
>};
>
>class NodeObjectRenderer implements ObjectRenderer
>{
>     public String doRender(Object obj)
>     {
>         return XMLHelper.nodeToString((Node)obj);
>     }
>};
>
>..and then have a line like this in the application..
>
>     static
>     {
>         Category catRoot = Category.getRoot();
>         catRoot.setPriority(Priority.INFO);
>         Layout layout = new PatternLayout("%d{dd MMM yyyy HH:mm:ss,SSS} %-5p
>%-30.30c %x - %m\n");
>         APPENDER = new ConsoleAppender();
>         ConsoleAppender ca = (ConsoleAppender)APPENDER;
>         ca.setLayout(layout);
>         ca.setName("Console Logger");
>         ca.setWriter(new java.io.OutputStreamWriter(System.out));
>         catRoot.addAppender(APPENDER);
>
>         NodeRenderSupport nodeRendererSupport=new NodeRenderSupport();
>         nodeRendererSupport.setRenderer(Node.class, new
>NodeObjectRenderer());
>
>           // How/where to add the NodeRenderSupport??
>
>     }
>
>..but where then do I then add the nodeRendererSupport??  I cannot find
>anywhere to explicitly add the renderer..?
>Any comments welcome.
>
>Regards,
>/OB.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org

--
Ceki 


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


Mime
View raw message