The version used here is for Log4j-1.2.15,jar resources to get the download. first, the introduction
During the normal development process, sometimes do not want to print all the logs to the same log file, in addition to the Java Engineering Integration log4j 1.x posting introduction of the use of a logger, Configuring multiple Appender Log4j.appender.d.threshold properties, you can also configure multiple logger in the configuration file log4j.properties. second, the specific configuration
In this configuration, in addition to the default Rootlogger, add a secondlogger, please note the specific configuration syntax.
log4j.rootlogger =debug,console,file Log4j.logger.secondLogger, Secondadpter Log4j.appender.console=org.apache.log4j.consoleappender log4j.appender.console.layout= Org.apache.log4j.PatternLayout log4j.appender.console.layout.conversionpattern=[%5p]%d{yyyy-mm-dd HH:mm:ss} [%t] ( %f:%l)%m%n Log4j.appender.file=org.apache.log4j.dailyrollingfileappender log4j.appender.file.file=./log/ First.log log4j.appender.file.datepattern= '. '
YYYY-MM-DD Log4j.appender.file.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=[%5P]%d{yyyy-mm-dd HH:mm:ss} [%t] (%f:%l)%m%n Log4j.appender.secondadpter=org.apache.log4j.dailyrollingfileappender log4j.appender.secondadpter.file=./log/ Second.log log4j.appender.secondadpter.datepattern= '. '
YYYY-MM-DD Log4j.appender.secondadpter.layout=org.apache.log4j.patternlayout LOG4J.APPENDER.SECONDADPTER.LAYOUT.CONVERSIONPATTERN=[%5P]%d{yyyy-mm-dd HH:mm:ss} [%t] (%f:%l)%m%n
iii. use of Secondlogger
You can write the log separately to the file by using the following methods to get Secondlogger./log/second.log:
Private static final Logger log = Logger.getlogger ("Secondlogger");
The Logger class introduced here is import Org.apache.log4j.Logger; Iv. Error Usage
It should be explained that the following classes are introduced:
Import Org.apache.commons.logging.Log;
Import Org.apache.commons.logging.LogFactory;
Writing to the./log/second.log log separately using the following Java code is a failure.
private static Final log = Logfactory.getlog (Secondlogger.class);