1. Log4j for log segmentation 1) Prepare three packages: log4j-1.2.17.jar tomcat-juli.jar tomcat-juli-adapters.jar and put them in the lib directory of tomcat or WEB_INF/lib of the project. 2) Create a new log4j.properties file in the lib directory and add the following content 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 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 3) In the tomcat root directory, in the conf folder, delete or rename the logging.properties file. Then modify the context.xml file and change the <Context> tag to <Context swallowOutput="true"> to take over the log output of Tomcat. In this way, log segmentation using log4j is completed. 2. Use cronolog to split logs 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 file. When the file extension changes, the current file is closed and a new file is opened. Cronolog is designed to be used with web servers such as Apache to split 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 bin/catalina.sh under tomcat (Note: the number of lines may not be mine, just find the statement) 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" & Once completed, restart tomcat. 3. Use logrotate to cut. In /etc/logrotate.d, create a new tomcatrotate, edit tomatrotate, and write the following content: /usr/local/tomcat7.0.79/logs/catalina.out { daily rotate 15 missingok dateext compress notifempty copytruncate } daily specifies the dump cycle as daily copytruncate is used for log files that are still open to back up and truncate the current log. /usr/local/tomcat7.0.79/logs/catalina.out specifies the path of catalina.out The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: A record of pitfalls in JS regular matching
>>: MySQL knowledge points for the second-level computer exam mysql alter command
It is really not easy to do a good reconstruction...
Today, I encountered a small problem that after s...
1. Introduction MySQL is used in the project. I i...
The difference between replace into and insert in...
1. Download Dependency npm install @antv/data-set...
Table of contents 1. Introduction 2. Thought Anal...
Install antd-mobile Global import npm install ant...
MySQL official website download address: https://...
Table of contents background 1. The query conditi...
This article shares with you a practical web navi...
This article is original by 123WORDPRESS.COM Ligh...
If you think the system is slow and want to chang...
When using Flex layout, you will find that when a...
This is a test of the interviewee's basic kno...
Software Version Windows: Windows 10 MySQL: mysql...