commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Tarkenton <d...@tarksoft.com>
Subject Re: [logging] [digester maybe?] Is this correct syntax for commons-logging?
Date Wed, 07 Jul 2004 16:53:54 GMT
Thanks for the reply, Mark.  Is it common practice in logging to make 
the root logger more restrictive than the subsequent "child" loggers? 

I can certainly adopt this strategy, however what I don't understand is 
why the digester.setLogger(logger) call in my previous example doesn't 
seem to work.  It seems to use the root logger no matter what I do.  Is 
it not possible to change the digester's logger from the default root 
logger to some other user defined logger?

i.e.  what purpose does digester.setLogger(logger) serve?  I was 
assuming that I was messing up the implementation somehow.

Mark Horn wrote:

>It is because you have your rootLogger set to DEBUG.  
>log4j.rootLogger=DEBUG, GuiAppender
>
>I would suggest setting you rootLogger to ERROR
>And setting a logger for your package
>
>Example: 
>Log4j.rootLogger=ERROR, GuiAppender
>log4j.logger.com.mycompany.mypackage=DEBUG
>
>Mark Horn
>
>-----Original Message-----
>From: Dan Tarkenton [mailto:dant@tarksoft.com] 
>Sent: Wednesday, July 07, 2004 12:00 PM
>To: commons-user@jakarta.apache.org
>Subject: [logging] [digester maybe?] Is this correct syntax for
>commons-logging?
>
>Hello all.
>
>I have a web app that uses Log4J.  I realize that commons-logging.jar 
>just provides an interface on top of a logging implementation such as 
>Log4J.  I am pretty sure that my commons-logging related syntax is what 
>is preventing me from controlling logging.  You see, I am also using 
>Apache Digester, and since Apache Digester uses commons-logging, it 
>seems to be finding my log4j.properties configuration file, and 
>automatically logging everything at the DEBUG level.  I assume it's just
>
>finding the root logger of Log4J, and not my "class level" logger.  I am
>
>trying to control that level of logging to only include ERROR level and 
>above.
>
>I know this _sounds_ like a log4J problem, but I really believe I must 
>be using commons-logging API incorrectly.  Take a look at my syntax for 
>adding a logger to my Digester object:
>
>public class TestResultsHandler implements MessageResourcesKeys {
>   
>    static final Logger logger = 
>Logger.getLogger(TestResultsHandler.class.getName());
>.
>.
>.
>public static Digester initializeParser() {
>    
>        Digester digester = new Digester();
>       
>        digester.setLogger(new Log4JLogger(logger));
>        digester.setValidating(true);
>        digester.setErrorHandler(new TestResultsErrorHandler());
>
>        // configure digester rules
>.
>.
>.
>        return digester;
>    }
>
>public static void parse(String document) throws TestResultsException {
>       
>        Digester digester = initializeParser();
>
>        TestResultsHandler resultsParser = null;
>        try {
>       
>        //resultsParser = (TestResultsHandler)digester.parse(new 
>StringReader(document));
>        resultsParser =
>            (TestResultsHandler)digester.parse(new 
>File("/usr/local/projects/BOMAnalysis/web/xml/TestResults.xml"));
>        } catch (SAXParseException saxe) {
>            String msg = 
>MessageUtil.formatMessage(MSG_TEST_RESULTS_PARSER_FAILURE);
>            throw new TestResultsException(msg, saxe);
>        } catch (SAXException saxe) {
>            String msg = 
>MessageUtil.formatMessage(MSG_TEST_RESULTS_PARSER_FAILURE);
>            throw new TestResultsException(msg, saxe);
>        } catch (IOException ioe) {
>            String msg = 
>MessageUtil.formatMessage(MSG_TEST_RESULTS_IO_FAILURE);
>            throw new TestResultsException(msg, ioe);
>             
>        }
>    }
>}
>
>Here are the contents of my log4j.properties file in WEB-INF\classes:
>
>log4j.rootLogger=DEBUG, GuiAppender
> 
># GuiAppender is set to be a FileAppender.
>log4j.appender.GuiAppender=org.apache.log4j.FileAppender
>log4j.appender.GuiAppender.Append=true
>log4j.appender.GuiAppender.File=/usr/local/projects/BOMAnalysis/logs/gui
>.log
>
># PmA1 uses PatternLayout.
>log4j.appender.GuiAppender.layout=org.apache.log4j.PatternLayout
>log4j.appender.GuiAppender.layout.ConversionPattern=%d: %-5p : %m%n
>
>log4j.logger.com.titan.bat.gui.testresults.TestResultsHandler=ERROR
>
>No matter what level I set the LEVEL for 
>log4j.logger.com.titan.bat.gui.testresults.TestResultsHandler, I always 
>get DEBUG messages which makes me believe the Digester is defaulting to 
>the root logger of Log4J.  As a matter of fact, if I take out the code 
>for setting the logger for the digester, it will still log at the DEBUG 
>level.  This is why I think my use of the commons-logging api is 
>incorrect.  I think perhaps I'm incorrectly setting the logger for the 
>Digester object.  I have certainly named a logger, 
>com.titan.bat.gui.testresults.TestResultsHandler in this properties 
>file; is this not the same logger that is referenced as the static 
>logger member of my TestResultsHandler class?
>
>Thanks in advance for any insight you may be able to provide.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>  
>


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


Mime
View raw message