1
votes

I am using this doc to change my Tomcat loggers to log4j:

https://tomcat.apache.org/tomcat-7.0-doc/logging.html

my log4j.properties file is as shown in the document, except I changed this line to confirm it's working: log4j.appender.CATALINA.File = ${catalina.base}/logs/test_catalina

I still see a file logs/catalina.out and not logs/test_catalina, which makes me think either log4j is not being used or my properties file is not read.

I have tomcat-juli-adapters.jar, log4j-1.2.17.jar and log4j.properties in lib and overwrote bin/tomcat-juli.jar

running set -x catalina.sh start shows:

 eval "/a/java64/jdk1.8.0/bin/java" "-Dnop" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dlog4j.debug=true  -Djava.endorsed.
dirs="/opt/apache-tomcat-7.0.62/endorsed" -classpath "/opt/apache-tomcat-7.0.62/bin/bootstrap.jar:/opt/apache-tomcat-7.0.62/bin/tomcat-juli.jar" -Dcatalina.base="/opt/apache-tomcat-7.0.62" -Dcatalina.home="/opt/apache-tom
cat-7.0.62" -Djava.io.tmpdir="/opt/apache-tomcat-7.0.62/temp" org.apache.catalina.startup.Bootstrap start &

I also have no logging.properties file on disk:

ls conf/*.properties 
conf/catalina.properties

I would really appreciate advice on how to debug this -- I'm not sure if a jar is not being found properly, if my log4j.properties has a problem, or Tomcat just plain can't tell I'd like log4j.

Using Tomcat version Server number: 7.0.62.0

1

1 Answers

1
votes

I would really appreciate advice on how to debug this

The switch of sending Tomcat log messages from java.util.logging to log4j 1.x is performed by Apache Commons Logging library. (Its compiled package-renamed version is in those tomcat-juli.jar and tomcat-juli-adapters.jar)

There is a debug setting available in Apache Commons Logging. After package renaming the setting name becomes org.apache.juli.logging.diagnostics.dest.

I do not see any evident error in those steps that you performed. Dummy issues may be: are the files readable?

Notes:

  1. It is possible to put tomcat-juli-adapters.jar into $CATALINA_HOME/bin instead of /lib, but you need to update CLASSPATH variable (in your bin/setenv.sh) so that it is included in the value of -classpath argument to java. Repacking the two jars into a single jar file is also an option.

  2. As mentioned by tomcat-7.0-doc/logging.html, deleting conf/logging.properties makes java.util.logging to fallback to default configuration. You may wish to explicitly configure that file.

  3. Source code for tomcat-juli.jar and tomcat-juli-adapters.jar can be found at Maven Central. Those libraries have groupId=org.apache.tomcat.extras