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
The Docker images we usually build are usually la...
After IntelliJ IDEA deploys a Javaweb project usi...
The CSS position attribute specifies the element&...
Table of contents Standards for smooth animation ...
This article shares with you how to use Navicat t...
1. Check whether the MySQL service is started. If...
1 / Copy the web project files directly to the we...
Background: I'm working on asset reporting re...
The pagination component is a common component in...
Preface When the system space usage is too large ...
MySQL escape Escape means the original semantics ...
<br />When you click the link, the web page ...
1. [admin@JD ~]$ cd opt #Enter opt in the root di...
This article shares with you the graphic tutorial...
1. First, create a hello-world.cpp file The progr...