2017-09-28 47 views
0

我正在嘗試使用JBERET實現在Java SE模式下運行JSR352 Java批處理程序。我可以看到我的main()方法得到執行。在這個main()方法中,我得到了一個工作操作員的處理並開始工作。JSR352 - JBERET - 如何檢查Java批處理程序作業日誌?

public static void main(String[] args) { 

    LoggingConfig logConfiguration = new LoggingConfig(); 

    logger.info("Begining Batch with JBeret approach"); 

    JobOperator jo = BatchRuntime.getJobOperator(); 
    long id = jo.start("PilotJob", null); 

    logger.info("End of Batch"); 

} 

但是,我的閱讀器,處理器,寫入器或偵聽器中沒有看到任何日誌語句被打印。

我有一個logging.properties定義並從我的項目src/main/resources/META-INF文件夾加載。我的main()方法中的日誌語句根據它進行打印,但是,我的讀寫器/處理器和偵聽器中的日誌語句根本不打印。

public class LoggingConfig { 
    public LoggingConfig() { 
     try { 
      // Load a properties file from class path that way can't be achieved 
      // with java.util.logging.config.file 

       final LogManager logManager = LogManager.getLogManager(); 
       try (final InputStream is = getClass().getResourceAsStream("/META-INF/logging.properties")) 
       { 
        logManager.readConfiguration(is); 
       } 

     } catch (Exception e) { 
      System.out.println("Error while reading Log configuration file"); 
      e.printStackTrace(); 
     } 
    } 
} 

爲什麼我的日誌報表(java的日誌庫)在我的Java批處理程序進行打印?

以下是main()方法的日誌。我可以清楚地看到工作已經開始,但不知道爲什麼批處理程序的日誌語句沒有打印出來。

INFO: App Begining Batch with JBeret approach - v1.0 
    INFO: org.jboss.weld.Version WELD-000900: 2.2.15 (Final) 
    INFO: org.jboss.weld.Bootstrap WELD-ENV-000014: Falling back to Java Reflection for bean-discovery-mode="annotated" discovery. Add org.jboss:jandex to the classpath to speed-up startup. 
    INFO: org.jboss.weld.Bootstrap WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 
    WARN: org.jboss.weld.Interceptor WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled 
    WARN: org.jboss.weld.Interceptor WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled 
    DEBUG: org.jboss.weld.Bootstrap WELD-000100: Weld initialized. Validating beans 
    DEBUG: org.jboss.weld.Reflection WELD-000620: interface javax.enterprise.inject.Intercepted is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable. 
    DEBUG: org.jboss.weld.Reflection WELD-000620: interface javax.enterprise.inject.Decorated is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.   
    FINE: javax.batch.runtime.BatchRuntime Loaded BatchContainerServiceProvider with className = org.jberet.operations.JobOperatorImpl 
    TRACE: org.jberet JBERET000022: resume is not implemented for local transactions 
    DEBUG: org.jberet JBERET000017: Persisted [email protected] with id 6 
    DEBUG: org.jberet JBERET000017: Persisted [email protected] with id 6 
    INFO: App End of Batch 

這是一個Listener代碼,它有一個Sysout和Log語句。他們都沒有得到我的Eclipse控制檯打印。

import java.util.logging.Logger; 

import javax.batch.api.listener.AbstractJobListener; 

public class PilotLibJobListener extends AbstractJobListener { 

    private final static Logger logger = Logger.getLogger("PilotLibJobListener"); 

    public void beforeJob() { 
     BatchListenerRecorder.batchListenersCountDownLatch.countDown(); 
     System.out.println("Before Job"); 
     logger.info("MyJobListener.beforeJob"); 
    } 

    @Override 
    public void afterJob() { 
     BatchListenerRecorder.batchListenersCountDownLatch.countDown(); 
     logger.info("MyJobListener.afterJob"); 
    } 

} 

回答

0

要查詢作業的執行狀態,你可以直接調用相應的API上JobOperator,例如,public JobExecution getJobExecution(long executionId)。返回的JobExecution對象包含最新的數據。

對於作業存儲庫,如果jdbc作業存儲庫對您的應用程序來說過重,則可以選擇內存作業存儲庫。但是對於默認的H2數據庫,您可以配置爲具有基於嵌入式或基於文件的H2數據庫,而不是客戶端 - 服務器模式,以限制資源消耗。

對於日誌記錄問題,您可以創建一個JIRA issuegithub issue,並附上一個可重複的測試應用程序?

+0

我的jberet屬性有一個H2數據庫配置爲作業回購,但是,我的問題是更多的朝着我的java批處理程序內的日誌語句沒有得到打印。我可以看到主程序中的日誌語句正在打印,但不是jsr352類中的日誌語句(reader/writer/processor/listener) – yathirigan

+0

我嘗試按照此https中的建議設置系統屬性org.jboss.logging.provider ://developer.jboss.org/thread/272789但是,仍然無法正常工作。我已經創建了一個github問題https://github.com/jberet/jsr352/issues/102這個問題 – yathirigan