Tomcat under log4j take over logs and split by date

Source: Internet
Author: User
Tags tomcat log4j


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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.