Tomcat's default log uses java.util.logging, which has several shortcomings. The file catalian.out cannot be generated daily like log4j, and will become larger and larger. The log format is inconsistent with that printed by log4j in the project, which is not conducive to parsing. I searched on the official website of Tomcat (https://tomcat.apache.org/tomcat-7.0-doc/logging.html) and found that by modifying some configurations and replacing the extension package, you can use log4j to output catalian.out. Create a log4j.properties file in $CATALINA_BASE/lib The content of log4j.properties is as follows: 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 log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout #log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n log4j.appender.CATALINA.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%t] %c | %m%n # configure customed log to catalina.out log4j.logger.com.xxxxx = WARN, CATALINA log4j.logger.org.apache = WARN, CATALINA log4j.logger.org.mybatis = WARN, CATALINA log4j.logger.java.sql = WARN, CATALINA log4j.logger.org.springframework = WARN, CATALINA Update tomcat related jar packages Download log4j-1.2.17.jar (http://www.apache.org/dist/logging/log4j/1.2.17/) Download two jar packages of tomcat7: tomcat-juli.jar and tomcat-juli-adapters.jar (http://www.apache.org/dist/tomcat/tomcat-7/v7.0.69/bin/extras/, preferably corresponding to the tomcat version) Put log4j-1.2.17.jar and tomcat-juli-adapters.jar in $CATALINA_HOME/lib; replace $CATALINA_HOME/bin/tomcat-juli.jar with the newly downloaded tomcat-juli.jar. Delete $CATALINA_BASE/conf/logging.properties. Restart tomcat About the default catalina log format If you only want to change the default log format of Tomcat, just replace the default java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter Change it to the following: java.util.logging.ConsoleHandler.formatter = com.xxx.LogFormatter org.apache.juli.FileHandler.formatter = com.xxx.LogFormatter Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: MySQL Oracle and SQL Server paging query example analysis
>>: How to use physics engine joints in CocosCreator
This article example shares the specific code of ...
Prerequisite: nginx needs to have the ngx_http_li...
Set the table's style="table-layout:fixed...
In the interview, you should have experienced the...
Data Type: The basic rules that define what data ...
Before the release of Microsoft IE 5.0, the bigges...
Table of contents Three steps to operate the data...
Copy code The code is as follows: <!DOCTYPE ht...
The following code introduces the installation me...
1. Manually create and add my.ini file # CLIENT S...
1 What is BEM Naming Standard Bem is the abbrevia...
When browser vendors bend the standards and take i...
brew install nginx Apple Mac uses brew to install...
Table of contents What utilities does VueUse have...
This article example shares the specific code of ...