我一直试图让log.debug在log4j中运行,但它根本不工作。下面是我的源代码
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestLog4J {
private static Log log = LogFactory.getLog(TestLog4J.class);
public static void main(String[] args) {
// following logs at FATAL level
if (log.isFatalEnabled()) {
log.fatal("Testing Fatal output");
}
// following logs at ERROR level
if (log.isErrorEnabled()) {
log.error("Testing Error output");
}
// following logs at WARN level
if (log.isWarnEnabled()) {
log.warn("Testing Warn output");
}
// following logs at INFO level
if (log.isInfoEnabled()) {
log.info("Testing Info output");
}
// following logs at DEBUG level
if (log.isDebugEnabled()) {
log.debug("Testing Debug output");
}
// following logs at TRACE level
if (log.isTraceEnabled()) {
log.trace("Testing Trace output");
}
}
}
这是我的log4j.properties ...我有一种有趣的感觉,log4f没有找到它。我该怎么说
# Global logging configuration
log4j.rootLogger=ALL, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern=[%p,%c{1}] %m%n
# Rolling log file output...
log4j.appender.fileout=org.apache.log4j.FileAppender
log4j.appender.fileout.File=spring-security-tutorial.log
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.conversionPattern=%d{ABSOLUTE} %5p %c{1},%t:%L - %m%n
log4j.appender.fileout.Append=false
答案 0 :(得分:0)
您如何指定log4j.properties
文件的位置?查看您是否选择正确的log4j.properties
的最简单方法是修改转换模式:
log4j.appender.stdout.layout.conversionPattern=[%p,%c{1}] TEST %m%n
并检查您的日志行是否包含前缀TEST
。