From 2684fbdbff0b234ef8d068d5e5f3a62dbcb8d161 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Wed, 17 Nov 2021 20:38:18 +0100 Subject: [PATCH] Migrate to Spring JCL logging. --- pom.xml | 22 -------- .../ElasticsearchRestTemplate.java | 8 +-- .../ReactiveElasticsearchTemplate.java | 17 +++---- .../elasticsearch7/ReactiveIndexTemplate.java | 8 +-- .../elasticsearch7/RestIndexTemplate.java | 6 +-- .../client/RestClientFactoryBean.java | 6 +-- .../elasticsearch/client/ClientLogger.java | 37 +++++++------- .../reactive/MultiNodeHostProvider.java | 50 +++++++++++++------ .../core/ReactiveResourceUtil.java | 3 -- .../elasticsearch/core/SearchHitMapping.java | 6 +-- .../convert/DatePropertyValueConverter.java | 10 ++-- .../DateRangePropertyValueConverter.java | 10 ++-- .../MappingElasticsearchConverter.java | 18 +++---- .../TemporalPropertyValueConverter.java | 11 ++-- .../TemporalRangePropertyValueConverter.java | 10 ++-- .../core/index/MappingBuilder.java | 16 +++--- .../SimpleElasticsearchPersistentEntity.java | 12 ++--- ...SimpleElasticsearchPersistentProperty.java | 30 +++++------ .../SimpleElasticsearchRepository.java | 8 +-- .../elasticsearch/support/VersionInfo.java | 26 +++++----- .../elasticsearch/FoobarIntegrationTest.java | 4 -- .../junit/jupiter/ClusterConnection.java | 28 +++++++---- .../SpringDataElasticsearchExtension.java | 10 ++-- src/test/resources/logback.xml | 16 ++++++ 24 files changed, 197 insertions(+), 175 deletions(-) diff --git a/pom.xml b/pom.xml index 698c06d05..5bec33960 100644 --- a/pom.xml +++ b/pom.xml @@ -147,21 +147,6 @@ - - - org.slf4j - log4j-over-slf4j - ${slf4j} - test - - - - org.apache.logging.log4j - log4j-core - ${log4j} - test - - com.fasterxml.jackson.core @@ -223,13 +208,6 @@ - - org.apache.logging.log4j - log4j-to-slf4j - ${log4j} - test - - io.projectreactor.tools blockhound-junit-platform diff --git a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ElasticsearchRestTemplate.java b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ElasticsearchRestTemplate.java index c135db7d1..76476c17b 100644 --- a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ElasticsearchRestTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ElasticsearchRestTemplate.java @@ -24,6 +24,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.bulk.BulkItemResponse; @@ -54,8 +56,6 @@ import org.elasticsearch.index.reindex.UpdateByQueryRequest; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.suggest.SuggestBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.elasticsearch.BulkFailureException; import org.springframework.data.elasticsearch.backend.elasticsearch7.cluster.ElasticsearchClusterOperations; import org.springframework.data.elasticsearch.backend.elasticsearch7.document.DocumentAdapters; @@ -116,7 +116,7 @@ */ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate { - private static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchRestTemplate.class); + private static final Log LOGGER = LogFactory.getLog(ElasticsearchRestTemplate.class); private final RestHighLevelClient client; private final ElasticsearchExceptionTranslator exceptionTranslator = new ElasticsearchExceptionTranslator(); @@ -419,7 +419,7 @@ public void searchScrollClear(List scrollIds) { request.scrollIds(scrollIds); execute(client -> client.clearScroll(request, RequestOptions.DEFAULT)); } catch (Exception e) { - LOGGER.warn("Could not clear scroll: {}", e.getMessage()); + LOGGER.warn(String.format("Could not clear scroll: %s", e.getMessage())); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveElasticsearchTemplate.java index 3a02d6f1b..f51640c00 100644 --- a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveElasticsearchTemplate.java @@ -26,6 +26,8 @@ import java.util.function.Function; import java.util.stream.Collectors; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.bulk.BulkItemResponse; @@ -47,8 +49,6 @@ import org.elasticsearch.index.reindex.UpdateByQueryRequest; import org.elasticsearch.search.suggest.SuggestBuilder; import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -109,8 +109,7 @@ */ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations, ApplicationContextAware { - private static final Logger QUERY_LOGGER = LoggerFactory - .getLogger("org.springframework.data.elasticsearch.core.QUERY"); + private static final Log QUERY_LOGGER = LogFactory.getLog("org.springframework.data.elasticsearch.core.QUERY"); private final ReactiveElasticsearchClient client; private final ElasticsearchConverter converter; @@ -811,7 +810,7 @@ public Flux> aggregate(Query query, Class entityType, protected Flux> doAggregate(SearchRequest request) { if (QUERY_LOGGER.isDebugEnabled()) { - QUERY_LOGGER.debug("Executing doCount: {}", request); + QUERY_LOGGER.debug(String.format("Executing doCount: %s", request)); } return Flux.from(execute(client -> client.aggregate(request))) // @@ -885,7 +884,7 @@ private Mono doCount(Query query, Class entityType, IndexCoordinates in protected Flux doFind(SearchRequest request) { if (QUERY_LOGGER.isDebugEnabled()) { - QUERY_LOGGER.debug("Executing doFind: {}", request); + QUERY_LOGGER.debug(String.format("Executing doFind: %s", request)); } return Flux.from(execute(client -> client.search(request))).map(DocumentAdapters::from) // @@ -903,7 +902,7 @@ protected Mono doFindForResponse(SearchRequest request, Function suggestEntityCreator) { if (QUERY_LOGGER.isDebugEnabled()) { - QUERY_LOGGER.debug("Executing doFindForResponse: {}", request); + QUERY_LOGGER.debug(String.format("Executing doFindForResponse: %s", request)); } return Mono.from(execute(client1 -> client1.searchForResponse(request))).map(searchResponse -> { @@ -920,7 +919,7 @@ protected Mono doFindForResponse(SearchRequest request, protected Mono doCount(SearchRequest request) { if (QUERY_LOGGER.isDebugEnabled()) { - QUERY_LOGGER.debug("Executing doCount: {}", request); + QUERY_LOGGER.debug(String.format("Executing doCount: %s", request)); } return Mono.from(execute(client -> client.count(request))) // @@ -936,7 +935,7 @@ protected Mono doCount(SearchRequest request) { protected Flux doScroll(SearchRequest request) { if (QUERY_LOGGER.isDebugEnabled()) { - QUERY_LOGGER.debug("Executing doScroll: {}", request); + QUERY_LOGGER.debug(String.format("Executing doScroll: %s", request)); } return Flux.from(execute(client -> client.scroll(request))) // diff --git a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveIndexTemplate.java b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveIndexTemplate.java index c70ecf658..8062ccb31 100644 --- a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveIndexTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/ReactiveIndexTemplate.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -36,8 +38,6 @@ import org.elasticsearch.client.indices.GetMappingsRequest; import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.elasticsearch.NoSuchIndexException; @@ -69,7 +69,7 @@ */ class ReactiveIndexTemplate implements ReactiveIndexOperations { - private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveIndexTemplate.class); + private static final Log LOGGER = LogFactory.getLog(ReactiveIndexTemplate.class); @Nullable private final Class boundClass; private final IndexCoordinates boundIndex; @@ -366,7 +366,7 @@ private Mono loadDocument(String path, String annotation) { } }); } else { - LOGGER.info("path in {} has to be defined. Using default instead.", annotation); + LOGGER.info(String.format("path in %s has to be defined. Using default empty Document instead.", annotation)); } return Mono.just(Document.create()); diff --git a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/RestIndexTemplate.java b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/RestIndexTemplate.java index ae1dadd15..2f8b289db 100644 --- a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/RestIndexTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/RestIndexTemplate.java @@ -20,6 +20,8 @@ import java.util.Map; import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -38,8 +40,6 @@ import org.elasticsearch.client.indices.PutIndexTemplateRequest; import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.cluster.metadata.MappingMetadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.elasticsearch.core.AbstractIndexTemplate; import org.springframework.data.elasticsearch.core.IndexInformation; import org.springframework.data.elasticsearch.core.IndexOperations; @@ -66,7 +66,7 @@ */ class RestIndexTemplate extends AbstractIndexTemplate implements IndexOperations { - private static final Logger LOGGER = LoggerFactory.getLogger(RestIndexTemplate.class); + private static final Log LOGGER = LogFactory.getLog(RestIndexTemplate.class); private final ElasticsearchRestTemplate restTemplate; diff --git a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/client/RestClientFactoryBean.java b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/client/RestClientFactoryBean.java index 629e2cf72..fabfb70f1 100644 --- a/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/client/RestClientFactoryBean.java +++ b/src/main/java/org/springframework/data/elasticsearch/backend/elasticsearch7/client/RestClientFactoryBean.java @@ -18,11 +18,11 @@ import java.net.URL; import java.util.ArrayList; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; @@ -38,7 +38,7 @@ */ public class RestClientFactoryBean implements FactoryBean, InitializingBean, DisposableBean { - private static final Logger LOGGER = LoggerFactory.getLogger(RestClientFactoryBean.class); + private static final Log LOGGER = LogFactory.getLog(RestClientFactoryBean.class); private @Nullable RestHighLevelClient client; private String hosts = "http://localhost:9200"; diff --git a/src/main/java/org/springframework/data/elasticsearch/client/ClientLogger.java b/src/main/java/org/springframework/data/elasticsearch/client/ClientLogger.java index 63100a390..4b3e002ea 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/ClientLogger.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/ClientLogger.java @@ -17,16 +17,15 @@ import java.util.function.Supplier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.http.HttpStatus; import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** * Logging Utility to log client requests and responses. Logs client requests and responses to Elasticsearch to a - * dedicated logger: {@code org.springframework.data.elasticsearch.client.WIRE} on {@link org.slf4j.event.Level#TRACE} - * level. + * dedicated logger: {@code org.springframework.data.elasticsearch.client.WIRE} on trace level. * * @author Mark Paluch * @author Christoph Strobl @@ -35,8 +34,7 @@ public abstract class ClientLogger { private static final String lineSeparator = System.getProperty("line.separator"); - private static final Logger WIRE_LOGGER = LoggerFactory - .getLogger("org.springframework.data.elasticsearch.client.WIRE"); + private static final Log WIRE_LOGGER = LogFactory.getLog("org.springframework.data.elasticsearch.client.WIRE"); private ClientLogger() {} @@ -52,7 +50,7 @@ public static boolean isEnabled() { /** * Log an outgoing HTTP request. * - * @param logId the correlation Id, see {@link #newLogId()}. + * @param logId the correlation id, see {@link #newLogId()}. * @param method HTTP method * @param endpoint URI * @param parameters optional parameters. @@ -60,16 +58,15 @@ public static boolean isEnabled() { public static void logRequest(String logId, String method, String endpoint, Object parameters) { if (isEnabled()) { - - WIRE_LOGGER.trace("[{}] Sending request {} {} with parameters: {}", logId, method.toUpperCase(), endpoint, - parameters); + WIRE_LOGGER.trace(String.format("[%s] Sending request %s %s with parameters: %s", logId, method.toUpperCase(), + endpoint, parameters)); } } /** * Log an outgoing HTTP request with a request body. * - * @param logId the correlation Id, see {@link #newLogId()}. + * @param logId the correlation id, see {@link #newLogId()}. * @param method HTTP method * @param endpoint URI * @param parameters optional parameters. @@ -79,43 +76,43 @@ public static void logRequest(String logId, String method, String endpoint, Obje Supplier body) { if (isEnabled()) { - - WIRE_LOGGER.trace("[{}] Sending request {} {} with parameters: {}{}Request body: {}", logId, method.toUpperCase(), - endpoint, parameters, lineSeparator, body.get()); + WIRE_LOGGER.trace(String.format("[%s] Sending request %s %s with parameters: %s%sRequest body: %s", logId, + method.toUpperCase(), endpoint, parameters, lineSeparator, body.get())); } } /** * Log a raw HTTP response without logging the body. * - * @param logId the correlation Id, see {@link #newLogId()}. + * @param logId the correlation id, see {@link #newLogId()}. * @param statusCode the HTTP status code. */ public static void logRawResponse(String logId, @Nullable HttpStatus statusCode) { if (isEnabled()) { - WIRE_LOGGER.trace("[{}] Received raw response: {}", logId, statusCode); + WIRE_LOGGER.trace(String.format("[%s] Received raw response: %s", logId, statusCode)); } } /** * Log a raw HTTP response along with the body. * - * @param logId the correlation Id, see {@link #newLogId()}. + * @param logId the correlation id, see {@link #newLogId()}. * @param statusCode the HTTP status code. * @param body body content. */ public static void logResponse(String logId, HttpStatus statusCode, String body) { if (isEnabled()) { - WIRE_LOGGER.trace("[{}] Received response: {}{}Response body: {}", logId, statusCode, lineSeparator, body); + WIRE_LOGGER.trace( + String.format("[%s] Received response: %s%sResponse body: %s", logId, statusCode, lineSeparator, body)); } } /** - * Creates a new, unique correlation Id to improve tracing across log events. + * Creates a new, unique correlation id to improve tracing across log events. * - * @return a new, unique correlation Id. + * @return a new, unique correlation id. */ public static String newLogId() { diff --git a/src/main/java/org/springframework/data/elasticsearch/client/reactive/MultiNodeHostProvider.java b/src/main/java/org/springframework/data/elasticsearch/client/reactive/MultiNodeHostProvider.java index 02c989483..25317b48a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/reactive/MultiNodeHostProvider.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/reactive/MultiNodeHostProvider.java @@ -29,8 +29,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.data.elasticsearch.client.ElasticsearchHost; import org.springframework.data.elasticsearch.client.ElasticsearchHost.State; import org.springframework.data.elasticsearch.client.NoReachableHostException; @@ -48,7 +48,7 @@ */ class MultiNodeHostProvider implements HostProvider { - private final static Logger LOG = LoggerFactory.getLogger(MultiNodeHostProvider.class); + private final static Log LOGGER = LogFactory.getLog(MultiNodeHostProvider.class); private final WebClientProvider clientProvider; private final Map hosts; @@ -61,7 +61,9 @@ class MultiNodeHostProvider implements HostProvider { this.hosts.put(endpoint, new ElasticsearchHost(endpoint, State.UNKNOWN)); } - LOG.debug("initialized with " + hosts); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("initialized with " + hosts); + } } /* @@ -90,19 +92,27 @@ public WebClient createWebClient(InetSocketAddress endpoint) { @Override public Mono lookupActiveHost(Verification verification) { - LOG.trace("lookupActiveHost " + verification + " from " + hosts()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("lookupActiveHost " + verification + " from " + hosts()); + } if (Verification.LAZY.equals(verification)) { for (ElasticsearchHost entry : hosts()) { if (entry.isOnline()) { - LOG.trace("lookupActiveHost returning " + entry); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("lookupActiveHost returning " + entry); + } return Mono.just(entry.getEndpoint()); } } - LOG.trace("no online host found with LAZY"); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("no online host found with LAZY"); + } } - LOG.trace("searching for active host"); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("searching for active host"); + } return findActiveHostInKnownActives() // .switchIfEmpty(findActiveHostInUnresolved()) // .switchIfEmpty(findActiveHostInDead()) // @@ -127,13 +137,17 @@ private Mono findActiveHostInDead() { private Mono findActiveForState(State state) { - LOG.trace("findActiveForState state " + state + ", current hosts: " + hosts); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("findActiveForState state " + state + ", current hosts: " + hosts); + } return checkNodes(state) // .map(this::updateNodeState) // .filter(ElasticsearchHost::isOnline) // .map(elasticsearchHost -> { - LOG.trace("findActiveForState returning host " + elasticsearchHost); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("findActiveForState returning host " + elasticsearchHost); + } return elasticsearchHost; }).map(ElasticsearchHost::getEndpoint) // .takeLast(1) // @@ -150,21 +164,27 @@ private ElasticsearchHost updateNodeState(Tuple2 tuple private Flux> checkNodes(@Nullable State state) { - LOG.trace("checkNodes() with state " + state); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("checkNodes() with state " + state); + } return Flux.fromIterable(hosts()) // .filter(entry -> state == null || entry.getState().equals(state)) // .map(ElasticsearchHost::getEndpoint) // .concatMap(host -> { - LOG.trace("checking host " + host); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("checking host " + host); + } Mono clientResponseMono = createWebClient(host) // .head().uri("/") // .exchangeToMono(Mono::just) // .timeout(Duration.ofSeconds(1)) // .doOnError(throwable -> { - LOG.trace("error checking host " + host + ", " + throwable.getMessage()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("error checking host " + host + ", " + throwable.getMessage()); + } hosts.put(host, new ElasticsearchHost(host, State.OFFLINE)); clientProvider.getErrorListener().accept(throwable); }); @@ -174,7 +194,9 @@ private Flux> checkNodes(@Nullable State state) .thenReturn(it.statusCode().isError() ? State.OFFLINE : State.ONLINE))); }) // .map(tuple -> { - LOG.trace("check result " + tuple); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("check result " + tuple); + } return tuple; }).onErrorContinue((throwable, o) -> clientProvider.getErrorListener().accept(throwable)); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveResourceUtil.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveResourceUtil.java index 168da2f8f..78191dab7 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveResourceUtil.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveResourceUtil.java @@ -22,8 +22,6 @@ import java.io.InputStreamReader; import java.nio.charset.Charset; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.DefaultDataBufferFactory; @@ -38,7 +36,6 @@ */ public abstract class ReactiveResourceUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveResourceUtil.class); private static final int BUFFER_SIZE = 8_192; /** diff --git a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitMapping.java b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitMapping.java index 8f01618e2..a9ff77a20 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/SearchHitMapping.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/SearchHitMapping.java @@ -22,8 +22,8 @@ import java.util.Map; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.data.elasticsearch.backend.elasticsearch7.document.SearchDocumentResponse; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; import org.springframework.data.elasticsearch.core.document.Document; @@ -49,7 +49,7 @@ */ public class SearchHitMapping { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchHitMapping.class); + private static final Log LOGGER = LogFactory.getLog(SearchHitMapping.class); private final Class type; private final ElasticsearchConverter converter; diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/DatePropertyValueConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/DatePropertyValueConverter.java index 1bc8b3685..d13853c77 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/DatePropertyValueConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/DatePropertyValueConverter.java @@ -18,8 +18,8 @@ import java.util.Date; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.data.mapping.PersistentProperty; /** @@ -28,7 +28,7 @@ */ public class DatePropertyValueConverter extends AbstractPropertyValueConverter { - private static final Logger LOGGER = LoggerFactory.getLogger(DatePropertyValueConverter.class); + private static final Log LOGGER = LogFactory.getLog(DatePropertyValueConverter.class); private final List dateConverters; @@ -47,7 +47,9 @@ public Object read(Object value) { try { return dateConverter.parse(s); } catch (Exception e) { - LOGGER.trace(e.getMessage(), e); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(e.getMessage(), e); + } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/DateRangePropertyValueConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/DateRangePropertyValueConverter.java index e4cf4f37f..4b5d7536a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/DateRangePropertyValueConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/DateRangePropertyValueConverter.java @@ -18,8 +18,8 @@ import java.util.Date; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.data.mapping.PersistentProperty; /** @@ -28,7 +28,7 @@ */ public class DateRangePropertyValueConverter extends AbstractRangePropertyValueConverter { - private static final Logger LOGGER = LoggerFactory.getLogger(DateRangePropertyValueConverter.class); + private static final Log LOGGER = LogFactory.getLog(DateRangePropertyValueConverter.class); private final List dateConverters; @@ -51,7 +51,9 @@ protected Date parse(String value) { try { return converters.parse(value); } catch (Exception e) { - LOGGER.trace(e.getMessage(), e); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(e.getMessage(), e); + } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java index ca26df40e..11bb95a38 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverter.java @@ -21,8 +21,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; @@ -91,7 +91,7 @@ public class MappingElasticsearchConverter private static final String INCOMPATIBLE_TYPES = "Cannot convert %1$s of type %2$s into an instance of %3$s! Implement a custom Converter<%2$s, %3$s> and register it with the CustomConversions."; private static final String INVALID_TYPE_TO_READ = "Expected to read Document %s into type %s but didn't find a PersistentEntity for the latter!"; - private static final Logger LOGGER = LoggerFactory.getLogger(MappingElasticsearchConverter.class); + private static final Log LOGGER = LogFactory.getLog(MappingElasticsearchConverter.class); private final MappingContext, ElasticsearchPersistentProperty> mappingContext; private final GenericConversionService conversionService; @@ -436,10 +436,10 @@ protected R readValue(@Nullable Object value, ElasticsearchPersistentPropert String key = propertyName + "-read"; int count = propertyWarnings.computeIfAbsent(key, k -> 0); if (count < 5) { - LOGGER.warn( - "Type {} of property {} is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for reading!" + LOGGER.warn(String.format( + "Type %s of property %s is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for reading!" + " It cannot be mapped from a complex object in Elasticsearch!", - property.getType().getSimpleName(), propertyName); + property.getType().getSimpleName(), propertyName)); propertyWarnings.put(key, count + 1); } } @@ -909,10 +909,10 @@ private void writeProperties(ElasticsearchPersistentEntity entity, Persistent String key = propertyName + "-write"; int count = propertyWarnings.computeIfAbsent(key, k -> 0); if (count < 5) { - LOGGER.warn( - "Type {} of property {} is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for writing!" + LOGGER.warn(String.format( + "Type %s of property %s is a TemporalAccessor class but has neither a @Field annotation defining the date type nor a registered converter for writing!" + " It will be mapped to a complex object in Elasticsearch!", - property.getType().getSimpleName(), propertyName); + property.getType().getSimpleName(), propertyName)); propertyWarnings.put(key, count + 1); } } else if (!isSimpleType(value)) { diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalPropertyValueConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalPropertyValueConverter.java index 357b49dde..7fc0621e2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalPropertyValueConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalPropertyValueConverter.java @@ -18,8 +18,8 @@ import java.time.temporal.TemporalAccessor; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.data.mapping.PersistentProperty; /** @@ -28,7 +28,7 @@ */ public class TemporalPropertyValueConverter extends AbstractPropertyValueConverter { - private static final Logger LOGGER = LoggerFactory.getLogger(TemporalPropertyValueConverter.class); + private static final Log LOGGER = LogFactory.getLog(TemporalPropertyValueConverter.class); private final List dateConverters; @@ -50,7 +50,10 @@ public Object read(Object value) { try { return dateConverter.parse(s, (Class) actualType); } catch (Exception e) { - LOGGER.trace(e.getMessage(), e); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(e.getMessage(), e); + + } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalRangePropertyValueConverter.java b/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalRangePropertyValueConverter.java index 39cb85dd6..90cecd675 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalRangePropertyValueConverter.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/convert/TemporalRangePropertyValueConverter.java @@ -18,8 +18,8 @@ import java.time.temporal.TemporalAccessor; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.data.mapping.PersistentProperty; import org.springframework.util.Assert; @@ -29,7 +29,7 @@ */ public class TemporalRangePropertyValueConverter extends AbstractRangePropertyValueConverter { - private static final Logger LOGGER = LoggerFactory.getLogger(TemporalRangePropertyValueConverter.class); + private static final Log LOGGER = LogFactory.getLog(TemporalRangePropertyValueConverter.class); private final List dateConverters; @@ -55,7 +55,9 @@ protected TemporalAccessor parse(String value) { try { return converters.parse(value, (Class) type); } catch (Exception e) { - LOGGER.trace(e.getMessage(), e); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(e.getMessage(), e); + } } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java index 248840f0d..a30726ef5 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/index/MappingBuilder.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.data.annotation.Transient; import org.springframework.data.elasticsearch.annotations.*; @@ -71,7 +71,7 @@ */ public class MappingBuilder { - private static final Logger logger = LoggerFactory.getLogger(ElasticsearchRestTemplate.class); + private static final Log LOGGER = LogFactory.getLog(ElasticsearchRestTemplate.class); private static final String FIELD_INDEX = "index"; private static final String FIELD_PROPERTIES = "properties"; @@ -265,16 +265,16 @@ private void mapEntity(ObjectNode objectNode, @Nullable ElasticsearchPersistentE if (property.isSeqNoPrimaryTermProperty()) { if (property.isAnnotationPresent(Field.class)) { - logger.warn("Property {} of {} is annotated for inclusion in mapping, but its type is " + // + LOGGER.warn(String.format("Property %s of %s is annotated for inclusion in mapping, but its type is " + // "SeqNoPrimaryTerm that is never mapped, so it is skipped", // - property.getFieldName(), entity.getType()); + property.getFieldName(), entity.getType())); } return; } buildPropertyMapping(propertiesNode, isRootObject, property); } catch (IOException e) { - logger.warn("error mapping property with name {}", property.getName(), e); + LOGGER.warn(String.format("error mapping property with name %s", property.getName()), e); } }); } @@ -491,9 +491,9 @@ private void addJoinFieldMapping(ObjectNode propertiesNode, ElasticsearchPersist JoinTypeRelation[] joinTypeRelations = property.getRequiredAnnotation(JoinTypeRelations.class).relations(); if (joinTypeRelations.length == 0) { - logger.warn("Property {}s type is JoinField but its annotation JoinTypeRelation is " + // + LOGGER.warn(String.format("Property %s's type is JoinField but its annotation JoinTypeRelation is " + // "not properly maintained", // - property.getFieldName()); + property.getFieldName())); return; } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java index 71676cf86..f5985b41d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java @@ -19,8 +19,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.elasticsearch.annotations.Document; @@ -63,7 +63,7 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntity implements ElasticsearchPersistentEntity { - private static final Logger LOGGER = LoggerFactory.getLogger(SimpleElasticsearchPersistentEntity.class); + private static final Log LOGGER = LogFactory.getLog(SimpleElasticsearchPersistentEntity.class); private static final SpelExpressionParser PARSER = new SpelExpressionParser(); private @Nullable final Document document; @@ -235,9 +235,9 @@ public void addPersistentProperty(ElasticsearchPersistentProperty property) { } private void warnAboutBothSeqNoPrimaryTermAndVersionProperties() { - LOGGER.warn( - "Both SeqNoPrimaryTerm and @Version properties are defined on {}. Version will not be sent in index requests when seq_no is sent!", - getType()); + LOGGER.warn(String.format( + "Both SeqNoPrimaryTerm and @Version properties are defined on %s. Version will not be sent in index requests when seq_no is sent!", + getType())); } @Nullable diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java index a732dc9b7..f1db0cf4e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java @@ -21,8 +21,8 @@ import java.util.Date; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanUtils; import org.springframework.data.elasticsearch.annotations.DateFormat; import org.springframework.data.elasticsearch.annotations.Field; @@ -69,7 +69,7 @@ public class SimpleElasticsearchPersistentProperty extends AnnotationBasedPersistentProperty implements ElasticsearchPersistentProperty { - private static final Logger LOGGER = LoggerFactory.getLogger(SimpleElasticsearchPersistentProperty.class); + private static final Log LOGGER = LogFactory.getLog(SimpleElasticsearchPersistentProperty.class); private static final List SUPPORTED_ID_PROPERTY_NAMES = Arrays.asList("id", "document"); private static final PropertyNameFieldNamingStrategy DEFAULT_FIELD_NAMING_STRATEGY = PropertyNameFieldNamingStrategy.INSTANCE; @@ -161,7 +161,7 @@ private void initPropertyValueConverter() { case Date_Nanos: { List dateConverters = getDateConverters(field, actualType); if (dateConverters.isEmpty()) { - LOGGER.warn("No date formatters configured for property '{}'.", getName()); + LOGGER.warn(String.format("No date formatters configured for property '%s'.", getName())); return; } @@ -170,7 +170,7 @@ private void initPropertyValueConverter() { } else if (Date.class.isAssignableFrom(actualType)) { propertyValueConverter = new DatePropertyValueConverter(this, dateConverters); } else { - LOGGER.warn("Unsupported type '{}' for date property '{}'.", actualType, getName()); + LOGGER.warn(String.format("Unsupported type '%s' for date property '%s'.", actualType, getName())); } break; } @@ -181,7 +181,7 @@ private void initPropertyValueConverter() { List dateConverters = getDateConverters(field, actualType); if (dateConverters.isEmpty()) { - LOGGER.warn("No date formatters configured for property '{}'.", getName()); + LOGGER.warn(String.format("No date formatters configured for property '%s'.", getName())); return; } @@ -191,7 +191,8 @@ private void initPropertyValueConverter() { } else if (Date.class.isAssignableFrom(genericType)) { propertyValueConverter = new DateRangePropertyValueConverter(this, dateConverters); } else { - LOGGER.warn("Unsupported generic type '{}' for date range property '{}'.", genericType, getName()); + LOGGER.warn( + String.format("Unsupported generic type '{%s' for date range property '%s'.", genericType, getName())); } break; } @@ -208,8 +209,8 @@ private void initPropertyValueConverter() { || (field.type() == FieldType.Float_Range && !Float.class.isAssignableFrom(genericType)) || (field.type() == FieldType.Long_Range && !Long.class.isAssignableFrom(genericType)) || (field.type() == FieldType.Double_Range && !Double.class.isAssignableFrom(genericType))) { - LOGGER.warn("Unsupported generic type '{}' for range field type '{}' of property '{}'.", genericType, - field.type(), getName()); + LOGGER.warn(String.format("Unsupported generic type '%s' for range field type '%s' of property '%s'.", + genericType, field.type(), getName())); return; } @@ -251,9 +252,9 @@ private List getDateConverters(Field field, Class List converters = new ArrayList<>(); if (dateFormats.length == 0 && dateFormatPatterns.length == 0) { - LOGGER.warn( - "Property '{}' has @Field type '{}' but has no built-in format or custom date pattern defined. Make sure you have a converter registered for type {}.", - getName(), field.type().name(), actualType.getSimpleName()); + LOGGER.warn(String.format( + "Property '%s' has @Field type '%s' but has no built-in format or custom date pattern defined. Make sure you have a converter registered for type %s.", + getName(), field.type().name(), actualType.getSimpleName())); return converters; } @@ -266,8 +267,9 @@ private List getDateConverters(Field field, Class case weekyear: case weekyear_week: case weekyear_week_day: - LOGGER.warn("No default converter available for '{}' and date format '{}'. Use a custom converter instead.", - actualType.getName(), dateFormat.name()); + LOGGER.warn(String.format( + "No default converter available for '%s' and date format '%s'. Use a custom converter instead.", + actualType.getName(), dateFormat.name())); break; default: converters.add(ElasticsearchDateConverter.of(dateFormat)); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java index 904281c07..68fa07643 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java @@ -24,13 +24,13 @@ import java.util.Optional; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQuery; +import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.IndexOperations; @@ -43,8 +43,6 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery; -import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQuery; -import org.springframework.data.elasticsearch.backend.elasticsearch7.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.query.Query; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.util.StreamUtils; @@ -71,8 +69,6 @@ */ public class SimpleElasticsearchRepository implements ElasticsearchRepository { - private static final Logger LOGGER = LoggerFactory.getLogger(SimpleElasticsearchRepository.class); - protected ElasticsearchOperations operations; protected IndexOperations indexOperations; diff --git a/src/main/java/org/springframework/data/elasticsearch/support/VersionInfo.java b/src/main/java/org/springframework/data/elasticsearch/support/VersionInfo.java index cdc027257..7ecebcab8 100644 --- a/src/main/java/org/springframework/data/elasticsearch/support/VersionInfo.java +++ b/src/main/java/org/springframework/data/elasticsearch/support/VersionInfo.java @@ -19,8 +19,8 @@ import java.io.InputStream; import java.util.Properties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; /** @@ -33,7 +33,7 @@ */ public final class VersionInfo { - private static final Logger LOG = LoggerFactory.getLogger(VersionInfo.class); + private static final Log LOGGER = LogFactory.getLog(VersionInfo.class); private static final String VERSION_PROPERTIES = "versions.properties"; @@ -50,7 +50,7 @@ public static Properties versionProperties() { try { versionProperties = loadVersionProperties(); } catch (IOException e) { - LOG.error("Could not load {}", VERSION_PROPERTIES, e); + LOGGER.error("Could not load " + VERSION_PROPERTIES, e); versionProperties = new Properties(); versionProperties.put(VERSION_SPRING_DATA_ELASTICSEARCH, "0.0.0"); versionProperties.put(VERSION_ELASTICSEARCH_CLIENT, "0.0.0"); @@ -70,25 +70,25 @@ public static void logVersions(String vendor, String runtimeLibraryVersion, @Nul Version versionRuntimeLibrary = Version.fromString(runtimeLibraryVersion); Version versionCluster = clusterVersion != null ? Version.fromString(clusterVersion) : null; - LOG.info("Version Spring Data Elasticsearch: {}", versionSpringDataElasticsearch.toString()); - LOG.info("Version Elasticsearch client in build: {}", versionBuiltLibraryES.toString()); - LOG.info("Version runtime client used: {} - {}", vendor, versionRuntimeLibrary.toString()); + LOGGER.info(String.format("Version Spring Data Elasticsearch: %s", versionSpringDataElasticsearch)); + LOGGER.info(String.format("Version Elasticsearch client in build: %s", versionBuiltLibraryES)); + LOGGER.info(String.format("Version runtime client used: %s - %s", vendor, versionRuntimeLibrary)); if (differInMajorOrMinor(versionBuiltLibraryES, versionRuntimeLibrary)) { - LOG.warn("Version mismatch in between Elasticsearch Clients build/use: {} - {}", versionBuiltLibraryES, - versionRuntimeLibrary); + LOGGER.warn(String.format("Version mismatch in between Elasticsearch Clients build/use: %s - %s", + versionBuiltLibraryES, versionRuntimeLibrary)); } if (versionCluster != null) { - LOG.info("Version cluster: {} - {}", vendor, versionCluster.toString()); + LOGGER.info(String.format("Version cluster: %s - %s", vendor, versionCluster)); if (differInMajorOrMinor(versionRuntimeLibrary, versionCluster)) { - LOG.warn("Version mismatch in between Client and Cluster: {} - {} - {}", vendor, versionRuntimeLibrary, - versionCluster); + LOGGER.warn(String.format("Version mismatch in between Client and Cluster: %s - %s - %s", vendor, + versionRuntimeLibrary, versionCluster)); } } } catch (Exception e) { - LOG.warn("Could not log version info: {} - {}", e.getClass().getSimpleName(), e.getMessage()); + LOGGER.warn(String.format("Could not log version info: %s - %s", e.getClass().getSimpleName(), e.getMessage())); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/FoobarIntegrationTest.java b/src/test/java/org/springframework/data/elasticsearch/FoobarIntegrationTest.java index 409bf4349..1015c3de0 100644 --- a/src/test/java/org/springframework/data/elasticsearch/FoobarIntegrationTest.java +++ b/src/test/java/org/springframework/data/elasticsearch/FoobarIntegrationTest.java @@ -4,8 +4,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest; /** @@ -15,8 +13,6 @@ @Foobar public abstract class FoobarIntegrationTest { - private final Logger LOGGER = LoggerFactory.getLogger(getClass()); - @Test @DisplayName("should run test") void shouldRunTest() { diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java index 9d055ea92..bef8de4ad 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java @@ -21,9 +21,9 @@ import java.util.Map; import java.util.Properties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.lang.Nullable; import org.testcontainers.elasticsearch.ElasticsearchContainer; import org.testcontainers.utility.DockerImageName; @@ -38,7 +38,7 @@ */ public class ClusterConnection implements ExtensionContext.Store.CloseableResource { - private static final Logger LOGGER = LoggerFactory.getLogger(ClusterConnection.class); + private static final Log LOGGER = LogFactory.getLog(ClusterConnection.class); private static final String SDE_TESTCONTAINER_IMAGE_NAME = "sde.testcontainers.image-name"; private static final String SDE_TESTCONTAINER_IMAGE_VERSION = "sde.testcontainers.image-version"; @@ -55,10 +55,14 @@ public ClusterConnection() { clusterConnectionInfo = startElasticsearchContainer(); if (clusterConnectionInfo != null) { - LOGGER.debug(clusterConnectionInfo.toString()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(clusterConnectionInfo.toString()); + } clusterConnectionInfoThreadLocal.set(clusterConnectionInfo); } else { - LOGGER.error("could not create ClusterConnectionInfo"); + if (LOGGER.isDebugEnabled()) { + LOGGER.error("could not create ClusterConnectionInfo"); + } } } @@ -82,7 +86,7 @@ private ClusterConnectionInfo startElasticsearchContainer() { try { IntegrationtestEnvironment integrationtestEnvironment = IntegrationtestEnvironment.get(); - LOGGER.info("Integration test environment: {}", integrationtestEnvironment); + LOGGER.info("Integration test environment: " + integrationtestEnvironment); if (integrationtestEnvironment == IntegrationtestEnvironment.UNDEFINED) { throw new IllegalArgumentException(IntegrationtestEnvironment.SYSTEM_PROPERTY + " property not set"); } @@ -128,13 +132,13 @@ private DockerImageName getDockerImageName(Map testcontainersPro String configuredImageName = imageName + ':' + imageVersion; DockerImageName dockerImageName = DockerImageName.parse(configuredImageName) .asCompatibleSubstituteFor("docker.elastic.co/elasticsearch/elasticsearch"); - LOGGER.info("Docker image: {}", dockerImageName); + LOGGER.info("Docker image: " + dockerImageName); return dockerImageName; } private Map testcontainersProperties(String propertiesFile) { - LOGGER.info("load configuration from {}", propertiesFile); + LOGGER.info("load configuration from " + propertiesFile); try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) { Properties props = new Properties(); @@ -155,10 +159,14 @@ private Map testcontainersProperties(String propertiesFile) { public void close() { if (clusterConnectionInfo != null && clusterConnectionInfo.getElasticsearchContainer() != null) { - LOGGER.debug("Stopping container"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Stopping container"); + } clusterConnectionInfo.getElasticsearchContainer().stop(); } - LOGGER.debug("closed"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("closed"); + } } } diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/SpringDataElasticsearchExtension.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/SpringDataElasticsearchExtension.java index 82ba9b973..63fa471f4 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/SpringDataElasticsearchExtension.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/SpringDataElasticsearchExtension.java @@ -19,13 +19,13 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.api.extension.ParameterResolutionException; import org.junit.jupiter.api.extension.ParameterResolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizer; @@ -46,7 +46,7 @@ public class SpringDataElasticsearchExtension implements BeforeAllCallback, ParameterResolver, ContextCustomizerFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataElasticsearchExtension.class); + private static final Log LOGGER = LogFactory.getLog(SpringDataElasticsearchExtension.class); private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace .create(SpringDataElasticsearchExtension.class.getName()); @@ -61,7 +61,9 @@ public void beforeAll(ExtensionContext extensionContext) { try { ExtensionContext.Store store = getStore(extensionContext); ClusterConnection clusterConnection = store.getOrComputeIfAbsent(STORE_KEY_CLUSTER_CONNECTION, key -> { - LOGGER.debug("creating ClusterConnection"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("creating ClusterConnection"); + } return createClusterConnection(); }, ClusterConnection.class); store.getOrComputeIfAbsent(STORE_KEY_CLUSTER_CONNECTION_INFO, diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml index 3fcfec056..99377e6ac 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback.xml @@ -1,4 +1,20 @@ + +