03
Sep
09

How to get Apache Tomcat 6 to log to the console


This site is a collaborative effort! The complete text and sourcecode for this is available on GitHub. Corrections and enhancements are welcome, please make the change and submit a pull request in the comment area below.

s article explains how to get apache tomcat to log to the console (system.out).

The process is quite simple. $CATALINA_HOME represents where you have tomcat version 6 installed.

Step 1

Download Apache log4j and put it into $CATALINA_HOME/lib folder.

Step 2

Download the jar files listed below

  • tomcat-juli-adapters.jar
  • tomcat-juli.jar

You may download them from here (fool proof method):

http://tomcat.apache.org/
Click on version 6 then click on Quick Navigation -> browse -> extras

Not sure if the following link will work years from now: http://www.poolsaboveground.com/apache/tomcat/tomcat-6/v6.0.20/bin/extras/ but it shows you were the files were at the time this blog was being written.

Step 3

Put tomcat-juli.jar into your $CATALINA_HOME/bin folder and the other jar file goes into the $CATALINA_HOME/lib folder.

Step 4

Put the following log4j.properties file into the $CATALINA_HOME/lib folder.

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1

# A1 is set to be a ConsoleAppender.

# A1 uses PatternLayout.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p %c - %m%n

Finally

Restart the tomcat server and you should now start seeing the output to the console.

2009-09-07 10:03:45,208 WARN  org.apache.commons.digester.Digester - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:helloWorld' did not find a matching property.
2009-09-07 10:03:45,211 INFO  org.apache.catalina.core.AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-sun-1.6.0.14/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.14/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.14/jre/../lib/amd64:/usr/lib64/xulrunner-addons:/usr/java/packages/lib/amd64:/lib:/usr/lib
2009-09-07 10:03:45,231 INFO  org.apache.coyote.http11.Http11Protocol - Initializing Coyote HTTP/1.1 on http-8080
2009-09-07 10:03:45,232 INFO  org.apache.catalina.startup.Catalina - Initialization processed in 316 ms
2009-09-07 10:03:45,254 INFO  org.apache.catalina.core.StandardService - Starting service Catalina
2009-09-07 10:03:45,255 INFO  org.apache.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/6.0.18
2009-09-07 10:03:45,654 INFO  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/helloWorld] - Initializing Spring root WebApplicationContext
2009-09-07 10:03:45,768 INFO  org.apache.coyote.http11.Http11Protocol - Starting Coyote HTTP/1.1 on http-8080
2009-09-07 10:03:45,799 INFO  org.apache.jk.common.ChannelSocket - JK: ajp13 listening on /0.0.0.0:8009
2009-09-07 10:03:45,803 INFO  org.apache.jk.server.JkMain - Jk running ID=0 time=0/12  config=null
2009-09-07 10:03:45,804 INFO  org.apache.catalina.startup.Catalina - Server startup in 572 ms

The logging is totally customizable. You can change the where the log output goes to or the Severity of errors that get logged by modifying the log4j.properties file seen above. To learn more about Apache log4j please visit the following URL: http://logging.apache.org

Note that this does not replace the custom logging properties you have within your applications. You can still specify them by putting a log4j.properties inside your applications /WEB-INF/classes folder. This logger is only at the top level. It helps in debugging issues you may encounter with the tomcat server.

This site is a collaborative effort! The complete text and sourcecode for this is available on GitHub. Corrections and enhancements are welcome, please make the change and submit a pull request in the comment area below.
Advertisements

1 Response to “How to get Apache Tomcat 6 to log to the console”


  1. 1 Martijn Hinten
    October 14, 2010 at 3:45 am

    Thanks, works like a charm.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 77 other followers

September 2009
S M T W T F S
« Aug   Oct »
 12345
6789101112
13141516171819
20212223242526
27282930  

Blog Stats

  • 830,829 hits

%d bloggers like this: