2013-04-01 177 views
1

我正在使用log4j ogging爲我的項目。不幸的是,我無法在手動havelogged的應用程序中記錄信息級別......儘管它完美地記錄了數據庫日誌!log4j信息級別不記錄信息

這裏是我的屬性文件:

log4j.rootLogger=OFF 

log4j.appender.serviceLog=org.apache.log4j.RollingFileAppender 
log4j.appender.serviceLog.File=C:/Users/prateekg/Desktop/log4j/log 

log4j.appender.dbLog=org.apache.log4j.RollingFileAppender 
log4j.appender.dbLog.File=C:/Users/prateekg/Desktop/log4j/dbLog 

log4j.appender.serviceLog.MaxFileSize=1MB 
log4j.appender.serviceLog.MaxBackupIndex=1 

log4j.appender.serviceLog.layout=org.apache.log4j.PatternLayout 
log4j.appender.serviceLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 

log4j.appender.dbLog.layout=org.apache.log4j.PatternLayout 
log4j.appender.dbLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 

log4j.category.serviceLog=INFO,serviceLog 
log4j.category.org.springframework.jdbc=DEBUG, dbLog 

編輯:

這是我的日誌代碼:

public static Logger logger = Logger.getLogger(Controller.class); 
Boolean commit=false; 
public Controller(DashBoardDAO dao,MessageProcessor mp, HandlerFactory hf, ToXML xml) 
{ 
    this.dao=dao; 
    this.mp=mp; 
    this.hf=hf; 
    this.xml=xml; 
    PropertyConfigurator.configure("log4j.properties"); 
} 

public Boolean controlFlow(Message message) 
{ 
    Handler handler=null; 
    String data[]=null; 
    Boolean flag=false; 

    int count=0; 

    handler=initializeHandlerFactory(message); 
    data=getMessage(handler,message); 
    flag=validate(data); 
    count=getEventCount(data); 
    //commit=mp.flag1; 
    //System.out.println("The flag is "+flag); 

    if(flag) 
    { 
     System.out.println("inside flag"); 
     String elementNames[]=dao.getElementNames(Integer.parseInt(data[0])); 
     System.out.println("No of tags "+elementNames.length); 
     logger.info("No of tags in the generated XML is "+elementNames.length); 
     File xmlFile=xml.convertToXML(elementNames, data); 
     logger.info("Temporary XML File created"); 
     logger.info("Data sent for insertion"); 
     dao.insert(count, data,xmlFile); 
     Boolean f=xmlFile.delete(); 
     System.out.println("Temp XML file Deleted: "+f); 
     if(f) 
     { 
     logger.info("Temporary XML File deleted"); 
     commit=mp.flag1; 
     } 
     else 
      logger.info("Error in deleting temporary XML File"); 
    } 
+1

請在您的服務中發佈日誌代碼嗎? – OQJF

+0

您的rootLogger已關閉,您似乎沒有定義自定義記錄器。嘗試打開根記錄器併爲其添加appender。 –

+0

當我添加一個rootlogger一切從一個z被記錄在文件中..我只想要在文件中的信息級別日誌記錄..! – Chandeep

回答

1

要麼你需要定義你的記錄作爲Logger.getLogger("serviceLog")或定義一個定製的appender與您的分類匹配

log4j.category.my.package.Controller=INFO,serviceLog 

或包裹

log4j.category.my.package=INFO,serviceLog 

此外,調用PropertyConfigurator.configure("log4j.properties");是沒有必要的,因爲這是在啓動時擡頭通過log4j的默認配置文件名。