From 2fcee5ae58e61c9c999606c9ff6ad3424644b4b5 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 24 Jan 2020 15:57:56 +0000 Subject: [PATCH] Append unique number to WebFlux server log prefix Closes gh-22039 --- .../server/reactive/ReactorServerHttpRequest.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java index e05f992c97d..9cd57c08c09 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.http.server.reactive; import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; +import java.util.concurrent.atomic.AtomicLong; import javax.net.ssl.SSLSession; @@ -47,6 +48,9 @@ import org.springframework.util.MultiValueMap; */ class ReactorServerHttpRequest extends AbstractServerHttpRequest { + private static final AtomicLong logPrefixIndex = new AtomicLong(0); + + private final HttpServerRequest request; private final NettyDataBufferFactory bufferFactory; @@ -181,8 +185,11 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { @Override @Nullable protected String initId() { - return this.request instanceof Connection ? - ((Connection) this.request).channel().id().asShortText() : null; + if (this.request instanceof Connection) { + return ((Connection) this.request).channel().id().asShortText() + + "-" + logPrefixIndex.incrementAndGet(); + } + return null; } }