Log4j2. xml configuration and usage, log4j2. xml configuration

Source: Internet
Author: User

Log4j2. xml configuration and usage, log4j2. xml configuration

Log4j2. xml configuration
1 // package 2 import org. apache. logging. log4j. LogManager; 3 import org. apache. logging. log4j. Logger; 4 5 // configuration file 6 <? Xml version = "1.0" encoding = "UTF-8"?> 7 <Configuration> 8 <Appenders> 9 <Console name = "STDOUT" target = "SYSTEM_OUT"> 10 <PatternLayout pattern = "% d %-5 p [% t] % C {2} (% F: % L)-% m % n "/> 11 </Console> 12 </Appenders> 13 <Loggers> 14 <logger name =" com. opensymphony. xwork2 "level =" debug "/> 15 <logger name =" org. apache. struts2 "level =" debug "/> 16 <Root level =" info "> 17 <AppenderRef ref =" STDOUT "/> 18 </Root19 </Loggers> 20 </Configuration>

LogUtil class


1 package cn.sxt.common.util;2 3 import org.apache.logging.log4j.LogManager;4 import org.apache.logging.log4j.Logger;5 6 public class LoggerUtil {7     public static final Logger LOGGER =  LogManager.getLogger();8 }




Log Level:

× Debug
× Info
× Warn
× Error
× Fatal
A level is higher than a level, but in specific development, there is no good article to explain how to select a level for adaptation. Record some of your opinions for future use.

=== Debug ===
The lowest level is generally not output during the actual operation of the system.

Therefore, this level of information can be used at will. Anyone who feels that it is helpful to know more about the system running status during debugging, such as the value of the variable, can output it for a look.

Of course, before each Debug call, you must add If judgment.

=== Info ===
This should be used to feedback the current status of the system to the end user. Therefore, the output information here should be of practical significance to the end user, that is, the end user must be able to understand what it means.

From a certain point of view, the information output by Info can be considered as part of a software product (just like the text on the interactive interface). Therefore, you need to be cautious about it.

=== Warn, Error, Fatal ===
Warnings, errors, and serious errors should all be detected in an abnormal state during system operation. The difference between them is that it is not that simple to distinguish between them. I roughly distinguish it like this:

The so-called warning should be that at this time some repairs should be carried out, and the system should be able to be restored to a normal state, and the system should be able to continue running.

The so-called error means that some corrective work can be carried out, but it cannot be determined that the system will work normally. In a future stage, the system may be due to the current problem, it may cause an irreparable error (such as downtime), but it may still work until it is stopped, and no serious problem occurs.

The so-called Fatal is very serious. It is certain that this error cannot be fixed, and if the system continues to run, it will inevitably become messy. At this time, the best measure is not to try to restore the system status to normal, but to keep the system valid data as much as possible and stop running.

That is to say, the specific one in Warn, Error, and Fatal is determined based on the potential impact of the current problem on the future. If there is no impact on the future, warning: If it must be a serious problem in the future, then Fatal will not be able to determine what will happen, then Error will occur.

<Reference: http://blog.chinaunix.net/uid-26434689-id-3017353.html>

Related Article

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.