Log4j: log4j: log4j: log4j: log4j: log4j: log4j: log4j: log4j: log4j: log4j
Solutions:
Create a text file called log4j.properties in your project’s SRC directory. Remember it is a text file, not a folder
Then add something like this to your text file:
# Configure logging for testing: optionally with log file
#log4j.rootLogger=debug,appender
log4j.rootLogger=info,appender
#log4j.rootLogger=error,appender
#\u8F93\u51FA\u5230\u63A7\u5236\u53F0
log4j.appender.appender=org.apache.log4j.ConsoleAppender
#\u6837\u5F0F\u4E3ATTCCLayout
log4j.appender.appender.layout=org.apache.log4j.TTCCLayout
Copy the code
I went to == without success no reason to keep looking
Intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect intersect
Basically, the log4j configuration file is not found and the application does not display the configuration when it executes, whereas log4j, Depend on the Thread. GetContextClassLoader (.) getResource () these two classes to locate the file by default information rather than directly to check his file system, To put Log4j in place, you need to know the search strategy of the class loader. Log4j does not provide a default configuration for input to either the console or the file system, although it may be disabled in some environments. It beeps for a long time, just like my brief explanation at the beginning of this article
Doesn’t solve the problem, so move on:
Simply put, log4j’s classes and properties files are not in the scope of the same classloader.
In Java classloader 2, methods are arranged in a hierarchical parent-child relationship. When a classloader of a subclass needs to find a class or resource, It first represents the parent class requirement.
Log4j only uses the default class loading mechanism forname() to conclude: so, if you have problems, try loading classes or resources yourself
Looks like Apache’s log didn’t help either
Finally, I found an answer on the Internet:
Insert this method into the main function and you can print your own log information
BasicConfigurator.configure(); // Automatically and quickly use the default Log4j environment.Copy the code
Then test the program without problems:
————————————————————————————
BUT even though the log message is printed, the configuration problem is not solved
From: www.cnblogs.com/huxinga/p/6…