Log4j 2.0 advanced usage in development-console output with simple configuration (3), log4j usage

Source: Internet
Author: User

Log4j 2.0 advanced usage in development-console output with simple configuration (3), log4j usage
Log4j 2.0 has recently ushered in major version upgrades. In addition to the deadlock bug in 1.x, the performance is also improved by 10 times.
The new features are also available in the latest version. The configuration file is not limited to the xml and java properties files. Json and yaml configuration files are supported.
The use of logs is often used in our daily development. Many experts have also encountered log deadlocks. Asynchronous log processing is introduced in 2.0. The deadlock problem can be solved.
Well, let's go to its helloworld.
Let's take a look at its simple configuration today. Configure the logger output to the console, and set it to info-level output.
Check the java code:

Package com. herman. log4j2. test; import org. apache. logging. log4j. logManager; import org. apache. logging. log4j. logger;/*** @ see log4j 2.0 simple configuration using console Appender * @ author Herman. xiong * @ date July 21, 2014 14:32:55 */public class Test1 {/*** set the log level to info and the output location to console */private static Logger log = LogManager. getLogger (Test0.class); public static void main (String [] args) {log. trace ("trace"); log. debug ("debug"); log.info ("info"); log. warn ("warn"); log. error ("error"); log. fatal ("fatal ");}}

The configuration file of Log4j 2.0, in the format of log4j2. x. Check the xml configuration file code:

<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <Appenders> <! -- Standard output --> <Console name = "STDOUT" target = "SYSTEM_OUT"> <! -- Output format --> <PatternLayout pattern = "% d %-5 p [% t] % C {2} (% F: % L) -% m % n "/> </Console> </Appenders> <Loggers> <! -- Configure the recorder level --> <Root level = "debug"> <! -- Output settings --> <AppenderRef ref = "STDOUT"/> </Root> </Loggers> </Configuration>
Welcome to follow my blog !!!!

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


How does log4j record the console output information to a file?

Configure the console output information in the log4j configuration file to your configuration file.

The log4j Console does not output logs. jar packages are also available, that is, the startup project. Logs output in the console are not output at all.

Check whether your printed log statement has been written?

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.