Undertow访问日志问题

时间:2020-03-06 00:28:30

标签: logging undertow

关于访问日志,我面临一个奇怪的问题。当我以jar运行应用程序时,访问日志中的消息显示部分正确。但是,当我在IDE中调试应用程序时,看不到此问题。

我正在如下使用Undertow及其AccessLogHandler-

Undertow.builder().setHandler(new AccessLogHandler(new RequestLimitingHandler(new RequestLimit(1000, 1000), getRestEasyServlet(config)), new Slf4jAccessLogReceiver(LoggerFactory.getLogger("com.pkg.logging")), "combined", Server.class.getClassLoader()))

package com.pkg.logging;
import org.slf4j.Logger;

import io.undertow.server.handlers.accesslog.AccessLogReceiver;

public class Slf4jAccessLogReceiver implements AccessLogReceiver {
    private final Logger logger;

    public Slf4jAccessLogReceiver(final Logger logger) {
        this.logger = logger;
    }

    @Override
    public void logMessage(String message) {
        logger.info(message);
    }
}

以下是当我以jar运行此应用程序时的消息-

2020-03-05 15:40:31,298 INFO [XNIO-1 task-1] class=logging %h %l %u %t "POST /entities/176ce8d1-ded8-3cbd-b18a-bfb3c0a7b1ea HTTP/1.1" %s %b "%{i,Referer}" "%{i,User-Agent}"

2020-03-05 15:40:41,625 INFO [XNIO-1 task-2] class=logging %h %l %u %t "POST /entities/176ce8d1-ded8-3cbd-b18a-bfb3c0a7b1ea HTTP/1.1" %s %b "%{i,Referer}" "%{i,User-Agent}"

就像我说的那样,当我从IDE运行相同的服务器代码并注意到日志时,我没有看到此问题。

以下是我正在使用的lib版本-

compile group: 'io.undertow', name: 'undertow-core', version: '2.0.14.Final'
compile group: 'io.undertow', name: 'undertow-servlet', version: '2.0.14.Final'
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.6.1.Final'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'

JDK-11

以下是log4j2文件-

<Configuration status="DEBUG">
    <Properties>
        <Property name="logPath">${env:logPath:-/home/}</Property>
    </Properties>
    <Appenders>
        <RollingRandomAccessFile name="File" fileName="${logPath}/yjava_jetty.out"
                                 filePattern="${logPath}server-%d{MM-dd-yyyy}-%i.log.gz">
            <PatternLayout alwaysWriteExceptions="false">
                <Pattern>\{"t":"%d","l":"%p","th":"%t","cl":"%c{1}",%m%enc{%throwable{100}}{JSON}"\}%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="500 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>

        <RollingRandomAccessFile name="AccessLog" fileName="${logPath}/access"
                                 filePattern="${logPath}/access-%d{MM-dd-yyyy}-%i.log.gz">
            <PatternLayout>
                <!--<Pattern>%d %p [%t] class=%c{1} %m%throwable{10}%n</Pattern>-->
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %msg%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>
            <DefaultRolloverStrategy  max="4">
                <Delete basePath="${logPath}" maxDepth="2">
                    <IfFileName glob="access-*.log.gz" />
                    <IfLastModified age="4h" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Logger name="com.pkg.logging" level="INFO" additivity="false">
            <AppenderRef ref="AccessLog"/>
        </Logger>
        <Logger name="io.undertow.request.dump" level="INFO" additivity="false">
            <AppenderRef ref="AccessLog"/>
        </Logger>
        <Root level="INFO" additivity="false">
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
</Configuration>

0 个答案:

没有答案