Log4j configuration in Tomcat and Engineering

Source: Internet
Author: User
The configuration fails according to many configuration steps on the Internet. Now let's look back at the inconsistency of most versions.

In addition, log4j is flexible in addition to managing logs for the entire container, it can also manage logs for a project. If there are only logs in the container, what should we do with the logs in JUnit? Therefore, project log management is also necessary.

Here is a configuration file that can be used.

Configuration of og4j1.3 in tomcat5:

  1. Disable Tomcat
  2. Download the commons logging package.
  3. Setcommons-logging.jarCopy to Tomcatcommon/libDirectory.
  4. Download the log4j 1.3 package.
  5. Copy log4j-1.3alpha-8.jar to Tomcatcommon/libDirectory.
  6. In Tomcatcommon/classesCreatelog4j.propertiesFile.
  7. Restart tomcat.

Log4j properties File
#
# Configures log4j as the Tomcat System Logger
#

#
# Configure the logger to output info level messages into a rolling log file.
#
Log4j. rootlogger = info, R, console

#
# To continue using the "Catalina. Out" file (which grows forever ),
# Comment out the above line and uncomment the next.
#
# Log4j. rootlogger = error, A1

#
# Configuration for standard output ("Catalina. Out ").
#
Log4j. appender. A1 = org. Apache. log4j. leleappender
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
#
# Print the date in iso8601 format
#
Log4j. appender. a1.layout. conversionpattern = % d [% T] %-5 p % C-% m % N

#
# Configuration for a rolling log file ("tomcat. log ").
#
Log4j. appender. r = org. Apache. log4j. dailyrollingfileappender
Log4j. appender. R. datepattern = '. 'yyyy-mm-dd
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
Log4j. appender. R. File = D:/tomcat/logs/tomcat. Log
Log4j. appender. R. layout = org. Apache. log4j. patternlayout
#
# Print the date in iso8601 format
#
Log4j. appender. R. layout. conversionpattern = % d [% T] %-5 p % C-% m % N

####################################
Log4j. appender. Console = org. Apache. log4j. leleappender
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
Log4j. appender. Console. Target = system. Out
Log4j. appender. Console. layout = org. Apache. log4j. patternlayout
#
# Print the date in iso8601 format
#
Log4j. appender. Console. layout. conversionpattern = % d [% T] %-5 p % C-% m % N
#
# Application logging options
#
# Log4j.logger.org. Apache = debug
# Log4j.logger.org. Apache = info
# Log4j.logger.org. Apache. Struts = debug
# Log4j.logger.org. Apache. Struts = info

Configure log4j1.3 in the project:

Create in the src directory of the projectlog4j.propertiesThe file is as follows:

#
# Configures log4j as the Tomcat System Logger
#

#
# Configure the logger to output info level messages into a rolling log file.
#
Log4j. rootlogger = info, console

#
# To continue using the "Catalina. Out" file (which grows forever ),
# Comment out the above line and uncomment the next.
#
# Log4j. rootlogger = error, A1

#
# Configuration for standard output ("Catalina. Out ").
#
Log4j. appender. A1 = org. Apache. log4j. leleappender
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
#
# Print the date in iso8601 format
#
Log4j. appender. a1.layout. conversionpattern = % d [% T] %-5 p % C-% m % N

####################################
Log4j. appender. Console = org. Apache. log4j. leleappender
#
# Edit the next line to point to your logs directory.
# The last part of the name is the log file name.
#
Log4j. appender. Console. Target = system. Out
Log4j. appender. Console. layout = org. Apache. log4j. patternlayout
#
# Print the date in iso8601 format
#
Log4j. appender. Console. layout. conversionpattern = % d [% T] %-5 p % C-% m % N
#
# Application logging options
#
# Log4j.logger.org. Apache = debug
# Log4j.logger.org. Apache = info
# Log4j.logger.org. Apache. Struts = debug
# Log4j.logger.org. Apache. Struts = info

 

Then OK. My project is struts spring hibernate, which can collect all the logs.

Refer:

Http://minaret.biz/tips/tomcatLogging

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.