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:
- Disable Tomcat
- Download the commons logging package.
- Set
commons-logging.jar
Copy to Tomcatcommon/lib
Directory.
- Download the log4j 1.3 package.
- Copy log4j-1.3alpha-8.jar to Tomcat
common/lib
Directory.
- In Tomcat
common/classes
Createlog4j.properties
File.
- 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.properties
The 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