Change the tomcat internal default log mode to log4j unsuccessful records

Source: Internet
Author: User

Official: https://tomcat.apache.org/download-70.cgi

Download is the zip version: Apache-tomcat-7.0.69.zip

Follow the official documentation:
Https://tomcat.apache.org/tomcat-7.0-doc/logging.html

  1. The new file is called log4j.properties , the content is not (copy of the official website) into the $CATALINA_BASE/lib next.
  2. Download log4j, Required v1.2.x ,: https://logging.apache.org/log4j/1.2/download.html, download the zip version log4j-1.2.17.zip. Extract the Log4j-1.2.17.jar.
  3. Download tomcat-juli.jar and tomcat-juli-adapters.jar . See the Add-ons documentation, as in the previous download of Tomcat. Just Extrax under the mark.
  4. Put it and put it in log4j.jar tomcat-juli-adapters.jar $CATALINA_HOME/lib .
  5. tomcat-juli.jarReplace with $CATALINA_HOME/bin/tomcat-juli.jar .
  6. Delete $CATALINA_BASE/conf/logging.properties java.util.logging to avoid generating 0-length log files.
  7. Start Tomcat.

    However, after pressing the above, it does not print the log properly. Show:

    Log4j:warn No Appenders could is found for logger (Org.apache.catalina.startup.Catalina).
    Log4j:warn Initialize the log4j system properly.
    Log4j:warn See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Logs folder, there are five more log files. Two have content: catalina.out , localhost . Catalina.out is the above words.
LocalHost is the record of contextinitialized.

When I renamed the log4j.properties above and started Tomcat, there was only one file in logs. The content is empty.

Note that Log4j.properties still works.

But the log cannot be lost.

Report:
List of files involved:

    • Apache-tomcat-7.0.69.zip,md5:296a27d0cc455d41ab5746a6ba34daca
    • Log4j-1.2.17.zip,md5:5bcf80352b7d622df0dbcb44e50cf0bb
    • Log4j-1.2.17.jar, md5:fb87bd84e336ca3dc6b6c108f51bf25e
    • Tomcat-juli.jar, md5:9f57b2d40f301891ba6c2ec3ddce5c85
    • Tomcat-juli-adapters.jar, md5:fd1b9a734ec046565122595a92b6a054

Log4j.properties's Content

Og4j.rootlogger = INFO, catalina# Define all the Appenderslog4j.appender.CATALINA = Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.CATALINA.File = ${catalina.base}/logs/ Catalinalog4j.appender.CATALINA.Append = Truelog4j.appender.CATALINA.Encoding = utf-8# Roll-over theLogOnce per Daylog4j.appender.CATALINA.DatePattern ='. 'Yyyy-mm-dd'. Log 'Log4j.appender.CATALINA.Layout= Org.apache.log4j.PatternLayoutlog4j.appender.CATALINA.Layout. Conversionpattern =%d[%t]%-5P%c-%m%nLog4j.appender.LOCALHOST = Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.LOCALHOST.File = ${ Catalina.base}/logs/localhostlog4j.appender.localhost.append = Truelog4j.appender.LOCALHOST.Encoding = utf-8Log4j.appender.LOCALHOST.DatePattern ='. 'Yyyy-mm-dd'. Log 'Log4j.appender.LOCALHOST.Layout= Org.apache.log4j.PatternLayoutlog4j.appender.LOCALHOST.Layout. Conversionpattern =%d[%t]%-5P%c-%m%nLog4j.appender.MANAGER = Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.MANAGER.File = ${catalina.base}/ Logs/managerlog4j.appender.manager.append = Truelog4j.appender.MANAGER.Encoding = utf-8Log4j.appender.MANAGER.DatePattern ='. 'Yyyy-mm-dd'. Log 'Log4j.appender.MANAGER.Layout= Org.apache.log4j.PatternLayoutlog4j.appender.MANAGER.Layout. Conversionpattern =%d[%t]%-5P%c-%m%nLog4j.appender.host-manager = Org.apache.log4j.dailyrollingfileappenderlog4j.appender.host-manager.file = ${ Catalina.base}/logs/host-managerlog4j.appender.host-manager.append = Truelog4j.appender.host-manager.encoding = utf-8Log4j.appender.host-manager.datepattern ='. 'Yyyy-mm-dd'. Log 'Log4j.appender.host-manager.Layout= Org.apache.log4j.patternlayoutlog4j.appender.host-manager.Layout. Conversionpattern =%d[%t]%-5P%c-%m%nLog4j.appender.CONSOLE = Org.apache.log4j.ConsoleAppenderlog4j.appender.CONSOLE.Encoding = utf-8Log4j.appender.CONSOLE.Layout= Org.apache.log4j.PatternLayoutlog4j.appender.CONSOLE.Layout. Conversionpattern =%d[%t]%-5P%c-%m%n# Configure which loggersLogto which appenderslog4j.logger.org.apache.catalina.core.ContainerBase. [Catalina]. [localhost] = INFO, LOCALHOSTlog4j.logger.org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/manager] = INFO, MANAGERlog4j.logger.org.apache.catalina.core.ContainerBase. [Catalina]. [localhost]. [/host-manager] = INFO, Host-manager

Copy file script for repro:

ImportShutilImportOsImportSyscatalina_base ="c:/apache-tomcat-7.0.69/"# move Log4j.properties to $CATALINA _base/libShutil.copyfile ("Log4j.properties", catalina_base+"Lib/log4j.properties")# Move Log4j.jar and Tomcat-juli-adapters.jar to $CATALINA _home/libShutil.copyfile ("Log4j-1.2.17.jar", catalina_base+"Lib/log4j.jar") Shutil.copyfile ("Tomcat-juli-adapters.jar", catalina_base+"Lib/tomcat-juli-adapters.jar")# Replace $CATALINA _home/bin/tomcat-juli.jar with Tomcat-juli.jarShutil.copyfile ("Tomcat-juli.jar", catalina_base+"Bin/tomcat-juli.jar")# $CATALINA _base/conf/logging.propertiesLoggingpath =catalina_base+"Conf/logging.properties"ifOs.path.isfile (Loggingpath): Os.remove (Loggingpath)Print "OK"

Change the tomcat internal default log mode to log4j unsuccessful records

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.