Skip to content

Commit

Permalink
Rename AdvancedByteBufFormat to AdvancedBufferFormat (#2417)
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Aug 3, 2022
1 parent fe37e85 commit 5ea1731
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 99 deletions.
20 changes: 10 additions & 10 deletions docs/asciidoc/wire-logger.adoc
Expand Up @@ -19,33 +19,33 @@ include::{examplesdir}/wiretap/Application.java[lines=18..35]
==== Wire Logger formatters
Reactor Netty supports 3 different formatters:

- {javadoc}/reactor/netty5/transport/logging/AdvancedByteBufFormat.html#HEX_DUMP[AdvancedByteBufFormat#HEX_DUMP] - the default
- {javadoc}/reactor/netty5/transport/logging/AdvancedBufferFormat.html#HEX_DUMP[AdvancedBufferFormat#HEX_DUMP] - the default

====
[source,java,indent=0]
.{sourcedir}/reactor/netty5/transport/logging/AdvancedByteBufFormat.java
.{sourcedir}/reactor/netty5/transport/logging/AdvancedBufferFormat.java
----
include::{formattersourcedir}/reactor/netty5/transport/logging/AdvancedByteBufFormat.java[lines=47..75]
include::{formattersourcedir}/reactor/netty5/transport/logging/AdvancedBufferFormat.java[lines=47..75]
----
====

- {javadoc}/reactor/netty5/transport/logging/AdvancedByteBufFormat.html#SIMPLE[AdvancedByteBufFormat#SIMPLE]
- {javadoc}/reactor/netty5/transport/logging/AdvancedBufferFormat.html#SIMPLE[AdvancedBufferFormat#SIMPLE]

====
[source,java,indent=0]
.{sourcedir}/reactor/netty5/transport/logging/AdvancedByteBufFormat.java
.{sourcedir}/reactor/netty5/transport/logging/AdvancedBufferFormat.java
----
include::{formattersourcedir}/reactor/netty5/transport/logging/AdvancedByteBufFormat.java[lines=34..45]
include::{formattersourcedir}/reactor/netty5/transport/logging/AdvancedBufferFormat.java[lines=34..45]
----
====

- {javadoc}/reactor/netty5/transport/logging/AdvancedByteBufFormat.html#TEXTUAL[AdvancedByteBufFormat#TEXTUAL]
- {javadoc}/reactor/netty5/transport/logging/AdvancedBufferFormat.html#TEXTUAL[AdvancedBufferFormat#TEXTUAL]

====
[source,java,indent=0]
.{sourcedir}/reactor/netty5/transport/logging/AdvancedByteBufFormat.java
.{sourcedir}/reactor/netty5/transport/logging/AdvancedBufferFormat.java
----
include::{formattersourcedir}/reactor/netty5/transport/logging/AdvancedByteBufFormat.java[lines=77..93]
include::{formattersourcedir}/reactor/netty5/transport/logging/AdvancedBufferFormat.java[lines=77..93]
----
====

Expand All @@ -59,6 +59,6 @@ When you need to change the default formatter you can configure it as follows:
include::{examplesdir}/wiretap/custom/Application.java[lines=18..38]
----
<1> Enables the wire logging,
{javadoc}/reactor/netty5/transport/logging/AdvancedByteBufFormat.html#TEXTUAL[AdvancedByteBufFormat#TEXTUAL] is used for
{javadoc}/reactor/netty5/transport/logging/AdvancedBufferFormat.html#TEXTUAL[AdvancedBufferFormat#TEXTUAL] is used for
printing the content.
====
Expand Up @@ -44,7 +44,7 @@
import reactor.core.Exceptions;
import reactor.netty5.NettyPipeline;
import reactor.netty5.ReactorNetty;
import reactor.netty5.transport.logging.AdvancedByteBufFormat;
import reactor.netty5.transport.logging.AdvancedBufferFormat;
import reactor.util.Logger;
import reactor.util.Loggers;
import reactor.util.annotation.Nullable;
Expand Down Expand Up @@ -664,6 +664,6 @@ public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) {
static final Logger log = Loggers.getLogger(SslProvider.class);

static final LoggingHandler LOGGING_HANDLER =
AdvancedByteBufFormat.HEX_DUMP
AdvancedBufferFormat.HEX_DUMP
.toLoggingHandler("reactor.netty5.tcp.ssl", LogLevel.DEBUG, Charset.defaultCharset());
}
Expand Up @@ -29,7 +29,7 @@
import reactor.netty5.resources.ConnectionProvider;
import reactor.netty5.resources.LoopResources;
import reactor.netty5.transport.ClientTransportConfig;
import reactor.netty5.transport.logging.AdvancedByteBufFormat;
import reactor.netty5.transport.logging.AdvancedBufferFormat;
import reactor.util.annotation.Nullable;

