2012-11-05 47 views
2

我有一個使用XMLConfiguration加載的配置文件(XML)。XMLConfiguration文件中的日誌更改

我需要確保這個XMLConfiguration實例更新(每30秒)。

對於這個問題,我有以下代碼:

XMLConfiguration configuration = new XMLConfiguration(configFile); 
configuration.setAutoSave(true); 

FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); 
strategy.setRefreshDelay(getRefreshDelay()); 
configuration.setReloadingStrategy(strategy); 

它的偉大工程,但事情是我要登錄這個XML文件進行任何更改。

有沒有辦法呢?

+0

請改善問題......你問的是如何登錄,或者你問如何檢查XML數據是否有變化?你想如何做日誌記錄,文本文件或什麼? – hyde

+0

感謝您的回覆 - 至於您的問題: 我想將更改記錄到日誌文件。 我想記錄的更改是xml文件中的更改。 我想我有一個答案 - 如果它是正確的,我會在幾秒內發佈它 – Noam

回答

2

我明白了!

所有我需要做的是這樣的:

 ConfigurationListener listener = new ConfigurationListener() { 

     @Override 
     public void configurationChanged(ConfigurationEvent event) { 
      if (!event.isBeforeUpdate()){ 
       System.out.println(event.getPropertyName() + " " + event.getPropertyValue()); 
      } 
     } 
    }; 
    configuration.addConfigurationListener(listener); 

它的工作原理!