我想做一個簡單的程序,它讀取屬性文件並將輸出記錄到控制檯,但我無法做到這一點。如何使用slf4j讀取.properties文件?
這是我的課:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class Slf4jSample {
public static void main(final String[] args) {
final Logger logger = LoggerFactory.getLogger(Slf4jSample.class);
logger.info("Hello World!");
}
private Slf4jSample() {
}
}
這是我的屬性文件:
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.logger.Slf4jSample=INFO, A1
當我運行這一點,給出了這樣的例外:
log4j:WARN No appenders could be found for logger (com.slf4j.Slf4jSample).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
請包括**完整的**堆棧跟蹤。 – 2011-12-20 07:52:31
你的classpath中需要的jar嗎? – hellectronic 2011-12-20 08:00:54
這是從http://stackoverflow.com/questions/8474954/read-properties-file-using-slf4j – oers 2011-12-20 08:19:54