我使用log4j的爲在我的項目記錄。我試過下面的代碼,但它在控制檯上打印而不是在文件中。任何人都可以提出缺什麼,我使用log4j的首次log4j的:在文件不登錄log.out
代碼:
public void testCase1() {
System.out.println("In test method 1 now");
Logger log = Logger.getLogger(DisplayCtrlTestCases.class.getName());
log.debug("Hello this is a debug message");
log.info("Hello this is an info message");
}
log4j.properties:
# Define the root logger with appender file
#log = /usr/home/log4j
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
O/P是這樣的:
run:
[java] log4j:WARN No appenders could be found for logger (ServPackage.Display).[TestNG] Running:
[java] log4j:WARN Please initialize the log4j system properly.
[java]
[java] log4j:WARN See logging.apache.org/log4j/1.2/faq.html#noconfig for more info. /home/admin/A/In/Servlet/testng.xml
[java]
[java]
[java] In test method 1 now
是你的類路徑中的log4j.properties?你可以顯示CONSOL輸出嗎? – Jens
是正在創建的log.out文件嗎? –
時在類路徑中找不到log4j.properties典型警告 –