如何使用logback记录访客IP

时间:2019-03-26 10:58:48

标签: java spring-boot spring-cloud-sleuth

这是我的logback.xml,我使用spring-boot和spring-cloud-sleuth。我想记录访问我网站的每个用户的ip地址,但这不起作用。

<conversionRule conversionWord="ip" converterClass="com.zzl.springcloud.utils.IPAddressConverter" />
<springProperty scope="context" name="spring_application_name" source="spring.application.name" />
<springProperty scope="context" name="server_port" source="server.port" />

<property name="APP_ID" value="log-service"/>

<!-- appID | module | dateTime | level | requestID | traceID | requestIP | userIP | serverIP | serverPort | processID | thread | location | detailInfo-->
<property name="CONSOLE_LOG_PATTERN" value="%clr(${APP_ID}){blue}|%clr(${spring_application_name}){cyan}|%clr(%d{ISO8601}){faint}|%clr(%p)|%X{requestId}|%X{X-B3-TraceId:-}|%X{requestIp}|%X{userIp}|%ip|${server_port}|${PID}|%clr(%t){faint}|%clr(%.40logger{39}){cyan}.%clr(%method){cyan}:%L|%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<property name="FILE_LOG_PATTERN" value="${APP_ID}|${spring_application_name}|%d{ISO8601}|%p|%X{requestId}|%X{X-B3-TraceId:-}|%X{requestIp}|%X{userIp}|%ip|${server_port}|${PID}|%t|%.40logger{39}.%method:%L|%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>

0 个答案:

没有答案