Apache's common logging is a high-level log framework that does not implement real log writing capabilities, but relies on other log systems such as log4j or Java. util. logging. You can use the configuration file to set whether to use log4j or Java. util. logging.
Java. utl. Logging is used by default. If you want to use log4j, You need to configure it in three steps,
1. Create a log4j configuration file, such as log4j. proiperties:
Log4j. rootlogger = debug, A1
Log4j. appender. A1 = org. Apache. log4j. leleappender
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
Log4j. appender. a1.layout. conversionpattern = %-4r %-5 p [% T] % 37C % 3x-% m % N
These configurations allow log4j to output log information to the console. For details about log4j configuration, see the Apache log4j documentation.
2. Create a configuration file for commons-logging, commons-logging.properties:
Org. Apache. commons. Logging. logfactory = org. Apache. commons. Logging. impl. log4jfactory
Org. Apache. commons. Logging. impl. log4jfactory is a logfactory derived class implemented by commons-logging for log4j.
3. Write in the Code:
Log = logfactory. getlog (...);
Then you can use log to directly write log information, such
Log. debug ("...")
Log. Error ("...");
...
Note: Both configuration files must be under classpath.