如果我通过logback启用tomcat访问日志,如下所示
logback.access:
enabled: true
compile group: 'net.rakugakibox.spring.boot', name: 'logback-access-spring-boot-starter', version: '2.5.0'
配置如下
<configuration>
<property name="LOG_HOME" value="${LOG_FILE_LOCATION:-/var/log/RSP}/${HOST_NAME}}"/>
<appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_HOME}/reservation_access.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/reservation_access-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%h %l %u [%{TraceId}i] %t "%r" %s %b %D</pattern>
</encoder>
</appender>
<appender-ref ref="ACCESS" />
</configuration>
它运行正常,但我无法理解它是如何选择%u的,documentation它被称为Remote user that was authenticated
所以tomcat如何知道谁被认证用户或任何人都可以提供如何生成这些访问日志的源代码。(我已经阅读了基本文章what is Access Log Valve)
如果我使用弹出启动属性启用访问日志,如下所示
server.tomcat.accesslog.pattern: '%h %l %u [%{TraceId}i] %t "%r" %s %b %D'
server.tomcat.accesslog.prefix: reservation_access
server.tomcat.accesslog.enabled: true
server.tomcat.accesslog.directory: /var/log/RSP/
server.tomcat.accesslog.suffix: .log
然后%u无效,
答案 0 :(得分:0)
logback-access-spring-boot-starter
从%u
读取HttpServletRequest#getRemoteUser()
的值。
在Spring世界中,HttpServletRequest.remoteUser()
通常由Spring Security填充。