Hi: Can any one confirm to me it's working to call doRender() method. I'll appreciate if you can provide me a successful example if you do make it work. I use log4j-1.2.14 in RAD6 and put log4j.xml in the WEB-INF/classes folder and I'm sure the added <renderer> has been loaded.
I tried the complete example from http://www.java2s.com/Code/Java/Language-Basics/log4jAcompleteexample.htm but the doRender() was never got called and it's not calling to my own test to add <renderer> to the log4j.xml and extend ObjectRenderer in my render class with doRender() method. I just have to know if this is the right way to call doRender() and capture the message to change it. I tried what Ron has suggested me to use LoggingEvent object to filter the message to do getMessage() and getRenderedMessage(). but it's not good to me since there are no setRenderedMessage() to alter the message that I want to return. Thanks. Naider log4j: Threshold ="null". log4j: Rendering class: [com.apress.logging.log4j.renderer.OrderRenderer], Rendered class: [com.apress.business.CustomerOrder]. log4j: Level value for root is [debug]. log4j: root level set to DEBUG log4j: Class name: [org.apache.log4j.ConsoleAppender] log4j: Setting property [threshold] to [DEBUG]. log4j: Parsing layout of class: "org.apache.log4j.PatternLayout" log4j: Setting property [conversionPattern] to [%d %-5p [%t] %C{2} (%F:%L) - %m%n]. log4j: Adding filter of type [class com.test.logging.log4j.filter.MyStringFilter] to appender named [STDOUT]. log4j: Adding appender named [STDOUT] to category [root]. enter MyDemo %%%enter DtccStringFilter decide %%%DTCC getMessage string is captured *test this string* %%%DTCC getRenderedMessage string is captured *test this string* 2007-06-06 10:52:25,551 INFO [main] log4j.MyDemo (MyDemo.java:20) - test this string --- Naider Chen <[EMAIL PROTECTED]> wrote: > Thanks Ron: > > Thank you for your reply and I really appreciate it. > > > May be The getRenderedMessage method in the > LoggingEvent is another place that I can intercept > the > log message. But I'm just beginning to look how to > use log4j and I need to do some more research to > find > out how do I overwrite the getRenderedMessage method > to scan and pre-process the message. Can I extend > the > LoggingEvent and do something to have log4j use my > child LoggingEvent method so that I can do what I > need > to do with the message. > > > What I really need to do is to create a utilities to > be used to plug in to the application code so that > all > the log message can be scanned/pre-processed before > sending to the Appender. And of course the > application code need to do the little the better. > > > I'm sure the added <renderer> tag in my log4j.xml is > loaded in my server but what I don't understand is > that the doRender method is not get called. Could > that be because a String object is been bypassed > because it's already a String so that there is no > need > to render it again? I thought the doRender(object > o) > will catch all the object. Is this right? > > > It this doRender approach the deadend to intercept > the > message or I can still catch a String object in > doRender? > > > I have changed the renderedClass="java.lang.Object" > to > Object instead of String but it's the same thing > doRender method print statement can't be found in my > consoleAppender. > > <log4j:configuration > xmlns:log4j="http://jakarta.apache.org/log4j/" > debug="true"> > <renderer renderedClass="java.lang.Object" > renderingClass="test.log4j.LogCatcher"/> > > > Here's the ocnsole log that shows the new <renderer> > tag showned in the logger. > > [6/1/07 15:28:09:453 EDT] 0000002a SystemOut O > log4j: Rendering class: [test.log4j.LogCatcher], > Rendered class: [java.lang.Object]. > [6/1/07 15:28:09:453 EDT] 0000002a SystemOut O > log4j: Level value for root is [debug]. > [6/1/07 15:28:09:453 EDT] 0000002a SystemOut O > log4j: root level set to DEBUG > [6/1/07 15:28:09:469 EDT] 0000002a SystemOut O > log4j: Class name: > [org.apache.log4j.ConsoleAppender] > [6/1/07 15:28:09:500 EDT] 0000002a SystemOut O > log4j: Setting property [threshold] to [DEBUG]. > [6/1/07 15:28:09:500 EDT] 0000002a SystemOut O > log4j: Parsing layout of class: > "org.apache.log4j.PatternLayout" > [6/1/07 15:28:09:657 EDT] 0000002a SystemOut O > log4j: Setting property [conversionPattern] to [%d > %-5p [%t] %C{2} (%F:%L) - %m%n]. > [6/1/07 15:28:09:657 EDT] 0000002a SystemOut O > log4j: Adding appender named [STDOUT] to category > [root]. > [6/1/07 15:28:09:672 EDT] 0000002a ServletWrappe A > SRVE0242I: [TestCsfEAR] [/x] [EntitlementServlet]: > Initialization successful. > [6/1/07 15:28:09:704 EDT] 0000002a SystemOut O > 2007-06-01 15:28:09,704 ERROR [WebContainer : 1] > log4j.EntitlementServlet > (EntitlementServlet.java:59) > - log this info !!@@##$$%%^^&&**()++ > > > --- "Gallagher, Ron" <[EMAIL PROTECTED]> wrote: > > > Naider -- > > > > The purpose of Renderers is to generate a String > > representation of an > > Object. Since a String is already a String, > there's > > no need to do any > > additional rendering. > > > > The getRenderedMessage method in the LoggingEvent > is > > what is responsible > > for calling any defined renderers. This method > has > > an explicit check > > for situations where the object that's about be > > rendered is an instance > > of String. In that case, the Object to render is > > simply cast into a > > String and used as-is. > > > > > > Ron Gallagher, AT&T Mobility > > > > > > -----Original Message----- > > From: Naider Chen [mailto:[EMAIL PROTECTED] > > Sent: Thursday, May 31, 2007 5:26 PM > > To: Log4J Users List > > Subject: Unable to call doRender. Am I missing > > anything? > > > > I'm trying to intercept the logging message to > > filter > > some keyword before forwarding to the destination. > > > I > > tested it in a windows environment using RAD6 > > > > I add the new <renderer> tag entry to log4j.xml > and > > put both log4j.dtd and log4j.xml in the > > WEB-INF/classes folder but after I re-compile and > > bounce the server the doRender method was never > get > > called. > > > > Am I missing snything? Please help. Thanks. > > > > <renderer renderedClass="java.lang.String" > > renderingClass="test.log4j.LogCatcher"/> > > > > I create a new class test.log4j.LogCatcher as > > follows: > > > > package test.log4j; > > import org.apache.log4j.*; > > import org.apache.log4j.spi.*; > > import org.apache.log4j.or.ObjectRenderer; > > > > public class LogCatcher implements ObjectRenderer > { > > > > public String doRender(Object arg0) { > > String st = arg0.toString(); > > System.out.println("LogCatcher doRender > ********** > > log string catched = *" + st + "*"); > > return st; > > } > > } > > > > ALWAYS THERE FOR YOU!!! > > Naider Chen > > EMAIL ME ANYTIME!!!! > > > > > > > > > > > > > ________________________________________________________________________ > > ____________ > > Choose the right car based on your needs. Check > out > > Yahoo! Autos new > > Car Finder tool. > > http://autos.yahoo.com/carfinder/ > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > > > ALWAYS THERE FOR YOU!!! > Naider Chen > EMAIL ME ANYTIME!!!! > > > > > > ____________________________________________________________________________________ > Moody friends. Drama queens. Your life? Nope! - > their life, your story. Play Sims Stories at Yahoo! > Games. > http://sims.yahoo.com/ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > > ____________________________________________________________________________________ Need a vacation? Get great deals to amazing places on Yahoo! Travel. http://travel.yahoo.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
