Since it is an old article, some of the code in the article seems to be old, old text, see: http://blog.9cbs.net/changzheng/archive/2004/11/18/186220.aspx, now make a supplement article An article
We combine Apache's Commons Logging to do log management.
First download Commons logging:
http://mirrors.isc.org/pub/apache/jakarta/commons/logging/binaries/commons-logging-1.0.4.zip
Use the code to read the configuration file in the original text. PropertyConfigurator.configure ("Log4j.properties");
Such log4j's profile must be placed in the root directory to read, it is very inconvenient, we want to put it in the src directory. It is very simple to use Commons logging.
First, place the configuration file into the src directory, then you do not have to display the configuration file, just click on the code.
Log logger1 = logfactory.getlog ("console");
Where the LOG class and the LogFactory class are
Import org.apache.commons.logging.log;
Import org.apache.commons.logging.logfactory;
The rest of the code is not moving
Logger1.debug ("debug !!!");
Logger1.info ("info !!!");
Logger1.warn ("Warn !!!");
Logger1. Error ("Error !!!");
Logger1.fatal ("Fatal !!!");
The same is true for writing logs to the NT event manager.
Log logger2 = logfactory.getlog ("ntlog");
Mail's writing is pushed
Log logger3 = logfactory.getlog ("maillog");
OK, try it :)