Skip to content

Commit f54f7f0

Browse files
committed
Add NetworkLogging config enabled property.
1 parent 4efc880 commit f54f7f0

9 files changed

Lines changed: 37 additions & 10 deletions

File tree

vertx-core/src/main/java/io/vertx/core/http/impl/HttpClientBuilderInternal.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.vertx.core.internal.http.HttpClientInternal;
1818
import io.vertx.core.internal.net.NetClientInternal;
1919
import io.vertx.core.net.ClientSSLOptions;
20+
import io.vertx.core.net.NetworkLogging;
2021
import io.vertx.core.net.ProxyOptions;
2122
import io.vertx.core.net.endpoint.LoadBalancer;
2223
import io.vertx.core.net.AddressResolver;
@@ -257,12 +258,13 @@ public HttpClientAgent build() {
257258
.protocol("http")
258259
.sslOptions(sslOptions)
259260
.build();
261+
NetworkLogging networkLogging = co.getTcpConfig().getNetworkLogging();
260262
transport = new TcpHttpClientTransport(
261263
tcpClient,
262264
co.getTracingPolicy(),
263265
co.isDecompressionEnabled(),
264-
co.getTcpConfig().getNetworkLogging() != null,
265-
co.getTcpConfig().getNetworkLogging() != null ? co.getTcpConfig().getNetworkLogging().getDataFormat() : null,
266+
networkLogging != null && networkLogging.isEnabled(),
267+
networkLogging != null ? networkLogging.getDataFormat() : null,
266268
co.isForceSni(),
267269
supportedVersions.contains(HttpVersion.HTTP_1_1) || supportedVersions.contains(HttpVersion.HTTP_1_0) ? (co.getHttp1Config() != null ? co.getHttp1Config() : new Http1ClientConfig()) : null,
268270
supportedVersions.contains(HttpVersion.HTTP_2) ? (co.getHttp2Config() != null ? co.getHttp2Config() : new Http2ClientConfig()) : null,

vertx-core/src/main/java/io/vertx/core/http/impl/tcp/TcpHttpClientTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static TcpHttpClientTransport create(NetClientInternal netClient,
6767
return new TcpHttpClientTransport(netClient,
6868
config.getTracingPolicy(),
6969
config.isDecompressionEnabled(),
70-
config.getTcpConfig().getNetworkLogging() != null,
70+
config.getTcpConfig().getNetworkLogging() != null && config.getTcpConfig().getNetworkLogging().isEnabled(),
7171
config.getTcpConfig().getNetworkLogging() != null ? config.getTcpConfig().getNetworkLogging().getDataFormat() : null,
7272
config.isForceSni(),
7373
config.getHttp1Config(),

vertx-core/src/main/java/io/vertx/core/net/NetworkLogging.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,37 @@
2323
@DataObject
2424
public class NetworkLogging {
2525

26+
private boolean enabled;
2627
private ByteBufFormat dataFormat;
2728

2829
public NetworkLogging() {
30+
enabled = NetworkOptions.DEFAULT_LOG_ENABLED;
2931
dataFormat = NetworkOptions.DEFAULT_LOG_ACTIVITY_FORMAT;
3032
}
3133

3234
public NetworkLogging(NetworkLogging other) {
35+
enabled = other.enabled;
3336
dataFormat = other.dataFormat;
3437
}
3538

39+
/**
40+
* @return {@code} when network logging is enabled
41+
*/
42+
public boolean isEnabled() {
43+
return enabled;
44+
}
45+
46+
/**
47+
* Set to true to enable network logging: Netty's pipeline is configured for logging on Netty's logger.
48+
*
49+
* @param enabled true for logging the network activity
50+
* @return a reference to this, so the API can be used fluently
51+
*/
52+
public NetworkLogging setEnabled(boolean enabled) {
53+
this.enabled = enabled;
54+
return this;
55+
}
56+
3657
/**
3758
* @return per stream Netty's logging handler's data format.
3859
*/

vertx-core/src/main/java/io/vertx/core/net/TcpEndpointConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public TcpEndpointConfig(TCPSSLOptions options) {
4747
setIdleTimeout(Duration.of(options.getIdleTimeout(), options.getIdleTimeoutUnit().toChronoUnit()));
4848
setReadIdleTimeout(Duration.of(options.getReadIdleTimeout(), options.getIdleTimeoutUnit().toChronoUnit()));
4949
setWriteIdleTimeout(Duration.of(options.getWriteIdleTimeout(), options.getIdleTimeoutUnit().toChronoUnit()));
50-
setNetworkLogging(options.getLogActivity() ? new NetworkLogging().setDataFormat(options.getActivityLogDataFormat()) : null);
50+
setNetworkLogging(options.getLogActivity() ? new NetworkLogging().setEnabled(true).setDataFormat(options.getActivityLogDataFormat()) : null);
5151
setSsl(options.isSsl());
5252
}
5353

vertx-core/src/main/java/io/vertx/core/net/impl/quic/QuicClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ private Future<QuicConnection> connect(Channel ch,
187187
@Override
188188
protected void initChannel(Channel ch) {
189189
connectionGroup.add(ch);
190-
ByteBufFormat activityLogging = config.getNetworkLogging() != null ? config.getNetworkLogging().getDataFormat() : null;
190+
NetworkLogging networkLogging = config.getNetworkLogging();
191+
ByteBufFormat activityLogging = networkLogging != null && networkLogging.isEnabled()? networkLogging.getDataFormat() : null;
191192
QuicConnectionHandler handler = new QuicConnectionHandler(context, metrics, config.getIdleTimeout(),
192193
config.getReadIdleTimeout(), config.getWriteIdleTimeout(), activityLogging, remoteAddress, promise::tryComplete);
193194
ch.pipeline().addLast("handler", handler);

vertx-core/src/main/java/io/vertx/core/net/impl/quic/QuicServerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ protected QuicCodecBuilder<?> codecBuilder(ContextInternal context, SslContextPr
157157
protected void initChannel(Channel ch) {
158158
connectionGroup.add(ch);
159159
QuicChannel channel = (QuicChannel) ch;
160-
ByteBufFormat activityLogging = config.getNetworkLogging() != null ? config.getNetworkLogging().getDataFormat() : null;
160+
NetworkLogging networkLogging = config.getNetworkLogging();
161+
ByteBufFormat activityLogging = networkLogging != null && networkLogging.isEnabled() ? networkLogging.getDataFormat() : null;
161162
QuicConnectionHandler handler = new QuicConnectionHandler(context, metrics, config.getIdleTimeout(),
162163
config.getReadIdleTimeout(), config.getWriteIdleTimeout(), activityLogging,
163164
vertx.transport().convert(channel.remoteSocketAddress()), QuicServerImpl.this.handler);

vertx-core/src/main/java/io/vertx/core/net/impl/tcp/NetClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ protected void handleClose(Completable<Void> completion) {
8080
NetClientImpl.this.handleClose(completion);
8181
}
8282
};
83+
NetworkLogging networkLogging = config.getNetworkLogging();
8384
this.config = config;
8485
this.registerWriteHandler = registerWriteHandler;
8586
this.sslContextManager = new SslContextManager(SslContextManager.resolveEngineOptions(config.getSslEngineOptions(), sslOptions != null && sslOptions.isUseAlpn()));
8687
this.metrics = vertx.metrics() != null ? vertx.metrics().createTcpClientMetrics(config, protocol) : null;
87-
this.logging = config.getNetworkLogging() != null ? config.getNetworkLogging().getDataFormat() : null;
88+
this.logging = networkLogging != null && networkLogging.isEnabled() ? networkLogging.getDataFormat() : null;
8889
this.idleTimeout = config.getIdleTimeout() != null ? config.getIdleTimeout() : Duration.ofMillis(0L);
8990
this.readIdleTimeout = config.getReadIdleTimeout() != null ? config.getReadIdleTimeout() : Duration.ofMillis(0L);
9091
this.writeIdleTimeout = config.getWriteIdleTimeout() != null ? config.getWriteIdleTimeout() : Duration.ofMillis(0L);

vertx-core/src/main/java/io/vertx/core/net/impl/tcp/NetServerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ private void connected(Channel ch, SslContextManager sslContextManager, SSLOptio
275275
}
276276

277277
protected void initChannel(ChannelPipeline pipeline, boolean ssl) {
278-
if (config.getNetworkLogging() != null) {
279-
pipeline.addLast("logging", new LoggingHandler(config.getNetworkLogging().getDataFormat()));
278+
NetworkLogging networkLogging = config.getNetworkLogging();
279+
if (networkLogging != null && networkLogging.isEnabled()) {
280+
pipeline.addLast("logging", new LoggingHandler(networkLogging.getDataFormat()));
280281
}
281282
long idleTimeout = config.getIdleTimeout() != null ? config.getIdleTimeout().toMillis() : 0L;
282283
long readIdleTimeout = config.getReadIdleTimeout() != null ? config.getReadIdleTimeout().toMillis() : 0L;

vertx-core/src/test/java/io/vertx/tests/net/quic/QuicServerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ public void testServerNameIndication() throws Exception {
10061006
public void testServerLogging() throws Exception {
10071007
TestLoggerFactory fact = TestUtils.testLogging(() -> {
10081008
try {
1009-
testConnect(new QuicServerConfig().setNetworkLogging(new NetworkLogging()), 9999);
1009+
testConnect(new QuicServerConfig().setNetworkLogging(new NetworkLogging().setEnabled(true)), 9999);
10101010
} catch (Exception e) {
10111011
fail(e);
10121012
}

0 commit comments

Comments
 (0)