Java Open Source project: A brief introduction to the use of log4j

Source: Internet
Author: User
Tags current time java open source projects log4j

First, the preface

Java has too many open source projects, this situation is absolutely in the five dynasties period of China's "Hundred schools", "blooming" prosperity. With Java technology, our project has little need to purchase the Java support development products, just put an open source product through the architect's hand, reasonable collocation and stitching, can make flexible, good performance of commercial products.

Undoubtedly, as a popular logging tool, log4j is one of the most brilliant aspects of Java open source projects. The author sees the Java project, nine to ten all adopt the log4j, investigate its reason, I think has the following points:

A log4j is supported by most Web application servers: As far as I know, Tomcat,weblogic,websphere,jboss supports log4j.

b Fast, Powerful: log4j configuration file to achieve the output to the console, files, roll back files, send log mail, output to the database log table, custom tags and so on a full set of functions. In the speed, from the beginning of the log4j, pay attention to the speed of operation has been put in the first place, and perseverance to improve and improve.

c) Simple and convenient to use: simply import a simple log4j-1.2.x.jar, and then write the following sentence at the beginning of the program class, private final static Logger log =logger.getlogger ( Classname.class);

This allows you to get a log-object log that can be easily written to a specific target.

Second, why need log4j? The commissioning of---project is the internal driving force of log4j

The original approach is to output the information to the screen (console), using the System.out.println provided by the JDK. But the downside of doing so is obvious:

A the output of the information is not flexible and cumbersome. For example, to output the execution of the file name, line number, current time, etc., println appears very primitive.

b If you want to change the content and format of the output, you need to recompile the source program.

c More seriously, if there are many println in the program, it will seriously affect the performance of the program.

Three, log4j use of several key points?

Root logger (Logger), Output end (appenders), and layout (layouts)

A to define the root logger in the format

Log4j.rootlogger = [level], appendName1, appendName2, ... appendnamen. The same logger can have multiple output terminals.

Level of ps:level (this level can be customized, the system provides the following levels by default)

debug//Debugging Information

info//General Information

warn//warning message

error//error message

fatal//Fatal error message

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.