Mercurial > hg > Blog
annotate content/Java/log4j-based-logging-in-tomcat-part2.md @ 0:4cd9b65e10e4
initial import of the pelican based blog
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 28 Jun 2013 08:48:58 +0200 |
parents | |
children |
rev | line source |
---|---|
0
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 Title: Log4j based logging in Tomcat 6 - Part 2 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 Date: 2008-06-15 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 Tags: logging, log4j, Tomcat |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
4 Lang: en |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 In my [previous experiment](|filename|./log4j-based-logging-in-tomcat-part1.md) I got Tomcat to log through commons-logging by following the Tomcat instructions. |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 While this works well for webapps that use commons-logging or log4j directly, webapps using JDK logging (e.g. [Hudson](http://hudson.dev.java.net/)) still clutter catalina.out. I remembered an approach that Holger was researching earlier: replace the standard JDK logging that comes preconfigured with Tomcat with a logger that pipes everything through [slf4j](http://www.slf4j.org/). |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 Holger's comment on the earlier blog post got me curious and I sat down and re-did his solution, this time using slf4j's JCL bridge. The net effect is that all logging in Tomcat is done through slf4j (and thus through log4j). The only log messages that show up in catalina.out are those printed to System.out by the webapps but I think that's negligible. |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 Just do the following easy steps to apply the logging Judo to Tomcat: |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 1. In your Tomcat install dir, create a new folder named ext to hold additional jars. |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 1. copy `jul-to-slf4j.jar`, `slf4j-api.jar`, `slf4j-log4j12.jar` and `log4j.jar` to the new ext folder |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 1. also put a `log4j.properties` into the ext folder |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 1. replace Tomcat's `logging.properties` with a file that contains the following:<br> |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 handlers= org.slf4j.bridge.SLF4JBridgeHandler<br> |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 .level= INFO |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 1. patch `catalina.sh` to have the `ext` folder and all its jars on the CLASSPATH. |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 1. restart tomcat et voilĂ ... no more logging to catalina.out |