import java.net.SocketAddress;
Expand Down Expand Up @@ -133,7 +133,7 @@ protected ChannelPipelineConfigurer defaultOnChannelInit() {
static final ChannelOperations.OnSetup DEFAULT_OPS = (ch, c, msg) -> new ChannelOperations<>(ch, c);

static final LoggingHandler LOGGING_HANDLER =
AdvancedByteBufFormat.HEX_DUMP
AdvancedBufferFormat.HEX_DUMP
.toLoggingHandler(TcpClient.class.getName(), LogLevel.DEBUG, Charset.defaultCharset());

/**
Expand Down
Expand Up @@ -27,7 +27,7 @@
import reactor.netty5.channel.MicrometerChannelMetricsRecorder;
import reactor.netty5.resources.LoopResources;
import reactor.netty5.transport.ServerTransportConfig;
import reactor.netty5.transport.logging.AdvancedByteBufFormat;
import reactor.netty5.transport.logging.AdvancedBufferFormat;
import reactor.util.annotation.Nullable;

import java.net.SocketAddress;
Expand Down Expand Up @@ -113,7 +113,7 @@ protected ChannelPipelineConfigurer defaultOnChannelInit() {
static final ChannelOperations.OnSetup DEFAULT_OPS = (ch, c, msg) -> new ChannelOperations<>(ch, c);

static final LoggingHandler LOGGING_HANDLER =
AdvancedByteBufFormat.HEX_DUMP
AdvancedBufferFormat.HEX_DUMP
.toLoggingHandler(TcpServer.class.getName(), LogLevel.DEBUG, Charset.defaultCharset());

/**
Expand Down
Expand Up @@ -35,7 +35,7 @@
import io.netty.contrib.handler.proxy.Socks5ProxyHandler;
import io.netty5.util.internal.StringUtil;
import reactor.netty5.NettyPipeline;
import reactor.netty5.transport.logging.AdvancedByteBufFormat;
import reactor.netty5.transport.logging.AdvancedBufferFormat;
import reactor.util.annotation.Nullable;

/**
Expand Down Expand Up @@ -229,7 +229,7 @@ private boolean getNonProxyHostsValue() {
}

static final LoggingHandler LOGGING_HANDLER =
AdvancedByteBufFormat.HEX_DUMP
AdvancedBufferFormat.HEX_DUMP
.toLoggingHandler("reactor.netty5.proxy", LogLevel.DEBUG, Charset.defaultCharset());

static final String HTTP_PROXY_HOST = "http.proxyHost";
Expand Down
Expand Up @@ -34,7 +34,7 @@
import reactor.netty5.DisposableChannel;
import reactor.netty5.channel.ChannelMetricsRecorder;
import reactor.netty5.internal.util.Metrics;
import reactor.netty5.transport.logging.AdvancedByteBufFormat;
import reactor.netty5.transport.logging.AdvancedBufferFormat;
import reactor.netty5.resources.LoopResources;
import reactor.util.Logger;
import reactor.util.Loggers;
Expand Down Expand Up @@ -282,7 +282,7 @@ public final T runOn(LoopResources loopResources, boolean preferNative, @Nullabl

/**
* Apply or remove a wire logger configuration using {@link Transport} category (logger),
* {@code DEBUG} logger level and {@link AdvancedByteBufFormat#HEX_DUMP} for {@link Buffer} format,
* {@code DEBUG} logger level and {@link AdvancedBufferFormat#HEX_DUMP} for {@link Buffer} format,
* which means both events and content will be logged and the content will be in hex format.
*
* @param enable specifies whether the wire logger configuration will be added to the pipeline
Expand All @@ -308,7 +308,7 @@ else if (configuration().loggingHandler != null) {

/**
* Apply a wire logger configuration using the specified category (logger),
* {@code DEBUG} logger level and {@link AdvancedByteBufFormat#HEX_DUMP} for {@link Buffer} format,
* {@code DEBUG} logger level and {@link AdvancedBufferFormat#HEX_DUMP} for {@link Buffer} format,
* which means both events and content will be logged and the content will be in hex format.
*
* @param category the logger category
Expand All @@ -321,7 +321,7 @@ public T wiretap(String category) {

/**
* Apply a wire logger configuration using the specified category (logger),
* logger level and {@link AdvancedByteBufFormat#HEX_DUMP} for {@link Buffer} format,
* logger level and {@link AdvancedBufferFormat#HEX_DUMP} for {@link Buffer} format,
* which means both events and content will be logged and the content will be in hex format.
*
* @param category the logger category
Expand All @@ -331,28 +331,28 @@ public T wiretap(String category) {
public T wiretap(String category, LogLevel level) {
Objects.requireNonNull(category, "category");
Objects.requireNonNull(level, "level");
return wiretap(category, level, AdvancedByteBufFormat.HEX_DUMP);
return wiretap(category, level, AdvancedBufferFormat.HEX_DUMP);
}

/**
* Apply a wire logger configuration using the specified category (logger),
* logger level and {@link Buffer} format.
* Depending on the format:
* <ul>
* <li>{@link AdvancedByteBufFormat#SIMPLE} - only the events will be logged</li>
* <li>{@link AdvancedByteBufFormat#HEX_DUMP} - both events and content will be logged,
* <li>{@link AdvancedBufferFormat#SIMPLE} - only the events will be logged</li>
* <li>{@link AdvancedBufferFormat#HEX_DUMP} - both events and content will be logged,
* with content in hex format</li>
* <li>{@link AdvancedByteBufFormat#TEXTUAL} - both events and content will be logged,
* <li>{@link AdvancedBufferFormat#TEXTUAL} - both events and content will be logged,
* with content in plain text format</li>
* </ul>
* When {@link AdvancedByteBufFormat#TEXTUAL} is specified, {@link Charset#defaultCharset()} will be used.
* When {@link AdvancedBufferFormat#TEXTUAL} is specified, {@link Charset#defaultCharset()} will be used.
*
* @param category the logger category
* @param level the logger level
* @param format the {@link Buffer} format
* @return a new {@link Transport} reference
*/
public final T wiretap(String category, LogLevel level, AdvancedByteBufFormat format) {
public final T wiretap(String category, LogLevel level, AdvancedBufferFormat format) {
Objects.requireNonNull(category, "category");
Objects.requireNonNull(level, "level");
Objects.requireNonNull(format, "format");
Expand All @@ -362,14 +362,14 @@ public final T wiretap(String category, LogLevel level, AdvancedByteBufFormat fo
/**
* Apply a wire logger configuration using the specific category (logger),
* logger level, {@link Buffer} format and charset.
* The charset is relevant in case of {@link AdvancedByteBufFormat#TEXTUAL}
* The charset is relevant in case of {@link AdvancedBufferFormat#TEXTUAL}
* and a different charset than {@link Charset#defaultCharset()} is required.
* Depending on the format:
* <ul>
* <li>{@link AdvancedByteBufFormat#SIMPLE} - only the events will be logged</li>
* <li>{@link AdvancedByteBufFormat#HEX_DUMP} - both events and content will be logged,
* <li>{@link AdvancedBufferFormat#SIMPLE} - only the events will be logged</li>
* <li>{@link AdvancedBufferFormat#HEX_DUMP} - both events and content will be logged,
* with content in hex format</li>
* <li>{@link AdvancedByteBufFormat#TEXTUAL} - both events and content will be logged,
* <li>{@link AdvancedBufferFormat#TEXTUAL} - both events and content will be logged,
* with content in plain text format</li>
* </ul>
*
Expand All @@ -379,7 +379,7 @@ public final T wiretap(String category, LogLevel level, AdvancedByteBufFormat fo
* @param charset the charset
* @return a new {@link Transport} reference
*/
public final T wiretap(String category, LogLevel level, AdvancedByteBufFormat format, Charset charset) {
public final T wiretap(String category, LogLevel level, AdvancedBufferFormat format, Charset charset) {
Objects.requireNonNull(category, "category");
Objects.requireNonNull(level, "level");
Objects.requireNonNull(format, "format");
Expand Down
Expand Up @@ -25,12 +25,12 @@
/**
* Used to control the format and verbosity of logging for {@link Buffer}s and {@link ByteBufHolder}s.
* <p>
* Adds {@link AdvancedByteBufFormat#TEXTUAL} format to io.netty5.handler.logging.ByteBufFormat.
* Adds {@link AdvancedBufferFormat#TEXTUAL} format to {@link io.netty5.handler.logging.BufferFormat}.
*
* @author Maximilian Goeke
* @since 1.0.0
*/
public enum AdvancedByteBufFormat {
public enum AdvancedBufferFormat {
/**
* When wire logging is enabled with this format, only the events will be logged.
* <p>Examples:</p>
Expand Down Expand Up @@ -98,7 +98,7 @@ public enum AdvancedByteBufFormat {
*
* @param category the logger category
* @param level the logger level
* @param charset the charset (only relevant for {@link AdvancedByteBufFormat#TEXTUAL})
* @param charset the charset (only relevant for {@link AdvancedBufferFormat#TEXTUAL})
* @return a new {@link LoggingHandler} reference
*/
public LoggingHandler toLoggingHandler(String category, LogLevel level, Charset charset) {
Expand Down
Expand Up @@ -33,15 +33,15 @@
import static io.netty.buffer.ByteBufUtil.appendPrettyHexDump;
import static io.netty5.util.internal.StringUtil.NEWLINE;
import static java.util.Objects.requireNonNull;
import static reactor.netty5.transport.logging.AdvancedByteBufFormat.HEX_DUMP;
import static reactor.netty5.transport.logging.AdvancedByteBufFormat.SIMPLE;
import static reactor.netty5.transport.logging.AdvancedByteBufFormat.TEXTUAL;
import static reactor.netty5.transport.logging.AdvancedBufferFormat.HEX_DUMP;
import static reactor.netty5.transport.logging.AdvancedBufferFormat.SIMPLE;
import static reactor.netty5.transport.logging.AdvancedBufferFormat.TEXTUAL;

/**
* Extends {@link LoggingHandler} in order to provide extended connection id, which in case of HTTP
* adds the serial number of the request received on that connection.
* <p>
* In case of {@link AdvancedByteBufFormat#TEXTUAL} logs all events in a
* In case of {@link AdvancedBufferFormat#TEXTUAL} logs all events in a
* textual representation, so it's human readable and less verbose.
* <p>
* Hint: Logger escapes newlines as "\n" to reduce output.
Expand All @@ -52,7 +52,7 @@
*/
final class ReactorNettyLoggingHandler extends LoggingHandler {

private final AdvancedByteBufFormat byteBufFormat;
private final AdvancedBufferFormat bufferFormat;
private final Charset charset;
private final String name;

Expand All @@ -61,43 +61,43 @@ final class ReactorNettyLoggingHandler extends LoggingHandler {
*
* @param name the name of the class to use for the logger
* @param level the log level
* @param byteBufFormat the byte buffer format
* @param bufferFormat the byte buffer format
*/
ReactorNettyLoggingHandler(String name, LogLevel level, AdvancedByteBufFormat byteBufFormat) {
super(name, level, byteBufFormat == SIMPLE ? BufferFormat.SIMPLE : BufferFormat.HEX_DUMP);
this.byteBufFormat = byteBufFormat;
ReactorNettyLoggingHandler(String name, LogLevel level, AdvancedBufferFormat bufferFormat) {
super(name, level, bufferFormat == SIMPLE ? BufferFormat.SIMPLE : BufferFormat.HEX_DUMP);
this.bufferFormat = bufferFormat;
this.charset = null;
this.name = name;
}

/**
* Creates a new instance with the specified logger name, level and charset.
* The byte buffer format is {@link AdvancedByteBufFormat#TEXTUAL}
* The byte buffer format is {@link AdvancedBufferFormat#TEXTUAL}
*
* @param name the name of the class to use for the logger
* @param level the log level
* @param charset the charset used to decode the ByteBuf
*/
ReactorNettyLoggingHandler(final String name, final LogLevel level, final Charset charset) {
super(name, level);
this.byteBufFormat = TEXTUAL;
this.bufferFormat = TEXTUAL;
this.charset = requireNonNull(charset, "charset");
this.name = name;
}

/*
* The UnsupportedOperationException is thrown to reduce confusion. ReactorNettyLoggingHandler is using
* the AdvancedByteBufFormat and not ByteBufFormat.
* the AdvancedBufferFormat and not BufferFormat.
*/
@Override
public BufferFormat bufferFormat() {
if (byteBufFormat == SIMPLE) {
if (bufferFormat == SIMPLE) {
return BufferFormat.SIMPLE;
}
else if (byteBufFormat == HEX_DUMP) {
else if (bufferFormat == HEX_DUMP) {
return BufferFormat.HEX_DUMP;
}
throw new UnsupportedOperationException("ReactorNettyLoggingHandler isn't using the classic ByteBufFormat.");
throw new UnsupportedOperationException("ReactorNettyLoggingHandler isn't using the classic BufferFormat.");
}

@Override
Expand All @@ -108,15 +108,15 @@ public boolean equals(Object o) {
if (!(o instanceof ReactorNettyLoggingHandler that)) {
return false;
}
return byteBufFormat == that.byteBufFormat &&
return bufferFormat == that.bufferFormat &&
Objects.equals(charset, that.charset) &&
level() == that.level() &&
name.equals(that.name);
}

@Override
public int hashCode() {
return Objects.hash(byteBufFormat, charset, level(), name);
return Objects.hash(bufferFormat, charset, level(), name);
}

@Override
Expand Down Expand Up @@ -211,12 +211,12 @@ private String formatBuffer(ChannelHandlerContext ctx, String eventName, Buffer
else {
int outputLength = chStr.length() + 1 + eventName.length() + 2 + 10 + 1;
String message = "";
if (byteBufFormat == HEX_DUMP) {
if (bufferFormat == HEX_DUMP) {
int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
int hexDumpLength = 2 + rows * 80;
outputLength += hexDumpLength;
}
else if (byteBufFormat == TEXTUAL) {
else if (bufferFormat == TEXTUAL) {
message = msg.toString(charset);
outputLength += message.length() + 1;
}
Expand All @@ -227,11 +227,11 @@ else if (byteBufFormat == TEXTUAL) {
.append(": ")
.append(length)
.append('B');
if (byteBufFormat == HEX_DUMP) {
if (bufferFormat == HEX_DUMP) {
buf.append(NEWLINE);
BufferUtil.appendPrettyHexDump(buf, msg);
}
else if (byteBufFormat == TEXTUAL) {
else if (bufferFormat == TEXTUAL) {
buf.append(' ').append(message);
}

Expand All @@ -256,9 +256,9 @@ private String formatByteBufHolder(ChannelHandlerContext ctx, String eventName,
}
else {
StringBuilder buf;
if (byteBufFormat != TEXTUAL) {
if (bufferFormat != TEXTUAL) {
int outputLength = chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 2 + 10 + 1;
if (byteBufFormat == HEX_DUMP) {
if (bufferFormat == HEX_DUMP) {
int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
int hexDumpLength = 2 + rows * 80;
outputLength += hexDumpLength;
Expand All @@ -272,7 +272,7 @@ private String formatByteBufHolder(ChannelHandlerContext ctx, String eventName,
.append(", ")
.append(length)
.append('B');
if (byteBufFormat == HEX_DUMP) {
if (bufferFormat == HEX_DUMP) {
buf.append(NEWLINE);
appendPrettyHexDump(buf, content);
}
Expand Down

0 comments on commit 5ea1731

Please sign in to comment.