log4j log4j.properties configuration for multiple projects under Tomcat

Source: Internet
Author: User
Tags file size tomcat log4j

About Tomcat under multiple projects configure a log4j.properties, to output the respective log of the problem,

After the actual work of the summary and investigation, here to make a summary and memo.

To lift the log4j configuration, our common configuration method is to create a log4j.properties file for each project and write the information of its own output log.

But I encountered a problem at work, in fact, the load of the Log4j.properties file and the project reference jar package has an inseparable relationship.

The two scenarios I encountered are as follows:

1. Log4j.jar exists in the lib of each project

The \webroot\web-inf\lib\ path under your project has the jar package required for your project, Log4j.jar exists under this path,

When your tomcat starts, it uses the Log4j.jar package under the respective path of the project to load each project's own log4j.properties.

At this time each project can use the Webroot\web-inf\classes\log4j.properties configuration under its own project,

Outputs the respective specified log files.

2, Log4j.jar does not exist in each project LIB, unified call Tomcat under the Lib Log4j.jar

At this time, you will find that multiple works of log4j.properties are loaded at once, but after loading will overwrite the previously loaded configuration content.

All of the project logs are typed into the log file set in the log4j.properties of the last loaded project.

The solution at this point is to configure all of the project's logs in the same log4j.properties file.

The log4j.properties file is then placed under Tomcat Tomcat 6.0\webapps\root\web-inf\.

Example: a project and B project two projects deployed under Tomcat, log4j.properties simple settings.

Log4j.rootlogger=info #======================================================================== #向控制台输出log信息 #===
===================================================================== Log4j.category.com=info, CONSOLE Log4j.appender.console=org.apache.log4j.consoleappender log4j.appender.console.layout= Org.apache.log4j.PatternLayout Log4j.appender.console.layout.conversionpattern=%d{hh:mm:ss.  SSS}%-5p%c%m%n #======================================================================== # A project log output configuration
Automatically generate a new log file when the file size is 500KB, maximum 10 #========================================================================
Log4j.category.com.a=info, ALOG Log4j.appender.alog.file=d:/workspace/aproject/log/a-web-log.log
Log4j.appender.alog=org.apache.log4j.rollingfileappender log4j.appender.alog.maxfilesize=500kb
log4j.appender.alog.maxbackupindex=10 Log4j.appender.alog.layout=org.apache.log4j.patternlayout Log4j.appender.alog.layout.conversionpattern=%d{mm/dd HH:mm:ss. SSS}%-5p%c%m%n #======================================================================== # b Project Log output config file size to 500KB automatically generate a new log file, maximum build 10 #===================== =================================================== Log4j.category.com.b=info, BLOG log4j.appender.BLOG.File=D:/
Workspace/bproject/log/b-web-log.log Log4j.appender.blog.=org.apache.log4j.rollingfileappender Log4j.appender.BLOG. MAXFILESIZE=500KB Log4j.appender.BLOG. maxbackupindex=10 Log4j.appender.BLOG. Layout=org.apache.log4j.patternlayout Log4j.appender.BLOG. Layout. Conversionpattern=%d{mm/dd HH:mm:ss.
 SSS}%-5p%c%m%n

About log4j.properties specific settings can be found in the detailed explanation of other articles, here do not repeat.

It is important to note that the Scarlet Letter section is the name of the package in your project that needs to output the log portion of the code.

The path of a project's function code Save: Aproject\src\com\a\

B Project's function code save path: bproject\src\com\b\

In other words, each project should be developed in such a way that it is best to differentiate it under COM with a distinct folder name in order to differentiate the project against which the output log is made.

The problems encountered at work are the most valuable, and I believe this is also my most valuable asset.

Even if it's a simple question, I think it's worth it, and maybe it will help a lot of people.

The choice summarizes and organizes, also precisely is oneself becomes rich the first step, hoped that we all can become a wealthy person.

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.