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
This article example shares the specific code of ...
This article example shares the specific code of ...
When developing a web project, you need to instal...
yum quick install mysql Add yum repository rpm -U...
Table of contents Understanding Asynchrony fetch(...
Table of contents 1. List interface and other mod...
Preface Due to the needs of the company's bus...
Today I happened to be helping a friend move his ...
Table of contents background Problem Analysis 1. ...
Save the following code as the default homepage fi...
To solve the problem that Deepin cannot start Goo...
Due to company requirements, two nginx servers in...
1: What is openssl? What is its function? What is...
Achieve resultsRequirements/Functionality: How to...
First download JDK. Here we use jdk-8u181-linux-x...