Tomcat under use log4j take over catalina.out log file generation method, store by day, solve catalina.out log file too big problem
1. Prepare the jar package:
Log4j-1.2.17.jar (download from http://www.apache.org/dist/logging/log4j/1.2.17/)
Tomcat-juli.jar, Tomcat-juli-adapters.jar (downloaded from http://www.apache.org/dist/tomcat/tomcat-7/v7.0.52/bin/extras/, Select the corresponding branch based on your Tomcat version)
2. Copy the above three jar packages to the Tomcat Lib directory;
3. Copy the Tomcat-juli.jar to the Tomcat bin directory and replace the original jar package;
4. Modify Tomcat's Conf/context.xml file to <Context> <context swallowoutput= "true" >
(Add swallowoutput= "true" to the property configuration, only in order to fully take the Tomcat stdout to take over.) This step is crucial in the official website and the internet to find a lot of information is not mentioned. );
5. Delete Tomcat's conf/logging.properties file (or rename-suggest);
6. Create the Log4j.properties file in the Tomcat lib directory:
Log4j.rootlogger=info, CATALINA
# Define all the Appenders
Log4j.appender.catalina=org.apache.log4j.dailyrollingfileappender
Log4j.appender.catalina.file=${catalina.base}/logs/catalina.out
Log4j.appender.catalina.append=true
Log4j.appender.catalina.encoding=utf-8
# Roll-over The log once per day
Log4j.appender.catalina.datepattern= '. ' Yyyy-mm-dd '. Log '
Log4j.appender.CATALINA.layout = Org.apache.log4j.PatternLayout
Log4j.appender.CATALINA.layout.ConversionPattern =%d [%t]%-5p%c-%m%n
Log4j.appender.console=org.apache.log4j.consoleappender
Log4j.appender.console.encoding=utf-8
Log4j.appender.CONSOLE.layout = Org.apache.log4j.PatternLayout
Log4j.appender.CONSOLE.layout.ConversionPattern =%d [%t]%-5p%c-%m%n