Tomcat uses log4j to take over catalina.out log files are generated on a daily basis

Source: Internet
Author: User
Tags log4j

Tomcat under the use of log4j take over catalina.out log file generation, storage by day, solve catalina.out log file too big problem 1. Prepare 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

(Download from http://www.apache.org/dist/tomcat/tomcat-7/v7.0.52/bin/extras/, select the corresponding branch according to your Tomcat version) 2. Copy the three jar packages above to Tomcat's lib directory;
3. Copy the Tomcat-juli.jar to the Tomcat bin directory and replace the original jar package;
4. To modify Tomcat's Conf/context.xml file, the

(Increase the swallowoutput= "true" property configuration, only in this way to completely take the Tomcat stdout to take over. This step is very important in the official website and the internet to find a lot of information are not mentioned. 5. Delete Tomcat's conf/logging.properties file (or rename-recommend);
6. Create log4j.properties files in Tomcat's 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.
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.localhost=org.apache.log4j.dailyrollingfileappender
Log4j.appender.localhost.file=${catalina.base}/logs/localhost.
Log4j.appender.localhost.append=true
Log4j.appender.localhost.encoding=utf-8
Log4j.appender.localhost.datepattern= '. ' Yyyy-mm-dd '. Log '
Log4j.appender.LOCALHOST.layout = Org.apache.log4j.PatternLayout
Log4j.appender.LOCALHOST.layout.ConversionPattern =%d [%t]%-5p%c-%m%n

Log4j.appender.manager=org.apache.log4j.dailyrollingfileappender
Log4j.appender.manager.file=${catalina.base}/logs/manager.
Log4j.appender.manager.append=true
Log4j.appender.manager.encoding=utf-8
Log4j.appender.manager.datepattern= '. ' Yyyy-mm-dd '. Log '
Log4j.appender.MANAGER.layout = Org.apache.log4j.PatternLayout
Log4j.appender.MANAGER.layout.ConversionPattern =%d [%t]%-5p%c-%m%n

Log4j.appender.host-manager=org.apache.log4j.dailyrollingfileappender
Log4j.appender.host-manager.file=${catalina.base}/logs/host-manager.
Log4j.appender.host-manager.append=true
Log4j.appender.host-manager.encoding=utf-8
Log4j.appender.host-manager.datepattern= '. ' Yyyy-mm-dd '. Log '
Log4j.appender.host-manager.layout = Org.apache.log4j.PatternLayout
Log4j.appender.host-manager.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

# Configure which loggers log to which appenders
# Configure which loggers log to which appenders
Log4j.logger.org.apache.catalina.core.ContainerBase. [Catalina]. [Localhost]=info, localhost
Log4j.logger.org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/manager]=\
INFO, MANAGER
Log4j.logger.org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/host-manager]=\
INFO, Host-manager


7 reboot Tomcat, effect

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.