log4j configuration file Load mode

Source: Internet
Author: User

Use the background:
Apache log4j is a powerful log file that we need to know how our configuration files are loaded and how they are loaded when we use the IDE to configure log4j in the project.
Load Mode:
(1), automatically load the configuration file:
LOG4J will default to find the source folder's configuration file at startup, either Log4j.properties or Log4j.xml, which requires an explanation of the source folder, source folder is the directory where the source files are stored, and when the Java files in our src are compiled, we can put the log4j configuration file in src or create a new resource source folder.

(1), manually load the configuration file:
If we want to manually load the configuration file, in the specific Java class add a sentence is OK, propertyconfigurator.configure ("log4j.properties");

It is important to note that the default read is the path to the project root directory, log4j.properties need to be placed in the root directory.

How to load:
The above describes the two load mode, now we need to understand how these configuration files are loaded, which of course need to see log4j source, take log4j.properties This configuration file example.
When we configure the log isolation level at Log4j.properties: log4j.rootcategory=info,stdout,r,log4j needs to load our configuration file.
Set Debug Debug in Logmanager you know, in the Logmanager method, level is the load log4j.properties levels, which is the same as what we configured.

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.