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...