Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Explain in detail three ways for tomcat to cut catalina.out logs

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1.log4j performs log segmentation

1) prepare three packages: log4j-1.2.17.jar tomcat-juli.jar tomcat-juli-adapters.jar to the lib directory of tomcat or WEB_INF/lib of the project

2) create a new log4j.properties under the lib directory and add the following

Log4j.rootLogger = INFO CATALINA # Define all the appenderslog4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.CATALINA.File = ${catalina.base} / logs/catalinalog4j.appender.CATALINA.Append = truelog4j.appender.CATALINA.Encoding = UTF-8# Roll-over the log once per daylog4j.appender.CATALINA.DatePattern ='. 'yyyy-MM-dd'.log'log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayoutlog4j.appender.CATALINA.layout.ConversionPattern =% d [% t]%-5p% c -% M% n log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.LOCALHOST.File = ${catalina.base} / logs/localhostlog4j.appender.LOCALHOST.Append = truelog4j.appender.LOCALHOST.Encoding = UTF-8log4j.appender.LOCALHOST.DatePattern ='. 'yyyy-MM-dd'.log'log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayoutlog4j.appender.LOCALHOST.layout.ConversionPattern =% d [% t]%-5p% c -% m% n log4j.appender.MANAGER = org. Apache.log4j.DailyRollingFileAppenderlog4j.appender.MANAGER.File = ${catalina.base} / logs/managerlog4j.appender.MANAGER.Append = truelog4j.appender.MANAGER.Encoding = UTF-8log4j.appender.MANAGER.DatePattern ='. 'yyyy-MM-dd'.log'log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayoutlog4j.appender.MANAGER.layout.ConversionPattern =% d [% t]%-5p% c -% m% n log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.HOST -MANAGER.File = ${catalina.base} / logs/host-managerlog4j.appender.HOST-MANAGER.Append = truelog4j.appender.HOST-MANAGER.Encoding = UTF-8log4j.appender.HOST-MANAGER.DatePattern ='. 'yyyy-MM-dd'.log'log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayoutlog4j.appender.HOST-MANAGER.layout.ConversionPattern =% d [% t]%-5p% c -% m% n log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppenderlog4j. Appender.CONSOLE.Encoding = UTF-8log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayoutlog4j.appender.CONSOLE.layout.ConversionPattern =% d [% t]%-5p% c -% m% n # Configure which loggers log to which roomderslog4j.logger.org.apache.catalina.core.ContainerBase.[ catalina]. [localhost] = INFO [localhost]. [/ manager] =\ INFO, Managerlog4j.logger.org.apache.catalina.core.ContainerBase.[ Catalina] .[ localhost]. [/ host-manager] =\ INFO, HOST-MANAGER

3) under the tomcat root directory and the conf folder, delete or rename the logging.properties file. Then modify the context.xml file and change the label to take over the log output of tomcat. In this way, log segmentation using log4j is done.

2. Use cronolog to split the log

Cronolog is a filter program that reads log file entries from standard input and writes each entry to the output file specified by the file name template and the current log. When the extension file name changes, close the current file and open a new one. Cronolog is designed to be used with Web servers such as Apache, dividing access logs into daily or monthly logs.

# wget https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz# tar-zxf cronolog-1.6.2.tar.gz# cd cronolog#. / configure # make & & make install# which cronolog# / usr/local/sbin/cronolog

Edit the bin/catalina.sh under tomcat (Note: the number of lines is not necessarily mine, find the statement mainly)

Replace the above two contents with:

Org.apache.catalina.startup.Bootstrap "$@" start\ 2 > & 1 | / usr/local/sbin/cronolog "$CATALINA_BASE/logs/catalina-%Y-%m-%d.out" &

When you are finished, restart tomcat.

3. Use logrotate to cut.

Under / etc/logrotate.d, create a new tomcatrotate, edit the tomatrotate, and write the following:

/ usr/local/tomcat7.0.79/logs/catalina.out {dailyrotate 15missingokdateextcompressnotifemptycopytruncate}

Daily specifies that the dump cycle is daily

Rotate 15 specifies the number of times the log file is dumped before it is deleted. 0 means there is no backup and 5 means 5 backups are retained.

Missingok ignores the warning message if the log does not exist

The dateext file suffix is the date format, that is, the cut file is: xxx.log-20150828.gz

Log after compress is compressed and dumped by gzip (decompressed by gzip-d xxx.gz)

Notifempty does not dump if it is an empty file

Copytruncate is used for opening log files to back up and truncate the current log

/ usr/local/tomcat7.0.79/logs/catalina.out specifies the path to the catalina.out

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report