public class LogWebRequestFilter extends Object implements org.springframework.web.server.WebFilter
Mapped Diagnostic Context(映射调试上下文)
中,用于输出到日志文件中。
| 请求信息 | |
| %X{method} | 请求类型:GET、POST |
| %X{requestURL} | 完整的URL |
| %X{requestURLWithQueryString} | 完整的URL,含querydata |
| %X{requestURI} | 不包括host信息的URL |
| %X{requestURIWithQueryString} | 不包括host信息的URL,含querydata |
| %X{queryString} | Querydata |
| 客户端信息 | |
| %X{remoteAddr} | 用户IP地址 |
| %X{remoteRealIp} | 客户端的真实ip地址 |
| %X{userAgent} | 用户浏览器 |
| %X{referrer} | 上一个链接 |
| Modifier and Type | Field and Description |
|---|---|
static String |
MDC_COST_TIME
HTTP cost time
|
static String |
MDC_METHOD
HTTP request method
|
static String |
MDC_QUERY_STRING
query string
|
static String |
MDC_REFERRER
referrer
|
static String |
MDC_REMOTE_ADDR
客户端的ip地址(如果服务前面是 NGINX 转发过来的,那么就是它的 ip 地址)
|
static String |
MDC_REMOTE_REAL_IP
客户端的真实ip地址
|
static String |
MDC_REQUEST_SERVER_INFO
请求服务器域名+接口地址信息
|
static String |
MDC_REQUEST_URI
不包括host信息的URL
|
static String |
MDC_REQUEST_URI_WITH_QUERY_STRING
不包括host信息的URL,包括query string
|
static String |
MDC_REQUEST_URL
取得当前的request URL,不包括query string
|
static String |
MDC_REQUEST_URL_WITH_QUERY_STRING
取得当前的request URL,包括query string
|
static String |
MDC_START_TIME
HTTP request start time
|
static String |
MDC_STATUS
HTTP response status
|
static String |
MDC_USER_AGENT
user agent
|
| Constructor and Description |
|---|
LogWebRequestFilter(boolean logOnFilter,
boolean putRequestInfoToMDC)
记录web请求的日志信息
|
LogWebRequestFilter(boolean logOnFilter,
boolean putRequestInfoToMDC,
String pattern)
记录web请求的日志信息
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearMDC()
清除MDC下文中设置的信息,只有当前对象自己设置的MDC才能被清除。
|
reactor.core.publisher.Mono<Void> |
filter(org.springframework.web.server.ServerWebExchange exchange,
org.springframework.web.server.WebFilterChain filterChain) |
protected void |
putRequestInfo(org.springframework.http.server.reactive.ServerHttpRequest request,
String startTime)
设置内容到MDC中
|
public static final String MDC_START_TIME
public static final String MDC_COST_TIME
public static final String MDC_STATUS
public static final String MDC_METHOD
public static final String MDC_REQUEST_SERVER_INFO
public static final String MDC_REQUEST_URL
public static final String MDC_REQUEST_URL_WITH_QUERY_STRING
public static final String MDC_REQUEST_URI
public static final String MDC_REQUEST_URI_WITH_QUERY_STRING
public static final String MDC_QUERY_STRING
public static final String MDC_REMOTE_ADDR
public static final String MDC_REMOTE_REAL_IP
public static final String MDC_USER_AGENT
public static final String MDC_REFERRER
public LogWebRequestFilter(boolean logOnFilter,
boolean putRequestInfoToMDC)
logOnFilter - 是否在 filter(ServerWebExchange, WebFilterChain)
输出 log 日志,用于当前过滤器(默认值:false)putRequestInfoToMDC - 是否将请求的信息放入MDC中,默认只放 MDC_START_TIME、
MDC_COST_TIME、MDC_STATUS 这个key(默认值:false)public LogWebRequestFilter(boolean logOnFilter,
boolean putRequestInfoToMDC,
String pattern)
logOnFilter - 是否在 filter(ServerWebExchange, WebFilterChain)
输出 log 日志,用于当前过滤器(默认值:false)putRequestInfoToMDC - 是否将请求的信息放入MDC中,默认只放 MDC_START_TIME、
MDC_COST_TIME、MDC_STATUS 这个key(默认值:false)pattern - MDC_START_TIME 日期格式化 patternpublic reactor.core.publisher.Mono<Void> filter(org.springframework.web.server.ServerWebExchange exchange, org.springframework.web.server.WebFilterChain filterChain)
filter in interface org.springframework.web.server.WebFilterprotected void putRequestInfo(org.springframework.http.server.reactive.ServerHttpRequest request,
String startTime)
request - 客户端请求信息startTime - 请求开始时间public void clearMDC()
Copyright © 2018–2019. All rights reserved.