Log4j 2.0 advanced usage in development-default level (2)

Source: Internet
Author: User

Log4j 2.0 advanced usage in development-default level (2)

After several years of development, Log4j finally ushered in its sister version, Log4j 2.0. With the emphasis on reusable component development, in addition to developing a reusable log operation class from start to end, Apache provides us with a powerful log operation package-Log4j. Major upgrades must bring significant features. We will explain the disruptive features of 2.0 in the future. Today we will look at one of its features, the default level.

When using log4j 1. x, we all need to provide its own configuration file. If it is not provided, an error is reported. In version 2.0, the configuration file is no longer required. As for the configuration file that we didn't provide, it prints the error level information by default.

Let's take a look at the test code:

Package com. herman. log4j2. test; import org. apache. logging. log4j. logManager; import org. apache. logging. log4j. logger;/*** @ see log4j 2.0 default level: error * @ author Herman. xiong * @ date July 21, 2014 09:37:52 */public class Test0 {/*** if we do not provide the log4j configuration file in the project, log4j uses the default configuration, the method for obtaining the Logger in error * 4 */private static logger Logger = LogManager. getLogger (LogManager. ROOT_LOGGER_NAME); private static Logger log = LogManager. getLogger (Test0.class); private static Logger l = LogManager. getLogger (Test0.class. getName (); private static Logger rl = LogManager. getRootLogger (); public static void main (String [] args) {logger. trace ("trace"); logger. debug ("debug"); logger.info ("info"); logger. warn ("warn"); logger. error ("error"); logger. fatal ("fatal"); log. trace ("trace"); log. debug ("debug"); log.info ("info"); log. warn ("warn"); log. error ("error"); log. fatal ("fatal"); l. trace ("trace"); l. debug ("debug"); l.info ("info"); l. warn ("warn"); l. error ("error"); l. fatal ("fatal"); rl. trace ("trace"); rl. debug ("debug"); rl.info ("info"); rl. warn ("warn"); rl. error ("error"); rl. fatal ("fatal ");}}
Project:


09:41:29.150 [main] ERROR  - error09:41:29.151 [main] FATAL  - fatal09:41:29.151 [main] ERROR com.herman.log4j2.test.Test0 - error09:41:29.152 [main] FATAL com.herman.log4j2.test.Test0 - fatal09:41:29.152 [main] ERROR com.herman.log4j2.test.Test0 - error09:41:29.152 [main] FATAL com.herman.log4j2.test.Test0 - fatal09:41:29.152 [main] ERROR  - error09:41:29.152 [main] FATAL  - fatal

Welcome to my blog !!!

If you have any questions or problems, add the QQ group: 135430763 for feedback and learn together!



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.