2015-10-20 56 views
1

我需要閱讀的src /資源的自定義log4j.properties,這是行不通的log4j屬性文件中捆綁入火花應用罐子被忽略

try{ 
    val inStream :InputStream= className.this.getClass.getClassLoader.getResourceAsStream("log4j.properties"); 

    logCfgProps.load(inStream) 

} catch { 
    case e: Throwable=> 
    e.printStackTrace() 
    log.error("log.properties file not present") 
} 

PropertyConfigurator.configure(logCfgProps) 

這意味着在罐子捆綁log4j的被忽略。

我無法觸及spark home中conf目錄下的log4j屬性。

還有什麼其他的選擇?

編輯 一定有什麼地方錯了(在類路徑?) 因爲這樣做

val resource:URL = Thread.currentThread().getContextClassLoader() 
  .getResource("log4j.properties"); 
System.out.println("resource = " + resource); 

它指向的conf目錄下的log4j的,我不能修改,而我需要忽略。

如何做到這一點?

回答

2
  1. 你可以只給另一名到您的文件(並在代碼中使用它),所以與conf/log4j.properties沒有衝突。

  2. 您可以在類路徑中使用ClassLoader.getResources("log4j.properties")獲取給定名稱的所有資源,並選擇您想要的。