在web環境中加載log4j的配置文件時在web.xml中寫配置即可,在非web環境中加載log4j.PRoperties需要在main方法中添加
PropertyConfigurator.configure("log4j.properties")
但是在運行過程中出現filenotfondexception,按網上說的把配置文件放在src目錄下還是不能加載成功
此時總結了幾種解決辦法
1). 用絕對路徑,不推薦;
PropertyConfigurator.configure("D/workspace/test/src/log4j.properties")
2). 使用相對路徑:
a). 將log4j文件置于src/目錄下,配置中,PropertyConfigurator.configure("src/log4j.properties");
b). 將log4j文件置于項目的根下,配置中,PropertyConfigurator.configure("log4j.properties");
新聞熱點
疑難解答