Tomcat uses Log4j to output catalina.out logs
- 2021-01-14 07:08:12
- OfStack
catalian.out cannot be generated on a daily basis like log4j1, it will get bigger and bigger. java.util.logging Log format and project in log4j type out of the same, not conducive to parsing.
From tomcat website (https: / / tomcat. apache. org/tomcat - 7.0 - doc/logging html) for, modify 1 can use some configuration, replace the expansion pack log4j output catalian. out.
Create the file log4j.properties under $CATALINA_BASE/lib
log4j.properties contains the following contents:
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 tomcat7 2 jar package: tomcat - juli. jar and tomcat - juli - adapters. jar (http: / / www. apache. org/dist/tomcat/tomcat - 7 / v7. 0.69 / bin/extras/best and tomcat version)
log4j-1.2.17.jar and tomcat-juli-adapters.jar are placed under $CATALINA_HOME/lib. Replace the $CATALINA_HOME/bin/tomcat-juli.jar package with the newly downloaded tomcat-juli.jar package.
Delete $CATALINA_BASE conf/logging properties.
Restart tomcat
About the default catalina logging format
If you only want to change the default log format for tomcat, replace the default
java.util.logging.SimpleFormatter
Can. The format of format in SimpleFormatter class is
LoggingSupport.getSimpleFormat()
"%1$tb %1$td, %1$tY %1$tM:%1$tS %1$Tp %2$s% 4$s: %5$s%6$s%n". com.xxx.LogFormatter (com.xxx.LogFormatter); format is set to "%1$tY-%1$td %1$tH:%1$tM:%1$tL %4$s %2$s %5$s% 6$n". Modify $CATALINA_BASE conf/logging properties
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
Replace it as follows:
java.util.logging.ConsoleHandler.formatter = com.xxx.LogFormatter
org.apache.juli.FileHandler.formatter = com.xxx.LogFormatter
conclusion