如何对appender进行delare以及如何正确初始化log4j系统?

时间:2016-01-07 05:18:56

标签: java log4j

我需要生成我执行的java类的日志报告,当我运行代码时,我收到错误为“log4j:WARN没有找到记录器的appender(comparexmlf1.DomParser1)。 log4j:WARN请正确初始化log4j系统。“。现在我需要以下解决方案。 1.如何声明一个appender以及如何正确初始化log4j系统? 2.如何正确初始化log4j系统以及如何调用它们?

我的代码:

import org.apache.log4j.Logger;

public class DomParser1 {


final static Logger logger = Logger.getLogger(DomParser1.class);
 public static String si_orderid="";
 public static String si_unitid="";
 public static String si_parcelid="";
  public static String si_supplierid="";
  public static String sl_publicationyear_first="";


  public static void main(String[] args) throwstion,IOException 
{
   DomParser1 dp1=new DomParser1();
   DomParser2 dp3=new DomParser2();
   validatexml vx1=new validatexml();

  try { 


      File dir = new File("D:/xmlvalidator/QCSUCCESS");
      dir.mkdirs();
      File dir1=new File("D:/xmlvalidator/QCFAILED");
      dir1.mkdirs();
      File folder = new File("D:/xmlvalidator/IN PROCESS");
      File[] listOfFiles = folder.listFiles();
     String[] filename1=new String[50];
     String[] filename2=new String[50];
     String[] dirname1=new String[100];
     String my_new_str=null;
     String itemfile_dir=null;
     String si_isocode_val=null;

  }
catch (Exception e) 
  {
      logger.info("Error..!!!No Source Data Found");
      logger.info("pls check for valid marker file availability ");
      System.out.println("\n..!!!No Source Data Found");
      System.out.println("\ncheck for valid marker file availability ");

    // e.printStackTrace();
  }

我的log4j.properties:

#Root logger option
log4j.rootLogger=FATEL, file
#log4j.rootLogger=ERROR, stdout
#log4j.rootLogger=INFO, stdout
#log4j.rootLogger=FATEL, stdout


# Redirect log messages to console
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target=System.out
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%d
  {yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=E:/logfile.txt
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d
{yyyy-MM-dd HH:mm:ss}    %-5p %c{1}:%L - %m%n


# Rirect log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=E:/logfile.txt
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=
%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

任何人都可以帮忙解决我的问题吗?

0 个答案:

没有答案