If you're just building a Java project and you don't want to put it in the SRC directory, you can use the following method to specify the location of the log4j.properties.
private void Initlog4jconfig () {
Properties props = null;
FileInputStream FIS = null;
try {
//Read configuration information from the configuration file dbinfo.properties
props = new Properties ();
FIS = new FileInputStream ("Config/log4j.properties");
Props.load (FIS);
Propertyconfigurator.configure (props),//Mount log4j configuration information
} catch (Exception e) {
e.printstacktrace ();
} Finally {
if (FIS!= null)
try {
fis.close ();
} catch (IOException e) {
e.printstacktrace (); c17/>}
fis = null;
}
The point is:
Propertyconfigurator.configure (props);
This sentence.
If you do not specify the following prompts:
The
Log4j:warn No Appenders could is found for logger (org.apache.activemq.thread.TaskRunnerFactory).
Log4j:warn Please initialize the log4j system properly.
Log4j:warn the Http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.