Hey, All,
I'm attempting to use spring's Log4jConfigListener in an exploded web app I have and need some help. The problem is that, despite Log4jConfigListener correctly reading the log4j.properties file, the log level never goes below INFO even though the root logger is set to DEBUG.
My Environment:
.
- Tomcat 5.0.30 or Tomcat 5.0.28 (I've tried both)
My app is Tapestry-based web app with Spring and Hibernate.
I am using commons-logging to log within my code.
The commons-logging.jar and log4j.jar are in the web app's /WEB-INF/lib directory
My Config:
Web.xml:
Log4j.properties (lifted from the petclinic example and slightly modified):Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <!-- generated by Spindle, http://spindle.sourceforge.net --> <web-app> <display-name>JASF Time Manager</display-name> <!-- - Key of the system property that should specify the root directory of this - web app. Applied by WebAppRootListener or Log4jConfigListener. --> <context-param> <param-name>webAppRootKey</param-name> <param-value>jasf.root</param-value> </context-param> <!-- - Location of the Log4J config file, for initialization and refresh checks. - Applied by Log4jConfigListener. --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/classes/log4j.properties</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <filter> <filter-name>hibernateSessionFilter</filter-name> <filter-class> com.jasf.web.filters.OpenSessionInViewFilter </filter-class> </filter> <filter> <filter-name>redirect</filter-name> <filter-class>org.apache.tapestry.RedirectFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernateSessionFilter</filter-name> <url-pattern>/app</url-pattern> </filter-mapping> <filter-mapping> <filter-name>redirect</filter-name> <url-pattern>/</url-pattern> </filter-mapping> <listener> <listener-class> org.springframework.web.util.Log4jConfigListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>jasf</servlet-name> <servlet-class> org.apache.tapestry.ApplicationServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jasf</servlet-name> <url-pattern>/app</url-pattern> </servlet-mapping> </web-app>
And the console output:Code:# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml! # For all other servers: Comment out the Log4J listener in web.xml to activate Log4J. log4j.debug=true log4j.rootLogger=DEBUG, stdout, logfile log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n log4j.appender.logfile=org.apache.log4j.RollingFileAppender log4j.appender.logfile.File=${jasf.root}/WEB-INF/petclinic.log log4j.appender.logfile.MaxFileSize=512KB # Keep three backup files. log4j.appender.logfile.MaxBackupIndex=3 # Pattern to output: date priority [category] - message log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
--the above shows the file was picked up correctly....Code:INFO: Processing Context configuration file URL file:C:\tomcat\jakarta-tomcat-5.0.28\conf\Catalina\localhost\jasf.xml log4j: Parsing for [root] with value=[DEBUG, stdout, logfile]. log4j: Level token is [DEBUG]. log4j: Category root set to DEBUG log4j: Parsing appender named "stdout". log4j: Parsing layout options for "stdout". log4j: Setting property [conversionPattern] to [%d %p [%c] - <%m>%n]. log4j: End of parsing for "stdout". log4j: Parsed "stdout" options. log4j: Parsing appender named "logfile". log4j: Parsing layout options for "logfile". log4j: Setting property [conversionPattern] to [%d %p [%c] - %m%n]. log4j: End of parsing for "logfile". log4j: Setting property [file] to [C:\work\jasf\context\/WEB-INF/petclinic.log]. log4j: Setting property [maxFileSize] to [512KB]. log4j: Setting property [maxBackupIndex] to [3]. log4j: setFile called: C:\work\jasf\context\/WEB-INF/petclinic.log, true log4j: setFile ended log4j: Parsed "logfile" options. log4j: Finished configuring. log4j: Parsing for [root] with value=[DEBUG, stdout, logfile]. log4j: Level token is [DEBUG]. log4j: Category root set to DEBUG log4j: Parsing appender named "stdout". log4j: Parsing layout options for "stdout". log4j: Setting property [conversionPattern] to [%d %p [%c] - <%m>%n]. log4j: End of parsing for "stdout". log4j: Parsed "stdout" options. log4j: Parsing appender named "logfile". log4j: Parsing layout options for "logfile". log4j: Setting property [conversionPattern] to [%d %p [%c] - %m%n]. log4j: End of parsing for "logfile". log4j: Setting property [file] to [C:\work\jasf\context\/WEB-INF/petclinic.log]. log4j: Setting property [maxFileSize] to [512KB]. log4j: Setting property [maxBackupIndex] to [3]. log4j: setFile called: C:\work\jasf\context\/WEB-INF/petclinic.log, true log4j: setFile ended log4j: Parsed "logfile" options. log4j: Finished configuring.
A piece of code that makes a debug call _and_ that is called on startup:
...and the pertinent output logged to the console:Code:log.info("Starting execution..."); log.fatal("is de-f*cking bugging enabled? " + log.isDebugEnabled()); SimpleDateFormat dateFormatter = new SimpleDateFormat( "MM/dd/yyyy HH:mm"); Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR, 0); today.set(Calendar.MINUTE, 0); log.debug("Testing with date: " + dateFormatter.format(today.getTime()));
This looks like to me that some other logging file is getting picked up and read first, ignoring my logging file that _clearly_ was loaded.[/b]Code:Mar 22, 2005 9:53:27 PM com.jasf.jobs.PayPeriodJob executeInternal INFO: Starting execution... Mar 22, 2005 9:53:27 PM com.jasf.jobs.PayPeriodJob executeInternal [color=red][b]SEVERE: is de-f*cking bugging enabled? false[/b][/color] Mar 22, 2005 9:53:27 PM org.springframework.jdbc.datasource.JdbcTransactionObjectSupport <clinit> INFO: JDBC 3.0 Savepoint class is available Hibernate: select payperiod0_.id as id, payperiod0_.endDate as endDate, payperiod0_.complete as complete, payperiod0_.startDate as startDate, payperiod0_.status as status from PayPeriod payperiod0_ where (payperiod0_.status=? ) Mar 22, 2005 9:53:27 PM com.jasf.jobs.PayPeriodJob executeInternal INFO: 03/22/2005 12:00 is less than active period's end date of 03/27/2005 12:00


Reply With Quote