MDC Attributes
Walter Forbes Hoehn (wassa)
wassa at memphis.edu
Thu Mar 19 18:56:42 EDT 2015
Any objection to a small change along the lines of the patch below? Exposing this information through MDC attributes is useful for interleaving logs in clustered configurations. Is there a better solution? If not, I’ll add a JIRA issue.
-WFH
Index: SLF4JMDCServletFilter.java
===================================================================
--- SLF4JMDCServletFilter.java (revision 7421)
+++ SLF4JMDCServletFilter.java (working copy)
@@ -43,6 +43,12 @@
/** MDC attribute name for client address. */
@Nonnull @NotEmpty public static final String CLIENT_ADDRESS_MDC_ATTRIBUTE = "idp.remote_addr";
+
+ /** MDC attribute name for host name of the server to which the current request was sent. */
+ @Nonnull @NotEmpty public static final String SERVER_ADDRESS_MDC_ATTRIBUTE = "idp.server_hostname";
+
+ /** MDC attribute name for port number to which the current request was sent. */
+ @Nonnull @NotEmpty public static final String SERVER_PORT_MDC_ATTRIBUTE = "idp.server_port";
/** MDC attribute name for container session ID. */
@Nonnull @NotEmpty public static final String JSESSIONID_MDC_ATTRIBUTE = "idp.jsessionid";
@@ -54,6 +60,8 @@
try {
MDC.put(Version.MDC_ATTRIBUTE, Version.getVersion());
MDC.put(CLIENT_ADDRESS_MDC_ATTRIBUTE, request.getRemoteAddr());
+ MDC.put(SERVER_ADDRESS_MDC_ATTRIBUTE, request.getServerName());
+ MDC.put(SERVER_PORT_MDC_ATTRIBUTE, Integer.toString(request.getServerPort()));
if (request instanceof HttpServletRequest) {
final HttpSession session = ((HttpServletRequest) request).getSession();
if (session != null) {
More information about the dev
mailing list