Initialization of log4j

Source: Internet
Author: User
Tags log4j

Log4j is one of the most widely used logging frameworks.
The biggest question I've ever asked is why my program uses so much CPU after log4j. Is there a problem with log4j's design?

Here I put log4j common problems listed for your reference:

Log4j told me that it was not initialized correctly.

Phenomenon:
Occurs when the program is run
Log4j:no Appenders could is found for category (Some.category.name).
Log4j:please Initialize the log4j system properly.

Reason:
log4j log output requires a Appender,appender type with stdout,file,database table,syslog etc.
This error occurs if the specified logger is not and all of its ancestors are not appender.
Remember: log4j is not the default target appender.

Workaround:
The simplest is the ancestor setting of all logger appender.
Create a file under the program run Directory: log4j.properties
Content is:
Log4j.rootcategory=debug, stdout

Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.STDOUT.LAYOUT.CONVERSIONPATTERN=[%D{DD MMM yyyy hh:mm:ss,sss}] [%-5p] [%t] [%x] [%c] [%m]%n

And then use it in your program.
Private Category logger = Category.getroot (); Easiest

Or
Private Logger logger= Logger.getlogger (classname);

It's done.

Cond...

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.