Use log4j for Tomcat logs
Yesterday, my colleague encountered a fault. An error occurred while accessing a Tomcat server. Tomcat is in version 6.0. Then, if you want to view the Tomcat log, you cannot find the latest log, there are only a few log files in the logs for 08 years. My colleagues felt dizzy and I felt strange. As a matter of fact, Tomcat will generate log files by default. How can this problem disappear without reason?
I found related information on the Internet. Most of the information on the Internet is about how to make Tomcat use log4j. I think jdklogger is used by Tomcat by default. It is good if log4j can be used, as long as the log can generate a file.
So I made an experiment under tomcat5.5 and tomcat6 in my local environment.
As a result, it is found that there are still differences between atat5.5 and 6 When configuring log4j.
1) tomcat5.5
Copy the jar packages of commons-logging and log4j to the common/lib, and copy the log4j. properties and commons-logging.properties to the common/classes,
Log4j. properties. The configuration can be as follows:
Write
Log4j. rootlogger = info, stdout, file
# Direct log messages to stdout ###
Log4j. appender. stdout = org. Apache. log4j. leleappender
Log4j. appender. stdout. Target = system. Out
Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout
Log4j. appender. stdout. layout. conversionpattern = % d {absolute} % L-% m % N
# Direct messages to file systemout. Log ###
Log4j. appender. File = org. Apache. log4j. fileappender
Log4j. appender. file. File = ../logs/systemout. Log
Log4j. appender. file. append = false
Log4j. appender. file. layout = org. Apache. log4j. patternlayout
Log4j. appender. file. layout. conversionpattern = % d {absolute} % L-% m % N
# Block packages that you don't care about ###
Log4j.logger.org. Apache. commons. digester = Error
Log4j.logger.org. Apache. commons. beanutils = Error
Log4j.logger.org. Apache. commons. modeler = Error
Commons-logging.properties, configuration can be as follows:
Wrote org. Apache. commons. Logging. log = org. Apache. commons. Logging. impl. log4jlogger
# Please refer to the log implementations in package org. Apache. commons. Logging. impl #
# Org. Apache. commons. Logging. log = org. Apache. commons. Logging. impl. jdk14logger
# Org. Apache. commons. Logging. log = org. Apache. commons. Logging. impl. simplelog
After restarting tomcat, you can find the log file under logs.
2) tomcat6
Similarly, you need to copy the jar packages of commons-logging and log4j to Tomcat, but the target directory is different: $ {tomcat_home}/lib /;
The commons-logging.properties and log4j. properties need to be copied to the $ {tomcat_home}/lib/directory;
Extra, also need to http://www.apache.org/dist/tomcat/tomcat-6/v6.0.18/bin/extras/
Download two packages: tomcat-juli.jar, tomcat-juli-adapters.jar
Copy the tomcat-juli.jar to the bin, replace the original jar package with the same name; put the tomcat-juli-adapters.jar under $ {tomcat_home}/lib/
After completing the preceding steps, restart tomcat to find that log4j logs are generated.
References:
Http://tomcat.apache.org/tomcat-5.5-doc/logging.html
Http://tomcat.apache.org/tomcat-6.0-doc/logging.html
Http://www.blogjava.net/Unmi/archive/2008/07/07/213001.html