Recent company projects need to go to the network to download pictures, according to different circumstances to save the log to a different file. Specifically, the ordinary log information output to a separate file, the picture download failed to save the log separately to another file for later backtracking.
log4j configuration file
Log4j.rootlogger=info, stdout #Root Logger Log4j.appender.stdout=org.apache.log4j.consoleappender Log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=[%p]
%-d{yyyy-mm-dd HH:mm:ss} [%c%m]%m%n #============================================================logger S Log4j.logger.commonlog=info, stdout, S Log4j.additivity.CommonLog = False log4j.appender.s=
Org.apache.log4j.RollingFileAppender Log4j.appender.s.file=d:/fbb/myworkspace_dw/common_ganji.log Log4j.appender.s.layout=org.apache.log4j.patternlayout log4j.appender.s.layout.conversionpattern=[%p]%-d{
Yyyy-mm-dd HH:mm:ss} [%c%m]%m%n #============================================================logger B Log4j.logger.errorlog=error, stdout, B Log4j.additivity.ErrorLog = False log4j.appender.b=
Org.apache.log4j.RollingFileAppender Log4j.appender.b.file=d:/fbb/myworkspace_dw/failed_ganji.log Log4j.appender.b.layout=org.apache.log4j.patternlayout Log4j.appender.b.layout.conversionpatteRn=[%p]%-d{yyyy-mm-dd Hh\:mm\:ss} [%c%m]%m%n
Using the example in your application
Import Org.apache.log4j.Logger;
public class Logutil {
private static Logger Clogger = Logger.getlogger ("Commonlog");
private static Logger Elogger = Logger.getlogger ("ErrorLog");
public static void Downerror (Class clz,string message) {
elogger.error (message+ "[" +clz.getname () + "]");
}
public static void info (Class clz,string message) {
clogger.info (message+ "[" +clz.getname () + "]");
}
public static void Debug (Class clz,string message) {
clogger.debug (message+ "[" +clz.getname () + "]");
}
public static void Warn (Class clz,string message) {
Clogger.warn (message+ "[" +clz.getname () + "]");
}
public static void error (Class clz,string message) {
clogger.error (message+ "[" +clz.getname () + "]");
}
Here's the Commonlog, Errorlog is configured in the log4j configuration file.
Mark it, shout it.