我想使用log4j的記錄它的文件 這裏是代碼log4j的嘗試登錄文件
protected static Logger logger = Logger.getLogger(Application.class);
private static final String DIRECTORY = "/Users/me/Desktop";
private static final String EXTENSION = ".log";
protected void setupLogger(String fileName) {
SimpleLayout layout = new SimpleLayout();
FileAppender appender = new FileAppender(layout, DIRECTORY + "/logs/" + fileName + EXTENSION, false);
logger.addAppender(appender);
logger.setLevel((Level) Level.DEBUG);
}
,並在這裏是POM中,我使用http://pastebin.com/vXdFtzSU
,我的堆棧跟蹤得到的是這裏
Error:(40, 28) java: incompatible types: org.apache.log4j.FileAppender cannot be converted to org.apache.log4j.Appender
我想按照這個答案configure log4j to log to custom file at runtime
can you s你的導入聲明如何 – Raghu
import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.apache.log4j.FileAppender; –
嘗試從下面的命令mvn dependency:tree中找出依賴關係樹,並將其發佈到此處。有一個log4j jars.i的版本衝突,我認爲你需要從其他工件依賴中排除log4j。 –