How do I remove the Tomcat INFO console messages at start-up?
Author: Deron Eriksson
Description: This Java tutorial describes one way to remove the Tomcat's startup INFO messages.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1 || Tomcat 5.5.20


Page:    1 2 >

Note: There's a good chance that there's another, much better way of not showing the TomcatSW INFO messages when Tomcat starts up. The approach that I describe here feels like a hack, but it works. I'll illustrate using the log4j-webapp-demo project that I've used in some other examples.

'log4j-webapp-demo' project

The other day, I wrote a servletW with a <load-on-startup> tag so that its init method would get called when my web application started up in Eclipe. However, I was annoyed that it was hard to find the messages that were sent to the console by the init method because there were so many Tomcat INFO messages that were also displayed in the console during Tomcat start-up.

This is illustrated below:

Console Output

Mar 18, 2007 2:01:15 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\jdk1.5.0_09\jre\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\jdk1.5.0_09\bin;C:\maven-2.0.4\bin;C:\jadnt158;C:\mysql-essential-5.0.27\bin
Mar 18, 2007 2:01:15 AM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Mar 18, 2007 2:01:15 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 938 ms
Mar 18, 2007 2:01:15 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 18, 2007 2:01:15 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.20
Mar 18, 2007 2:01:15 AM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Log4JInitServlet is initializing log4j
Initializing log4j with: C:\projects\workspace\log4j-webapp-demo\web\WEB-INF/log4j.properties
Mar 18, 2007 2:01:16 AM org.apache.catalina.core.ApplicationContext log
INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
Mar 18, 2007 2:01:16 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Mar 18, 2007 2:01:16 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Mar 18, 2007 2:01:16 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Mar 18, 2007 2:01:16 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Mar 18, 2007 2:01:17 AM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Mar 18, 2007 2:01:17 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 18, 2007 2:01:17 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/94  config=null
Mar 18, 2007 2:01:17 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Mar 18, 2007 2:01:17 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2422 ms

Within all this output, I am interested in the following:

Log4JInitServlet is initializing log4j
Initializing log4j with: C:\projects\workspace\log4j-webapp-demo\web\WEB-INF/log4j.properties

I initially figured that there must be something in my Tomcat conf/ directory that would allow me to change the logging level when running the Tomcat bootstrap from within EclipseSW, but unfortunately I didn't find anything that worked. There's a logging.properties file in there that I figured I could tweak, but changing this file didn't seem to do anything (at least when running Tomcat in Eclipse via the org.apache.catalina.startup.Bootstrap class in bootstrap.jar).

I created a 'tomcat-log4j' folder, and created a log4j.properties file within that folder. This file is shown below. I set the log level to ERROR.

# This sets the global logging level and specifies the appenders
log4j.rootLogger=ERROR, myConsoleAppender

# settings for the console appender
log4j.appender.myConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.myConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.myConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Then I went to http://commons.apache.org/downloads/download_logging.cgi and downloaded the latest commons-logging jarW file, which was commons-logging-1.1.jar. I added this jar to the 'tomcat-log4j' folder.

Eclipse Navigator View

I added the 'tomcat-log4j' folder as a Class Folder to my project's build path so that the log4j.properties file could be found. I added the commons-logging-1.1.jar file to my project build path.

commons-logging-1.1.jar library added to project Java Build Path

(Continued on page 2)

Page:    1 2 >