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
(Continued from page 1) After doing this, when I started up my web app, I received the following console output. Console OutputLog4JInitServlet is initializing log4j Initializing log4j with: C:\projects\workspace\log4j-webapp-demo\web\WEB-INF/log4j.properties 0 [main] INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/balancer] - 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]] 453 [main] INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/jsp-examples] - ContextListener: contextInitialized() 453 [main] INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/jsp-examples] - SessionListener: contextInitialized() 719 [main] INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/servlets-examples] - ContextListener: contextInitialized() 719 [main] INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/servlets-examples] - SessionListener: contextInitialized() 1015 [main] INFO org.apache.coyote.http11.Http11BaseProtocol - Starting Coyote HTTP/1.1 on http-8080 1297 [main] INFO org.apache.jk.common.ChannelSocket - JK: ajp13 listening on /0.0.0.0:8009 1312 [main] INFO org.apache.jk.server.JkMain - Jk running ID=0 time=0/47 config=null 1375 [main] INFO org.apache.catalina.storeconfig.StoreLoader - Find registry server-registry.xml at classpath resource 1578 [main] INFO org.apache.catalina.startup.Catalina - Server startup in 2735 ms Notice the results. No TomcatSW INFO messages are displayed before the web application's log4j initialization servletW is hit since the root logger is set to ERROR. However, the init servlet changes the logging level to INFO, so the Tomcat INFO messages after this point in execution are displayed. Is it possible to remove these Tomcat INFO messages? Sure. One way to do this is to add the following to our log4j.properties file in the 'tomcat-log4j' folder: log4j.logger.org.apache=ERROR That line says that if a class is within the org.apache package, it's logging level is set to ERROR. This is shown below. # 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 log4j.logger.org.apache=ERROR If we now start up our application after this latest change, we see the following console output: Console OutputLog4JInitServlet is initializing log4j Initializing log4j with: C:\projects\workspace\log4j-webapp-demo\web\WEB-INF/log4j.properties Suppose we don't want to totally eliminate all the messages. Let's still display the message that reports on how long it takes Tomcat to start up. We can do this by adding the following to the log4j.properties file in the 'tomcat-log4j' folder: log4j.logger.org.apache.catalina.startup=INFO This is shown below. # 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 log4j.logger.org.apache=ERROR log4j.logger.org.apache.catalina.startup=INFO Now, if we run our web application, we see the following in our console output: Console Output0 [main] INFO org.apache.catalina.startup.Catalina - Initialization processed in 922 ms Log4JInitServlet is initializing log4j Initializing log4j with: C:\projects\workspace\log4j-webapp-demo\web\WEB-INF/log4j.properties 2297 [main] INFO org.apache.catalina.startup.Catalina - Server startup in 2297 ms As we've seen, it's possible configure the Tomcat start-up information that's displayed to the console when running the Tomcat bootstrap from within EclipseSW. I'm not really sure why the latest commons-logging jarW file isn't shipped with Tomcat. There is a commons-logging-api jar file within the Tomcat bin/ directory in my version of Tomcat, but it's obviously a bit different from the commons-logging jar file that I added to my project's build path. Related Tutorials:
|