雖然日誌級別設置爲INFO,但SLF4J仍在評估表達式。SLF4J-Log4J似乎沒有禁用日誌記錄
package com.ab.test.slf4j;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SimpleTest {
static final Logger logger = LoggerFactory.getLogger(SimpleTest.class);
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
logger.debug("Test " + testEnter());
logger.debug("Test {}", testEnter());
}
public static String testEnter() {
System.out
.println("If you see this it means your expression is evaluated :(");
return "test";
}
}
Log4J的屬性的文件:
log4j.rootLogger=INFO, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
執行命令輸出:
If you see this it means your expression is evaluated :(
If you see this it means your expression is evaluated :(
編輯:修正運行的輸出,如看到的那樣,表達式,但是日誌消息是沒有的。表達式不應該按照SLF4J's "Performance Logging"
我有slf4j-log4j12-1.6.4.jar,slf4j-api-1.6.4.jar和log4j-1.2.16.jar – 2011-12-27 10:47:37
@staffman對不起,我修改了輸出。 – 2011-12-27 10:53:54