Polish hint for suppressing logging at Encoder/Decoder

This commit is contained in:
Rossen Stoyanchev
2018-07-06 20:32:08 -04:00
parent 2874dd75ca
commit bca9f51092
10 changed files with 33 additions and 48 deletions

View File

@@ -33,7 +33,6 @@ import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import org.apache.commons.logging.Log;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -142,9 +141,8 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
private DataBuffer encodeValue(Object value, @Nullable MimeType mimeType, DataBufferFactory bufferFactory,
ResolvableType elementType, @Nullable Map<String, Object> hints, JsonEncoding encoding) {
Log theLogger = Hints.getLoggerOrDefault(hints, logger);
if (theLogger.isDebugEnabled()) {
theLogger.debug(Hints.getLogPrefix(hints) + "Encoding [" + value + "]");
if (logger.isDebugEnabled() && !Hints.suppressLogging(hints)) {
logger.debug(Hints.getLogPrefix(hints) + "Encoding [" + value + "]");
}
JavaType javaType = getJavaType(elementType.getType(), null);

View File

@@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.logging.impl.NoOpLog;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -87,7 +86,7 @@ public class MultipartHttpMessageWriter extends LoggingCodecSupport
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
/** Suppress logging from individual part writers (full map logged at this level). */
private static final Map<String, Object> DEFAULT_HINTS = Hints.from(Hints.LOGGER_HINT, new NoOpLog());
private static final Map<String, Object> DEFAULT_HINTS = Hints.from(Hints.SUPPRESS_LOGGING_HINT, true);
private final List<HttpMessageWriter<?>> partWriters;

View File

@@ -25,7 +25,6 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.logging.Log;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;
@@ -75,9 +74,8 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
protected Flux<DataBuffer> encode(Object value, DataBufferFactory dataBufferFactory,
ResolvableType type, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
try {
Log theLogger = Hints.getLoggerOrDefault(hints, logger);
if (theLogger.isDebugEnabled()) {
theLogger.debug(Hints.getLogPrefix(hints) + "Encoding [" + value + "]");
if (logger.isDebugEnabled() && !Hints.suppressLogging(hints)) {
logger.debug(Hints.getLogPrefix(hints) + "Encoding [" + value + "]");
}
DataBuffer buffer = dataBufferFactory.allocateBuffer(1024);
OutputStream outputStream = buffer.asOutputStream();