简体   繁体   English

未记录 TRACE 级别的消息。 log4j 如何启用跟踪日志记录级别

[英]TRACE level messages not being logged. log4j How to enable trace logging level

I'm currently working on a maven application that uses slf4j/log4j and I want to be able to output all log levels including trace to the console.我目前正在开发一个使用 slf4j/log4j 的 maven 应用程序,我希望能够 output 所有日志级别,包括到控制台的跟踪。 I've configured as follows:我已经配置如下:

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="ERROR">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%7pid] %-5p --- myapp              %-42.42c{1.} : %m%n" />
            <LevelRangeFilter maxLevel="TRACE" onMatch="ACCEPT" onMismatch="DENY"/>
        </Console>
    </Appenders>

    <Loggers>
        <Logger name="com.gpc.nar" level="ALL" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>
        <Root level="INFO">
            <!-- Console can still output logs from higher log levels. -->
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

Then I have a simple rest call that outputs each level to the console.然后我有一个简单的 rest 调用,将每个级别输出到控制台。

@RequestMapping(value = "/ping", method = RequestMethod.GET)
    public ResponseEntity<?> processPing() throws Exception {

        log.trace("trace");
        log.debug("debug");
        log.info("info");
        log.warn("warn");
        log.error("error");

        log.info("info enabled? : " + log.isInfoEnabled());
        log.info("trace enabled? : " + log.isTraceEnabled());

        return new ResponseEntity<>(HttpStatus.OK);
    }

Currently everything except trace is printed to the console.目前,除了跟踪之外的所有内容都打印到控制台。 Changing the level in my custom logger to error will prevent debug and warn from being printed, but setting the level to trace or all doesn't seem to enable trace.将自定义记录器中的级别更改为错误将阻止打印调试和警告,但将级别设置为跟踪或全部似乎不会启用跟踪。 log.isTraceEndable() always returns false and I'm not sure how to change it. log.isTraceEndable() 总是返回 false,我不知道如何更改它。

This behaviour might be due to missing minLevel in LevelRangeFilter .此行为可能是由于 LevelRangeFilter 中缺少minLevel所致

Class LevelRangeFilter. Class LevelRangeFilter。 This is a very simple filter based on level matching, which can be used to reject messages with priorities outside a certain range .这是一个非常简单的基于级别匹配的过滤器,可以用来拒绝优先级超出一定范围的消息 The filter admits three options LevelMin, LevelMax and AcceptOnMatch.该过滤器接受三个选项 LevelMin、LevelMax 和 AcceptOnMatch。 If the level of the LoggingEvent is not between Min and Max (inclusive), then Filter.如果 LoggingEvent 的级别不在 Min 和 Max(含)之间,则 Filter。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM