我已经将
实际输出:
上面的示例链接:http://www.tutorialspoint.com/log4j/log4j_logging_levels.htm
log4j
从这里添加到构建路径中。编写了一个简单的方法来测试日志级别
,但它没有在控制台上打印任何内容。import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class LoggerLevelTest {
private static org.apache.log4j.Logger log = Logger
.getLogger(LoggerLevelTest.class);
public static void main(String[] args) {
log.setLevel(Level.WARN);
log.trace("Trace Message!");
log.debug("Debug Message!");
log.info("Info Message!");
log.warn("Warn Message!");
log.error("Error Message!");
log.fatal("Fatal Message!");
}
}
Log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="LEVEL">WARN</Property> <!-- default value -->
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="${sys:LEVEL}">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
实际输出:
log4j:WARN Continuable parsing error 2 and column 30
log4j:WARN Document root element "Configuration", must match DOCTYPE root "null".
log4j:WARN Continuable parsing error 2 and column 30
log4j:WARN Document is invalid: no grammar found.
log4j:ERROR DOM element is - not a <log4j:configuration> element.
log4j:WARN No appenders could be found for logger (LoggerLevelTest).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
预期输出:
Warn Message!
Error Message!
Fatal Message!
上面的示例链接:http://www.tutorialspoint.com/log4j/log4j_logging_levels.htm
.xml
或.properties
文件。我已经添加了.xml
文件,并且还更改了输出。 - paul.xml
文件的内容。鉴于您的输出中根元素名称(Configuration
)中的大写字母C
,我怀疑这是一个Log4j2配置文件,它无法与Log4j 1.2一起使用。 - Luke Woodward