In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use Log4j to output catalina.out logs in Tomcat? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Create a log4j.properties file under $CATALINA_BASE/lib
The log4j.properties is as follows:
Log4j.rootLogger = INFO CATALINA# Define all the appenderslog4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppenderlog4j.appender.CATALINA.File = ${catalina.base} / logs/catalina.outlog4j.appender.CATALINA.Append = truelog4j.appender.CATALINA.Encoding = UTF-8# Roll-over the log once per daylog4j.appender.CATALINA.DatePattern ='. 'yyyy-MM-ddlog4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout#log4j.appender.CATALINA.layout.ConversionPattern =% d [% t]%-5p% c -% m % nlog4j.appender.CATALINA.layout.ConversionPattern =% d {yyyy-MM-dd HH:mm:ss.SSS}% p [% t]% c |% m%n# configure customed log to catalina.outlog4j.logger.com.xxxxx = WARN CATALINAlog4j.logger.org.apache = WARN, CATALINAlog4j.logger.org.mybatis = WARN, CATALINAlog4j.logger.java.sql = WARN, CATALINAlog4j.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 2 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 corresponds to the tomcat version)
Put log4j-1.2.17.jar and tomcat-juli-adapters.jar 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 log format
If you only want to change the default log format of tomcat, replace the default java.util.logging.SimpleFormatter. The format format in the SimpleFormatter class is LoggingSupport.getSimpleFormat (), and its specific value is: "% 1$ tb% 1$ td,% 1$ tY% 1$ tl:%1$ tM:%1$ tS% 1$ Tp% 2$ s%n%4$ s:% 5$ s% 6$ s% n", where the time format may not be what we expected, and there is a newline% n in it. For example, if you want to change the time format similar to the log4j above, you can rewrite a replacement class (com.xxx.LogFormatter). The format is set to "1$ tY-%1$ tm-%1$ td% 1$ tH:%1$ tM:%1$ tS.%1$ tL% 4$ s% 2$ s% 5$ s% 6$ s% n". Modify $CATALINA_BASE/conf/logging.properties
Java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
Replace it with the following:
Java.util.logging.ConsoleHandler.formatter = com.xxx.LogFormatterorg.apache.juli.FileHandler.formatter = com.xxx.LogFormatter after reading the above, do you know how to use Log4j to output catalina.out logs in Tomcat? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.