Skip to content

Commit 8c7ae5e

Browse files
committed
Migrate off SLF4J to Spring JCL.
Closes #3881
1 parent 3ab8e88 commit 8c7ae5e

27 files changed

+215
-191
lines changed

spring-data-mongodb/pom.xml

-7
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,6 @@
237237
<optional>true</optional>
238238
</dependency>
239239

240-
<dependency>
241-
<groupId>org.slf4j</groupId>
242-
<artifactId>jul-to-slf4j</artifactId>
243-
<version>${slf4j}</version>
244-
<scope>test</scope>
245-
</dependency>
246-
247240
<dependency>
248241
<groupId>nl.jqno.equalsverifier</groupId>
249242
<artifactId>equalsverifier</artifactId>

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/SpringDataMongoDB.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package org.springframework.data.mongodb;
1717

18-
import org.slf4j.Logger;
19-
import org.slf4j.LoggerFactory;
18+
import org.apache.commons.logging.Log;
19+
import org.apache.commons.logging.LogFactory;
2020
import org.springframework.data.util.Version;
2121
import org.springframework.util.StringUtils;
2222

@@ -31,7 +31,7 @@
3131
*/
3232
public class SpringDataMongoDB {
3333

34-
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataMongoDB.class);
34+
private static final Log LOGGER = LogFactory.getLog(SpringDataMongoDB.class);
3535

3636
private static final Version FALLBACK_VERSION = new Version(3);
3737
private static final MongoDriverInformation DRIVER_INFORMATION = MongoDriverInformation
@@ -68,7 +68,7 @@ public static Version version() {
6868
try {
6969
return Version.parse(versionString);
7070
} catch (Exception e) {
71-
LOGGER.debug("Cannot read Spring Data MongoDB version '{}'.", versionString);
71+
LOGGER.debug(String.format("Cannot read Spring Data MongoDB version '%s'.", versionString));
7272
}
7373

7474
return FALLBACK_VERSION;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/ServerAddressPropertyEditor.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.util.HashSet;
2222
import java.util.Set;
2323

24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
24+
import org.apache.commons.logging.Log;
25+
import org.apache.commons.logging.LogFactory;
2626
import org.springframework.lang.Nullable;
2727
import org.springframework.util.Assert;
2828
import org.springframework.util.StringUtils;
@@ -43,8 +43,8 @@ public class ServerAddressPropertyEditor extends PropertyEditorSupport {
4343
* A port is a number without a leading 0 at the end of the address that is proceeded by just a single :.
4444
*/
4545
private static final String HOST_PORT_SPLIT_PATTERN = "(?<!:):(?=[123456789]\\d*$)";
46-
private static final String COULD_NOT_PARSE_ADDRESS_MESSAGE = "Could not parse address {} '{}'. Check your replica set configuration!";
47-
private static final Logger LOG = LoggerFactory.getLogger(ServerAddressPropertyEditor.class);
46+
private static final String COULD_NOT_PARSE_ADDRESS_MESSAGE = "Could not parse address %s '%s'. Check your replica set configuration!";
47+
private static final Log LOG = LogFactory.getLog(ServerAddressPropertyEditor.class);
4848

4949
/*
5050
* (non-Javadoc)
@@ -88,14 +88,14 @@ public void setAsText(@Nullable String replicaSetString) {
8888
private ServerAddress parseServerAddress(String source) {
8989

9090
if (!StringUtils.hasText(source)) {
91-
LOG.warn(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source);
91+
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
9292
return null;
9393
}
9494

9595
String[] hostAndPort = extractHostAddressAndPort(source.trim());
9696

9797
if (hostAndPort.length > 2) {
98-
LOG.warn(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source);
98+
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "source", source));
9999
return null;
100100
}
101101

@@ -105,9 +105,9 @@ private ServerAddress parseServerAddress(String source) {
105105

106106
return port == null ? new ServerAddress(hostAddress) : new ServerAddress(hostAddress, port);
107107
} catch (UnknownHostException e) {
108-
LOG.warn(COULD_NOT_PARSE_ADDRESS_MESSAGE, "host", hostAndPort[0]);
108+
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "host", hostAndPort[0]));
109109
} catch (NumberFormatException e) {
110-
LOG.warn(COULD_NOT_PARSE_ADDRESS_MESSAGE, "port", hostAndPort[1]);
110+
LOG.warn(String.format(COULD_NOT_PARSE_ADDRESS_MESSAGE, "port", hostAndPort[1]));
111111
}
112112

113113
return null;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

+49-44
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import java.util.concurrent.TimeUnit;
2525
import java.util.stream.Collectors;
2626

27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
2729
import org.bson.Document;
2830
import org.bson.conversions.Bson;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3131

3232
import org.springframework.beans.BeansException;
3333
import org.springframework.context.ApplicationContext;
@@ -163,7 +163,7 @@
163163
*/
164164
public class MongoTemplate implements MongoOperations, ApplicationContextAware, IndexOperationsProvider {
165165

166-
private static final Logger LOGGER = LoggerFactory.getLogger(MongoTemplate.class);
166+
private static final Log LOGGER = LogFactory.getLog(MongoTemplate.class);
167167
private static final WriteResultChecking DEFAULT_WRITE_RESULT_CHECKING = WriteResultChecking.NONE;
168168

169169
private final MongoConverter mongoConverter;
@@ -507,8 +507,8 @@ protected void executeQuery(Query query, String collectionName, DocumentCallback
507507
Document fieldsObject = query.getFieldsObject();
508508

509509
if (LOGGER.isDebugEnabled()) {
510-
LOGGER.debug("Executing query: {} sort: {} fields: {} in collection: {}", serializeToJsonSafely(queryObject),
511-
sortObject, fieldsObject, collectionName);
510+
LOGGER.debug(String.format("Executing query: %s sort: %s fields: %s in collection: %s",
511+
serializeToJsonSafely(queryObject), sortObject, fieldsObject, collectionName));
512512
}
513513

514514
this.executeQueryInternal(new FindCallback(queryObject, fieldsObject, null),
@@ -700,8 +700,8 @@ public void dropCollection(String collectionName) {
700700
execute(collectionName, (CollectionCallback<Void>) collection -> {
701701
collection.drop();
702702
if (LOGGER.isDebugEnabled()) {
703-
LOGGER.debug("Dropped collection [{}]",
704-
collection.getNamespace() != null ? collection.getNamespace().getCollectionName() : collectionName);
703+
LOGGER.debug(String.format("Dropped collection [%s]",
704+
collection.getNamespace() != null ? collection.getNamespace().getCollectionName() : collectionName));
705705
}
706706
return null;
707707
});
@@ -903,8 +903,8 @@ public <T> List<T> findDistinct(Query query, String field, String collectionName
903903
MongoIterable<?> result = execute(collectionName, (collection) -> {
904904

905905
if (LOGGER.isDebugEnabled()) {
906-
LOGGER.debug("Executing findDistinct using query {} for field: {} in collection: {}",
907-
serializeToJsonSafely(mappedQuery), field, collectionName);
906+
LOGGER.debug(String.format("Executing findDistinct using query %s for field: %s in collection: %s",
907+
serializeToJsonSafely(mappedQuery), field, collectionName));
908908
}
909909

910910
QueryCursorPreparer preparer = new QueryCursorPreparer(query, entityClass);
@@ -1126,7 +1126,8 @@ public long count(Query query, @Nullable Class<?> entityClass, String collection
11261126
protected long doCount(String collectionName, Document filter, CountOptions options) {
11271127

11281128
if (LOGGER.isDebugEnabled()) {
1129-
LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName);
1129+
LOGGER
1130+
.debug(String.format("Executing count: %s in collection: %s", serializeToJsonSafely(filter), collectionName));
11301131
}
11311132

11321133
return execute(collectionName,
@@ -1453,7 +1454,8 @@ protected <T> T doSave(String collectionName, T objectToSave, MongoWriter<T> wri
14531454
protected Object insertDocument(String collectionName, Document document, Class<?> entityClass) {
14541455

14551456
if (LOGGER.isDebugEnabled()) {
1456-
LOGGER.debug("Inserting Document containing fields: {} in collection: {}", document.keySet(), collectionName);
1457+
LOGGER.debug(String.format("Inserting Document containing fields: %s in collection: %s", document.keySet(),
1458+
collectionName));
14571459
}
14581460

14591461
return execute(collectionName, collection -> {
@@ -1478,7 +1480,7 @@ protected List<Object> insertDocumentList(String collectionName, List<Document>
14781480
}
14791481

14801482
if (LOGGER.isDebugEnabled()) {
1481-
LOGGER.debug("Inserting list of Documents containing {} items", documents.size());
1483+
LOGGER.debug(String.format("Inserting list of Documents containing %s items", documents.size()));
14821484
}
14831485

14841486
execute(collectionName, collection -> {
@@ -1502,7 +1504,7 @@ protected List<Object> insertDocumentList(String collectionName, List<Document>
15021504
protected Object saveDocument(String collectionName, Document dbDoc, Class<?> entityClass) {
15031505

15041506
if (LOGGER.isDebugEnabled()) {
1505-
LOGGER.debug("Saving Document containing fields: {}", dbDoc.keySet());
1507+
LOGGER.debug(String.format("Saving Document containing fields: %s", dbDoc.keySet()));
15061508
}
15071509

15081510
return execute(collectionName, collection -> {
@@ -1607,8 +1609,8 @@ protected UpdateResult doUpdate(String collectionName, Query query, UpdateDefini
16071609

16081610
if (query.isSorted() && LOGGER.isWarnEnabled()) {
16091611

1610-
LOGGER.warn("{} does not support sort ('{}'). Please use findAndModify() instead.",
1611-
upsert ? "Upsert" : "UpdateFirst", serializeToJsonSafely(query.getSortObject()));
1612+
LOGGER.warn(String.format("%s does not support sort ('%s'). Please use findAndModify() instead.",
1613+
upsert ? "Upsert" : "UpdateFirst", serializeToJsonSafely(query.getSortObject())));
16121614
}
16131615

16141616
MongoPersistentEntity<?> entity = entityClass == null ? null : getPersistentEntity(entityClass);
@@ -1630,8 +1632,8 @@ protected UpdateResult doUpdate(String collectionName, Query query, UpdateDefini
16301632
return execute(collectionName, collection -> {
16311633

16321634
if (LOGGER.isDebugEnabled()) {
1633-
LOGGER.debug("Calling update using query: {} and update: {} in collection: {}",
1634-
serializeToJsonSafely(queryObj), serializeToJsonSafely(pipeline), collectionName);
1635+
LOGGER.debug(String.format("Calling update using query: %s and update: %s in collection: %s",
1636+
serializeToJsonSafely(queryObj), serializeToJsonSafely(pipeline), collectionName));
16351637
}
16361638

16371639
collection = writeConcernToUse != null ? collection.withWriteConcern(writeConcernToUse) : collection;
@@ -1648,8 +1650,8 @@ protected UpdateResult doUpdate(String collectionName, Query query, UpdateDefini
16481650
return execute(collectionName, collection -> {
16491651

16501652
if (LOGGER.isDebugEnabled()) {
1651-
LOGGER.debug("Calling update using query: {} and update: {} in collection: {}", serializeToJsonSafely(queryObj),
1652-
serializeToJsonSafely(updateObj), collectionName);
1653+
LOGGER.debug(String.format("Calling update using query: %s and update: %s in collection: %s",
1654+
serializeToJsonSafely(queryObj), serializeToJsonSafely(updateObj), collectionName));
16531655
}
16541656

16551657
collection = writeConcernToUse != null ? collection.withWriteConcern(writeConcernToUse) : collection;
@@ -1739,8 +1741,8 @@ protected <T> DeleteResult doRemove(String collectionName, Query query, @Nullabl
17391741
Document removeQuery = queryObject;
17401742

17411743
if (LOGGER.isDebugEnabled()) {
1742-
LOGGER.debug("Remove using query: {} in collection: {}.",
1743-
new Object[] { serializeToJsonSafely(removeQuery), collectionName });
1744+
LOGGER.debug(String.format("Remove using query: %s in collection: %s.", serializeToJsonSafely(removeQuery),
1745+
collectionName));
17441746
}
17451747

17461748
if (query.getLimit() > 0 || query.getSkip() > 0) {
@@ -1954,13 +1956,13 @@ public <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputColl
19541956
Document commandObject = new Document("group", document);
19551957

19561958
if (LOGGER.isDebugEnabled()) {
1957-
LOGGER.debug("Executing Group with Document [{}]", serializeToJsonSafely(commandObject));
1959+
LOGGER.debug(String.format("Executing Group with Document [%s]", serializeToJsonSafely(commandObject)));
19581960
}
19591961

19601962
Document commandResult = executeCommand(commandObject, this.readPreference);
19611963

19621964
if (LOGGER.isDebugEnabled()) {
1963-
LOGGER.debug("Group command result = [{}]", commandResult);
1965+
LOGGER.debug(String.format("Group command result = [%s]", commandResult));
19641966
}
19651967

19661968
@SuppressWarnings("unchecked")
@@ -2132,7 +2134,7 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
21322134
Document command = aggregationUtil.createCommand(collectionName, aggregation, context);
21332135

21342136
if (LOGGER.isDebugEnabled()) {
2135-
LOGGER.debug("Executing aggregation: {}", serializeToJsonSafely(command));
2137+
LOGGER.debug(String.format("Executing aggregation: %s", serializeToJsonSafely(command)));
21362138
}
21372139

21382140
Document commandResult = executeCommand(command);
@@ -2143,7 +2145,8 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
21432145
List<Document> pipeline = aggregationUtil.createPipeline(aggregation, context);
21442146

21452147
if (LOGGER.isDebugEnabled()) {
2146-
LOGGER.debug("Executing aggregation: {} in collection {}", serializeToJsonSafely(pipeline), collectionName);
2148+
LOGGER.debug(
2149+
String.format("Executing aggregation: %s in collection %s", serializeToJsonSafely(pipeline), collectionName));
21472150
}
21482151

21492152
return execute(collectionName, collection -> {
@@ -2209,7 +2212,8 @@ protected <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, Stri
22092212
List<Document> pipeline = aggregationDefinition.getAggregationPipeline();
22102213

22112214
if (LOGGER.isDebugEnabled()) {
2212-
LOGGER.debug("Streaming aggregation: {} in collection {}", serializeToJsonSafely(pipeline), collectionName);
2215+
LOGGER.debug(
2216+
String.format("Streaming aggregation: %s in collection %s", serializeToJsonSafely(pipeline), collectionName));
22132217
}
22142218

22152219
ReadDocumentCallback<O> readCallback = new ReadDocumentCallback<>(mongoConverter, outputType, collectionName);
@@ -2455,8 +2459,8 @@ protected MongoCollection<Document> doCreateCollection(String collectionName, Do
24552459

24562460
// TODO: Emit a collection created event
24572461
if (LOGGER.isDebugEnabled()) {
2458-
LOGGER.debug("Created collection [{}]",
2459-
coll.getNamespace() != null ? coll.getNamespace().getCollectionName() : collectionName);
2462+
LOGGER.debug(String.format("Created collection [%s]",
2463+
coll.getNamespace() != null ? coll.getNamespace().getCollectionName() : collectionName));
24602464
}
24612465
return coll;
24622466
});
@@ -2499,8 +2503,8 @@ protected <T> T doFindOne(String collectionName, Document query, Document fields
24992503
Document mappedQuery = queryContext.getMappedQuery(entity);
25002504

25012505
if (LOGGER.isDebugEnabled()) {
2502-
LOGGER.debug("findOne using query: {} fields: {} for class: {} in collection: {}", serializeToJsonSafely(query),
2503-
mappedFields, entityClass, collectionName);
2506+
LOGGER.debug(String.format("findOne using query: %s fields: %s for class: %s in collection: %s",
2507+
serializeToJsonSafely(query), mappedFields, entityClass, collectionName));
25042508
}
25052509

25062510
return executeFindOneInternal(new FindOneCallback(mappedQuery, mappedFields, preparer),
@@ -2551,8 +2555,8 @@ protected <S, T> List<T> doFind(String collectionName, Document query, Document
25512555
Document mappedQuery = queryContext.getMappedQuery(entity);
25522556

25532557
if (LOGGER.isDebugEnabled()) {
2554-
LOGGER.debug("find using query: {} fields: {} for class: {} in collection: {}",
2555-
serializeToJsonSafely(mappedQuery), mappedFields, entityClass, collectionName);
2558+
LOGGER.debug(String.format("find using query: %s fields: %s for class: %s in collection: %s",
2559+
serializeToJsonSafely(mappedQuery), mappedFields, entityClass, collectionName));
25562560
}
25572561

25582562
return executeFindMultiInternal(new FindCallback(mappedQuery, mappedFields, null),
@@ -2575,8 +2579,8 @@ <S, T> List<T> doFind(String collectionName, Document query, Document fields, Cl
25752579
Document mappedQuery = queryContext.getMappedQuery(entity);
25762580

25772581
if (LOGGER.isDebugEnabled()) {
2578-
LOGGER.debug("find using query: {} fields: {} for class: {} in collection: {}",
2579-
serializeToJsonSafely(mappedQuery), mappedFields, sourceClass, collectionName);
2582+
LOGGER.debug(String.format("find using query: %s fields: %s for class: %s in collection: %s",
2583+
serializeToJsonSafely(mappedQuery), mappedFields, sourceClass, collectionName));
25802584
}
25812585

25822586
return executeFindMultiInternal(new FindCallback(mappedQuery, mappedFields, null), preparer,
@@ -2678,8 +2682,8 @@ protected <T> T doFindAndRemove(String collectionName, Document query, Document
26782682
EntityReader<? super T, Bson> readerToUse = this.mongoConverter;
26792683

26802684
if (LOGGER.isDebugEnabled()) {
2681-
LOGGER.debug("findAndRemove using query: {} fields: {} sort: {} for class: {} in collection: {}",
2682-
serializeToJsonSafely(query), fields, sort, entityClass, collectionName);
2685+
LOGGER.debug(String.format("findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s",
2686+
serializeToJsonSafely(query), fields, sort, entityClass, collectionName));
26832687
}
26842688

26852689
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
@@ -2709,10 +2713,10 @@ protected <T> T doFindAndModify(String collectionName, Document query, Document
27092713
: updateContext.getMappedUpdate(entity);
27102714

27112715
if (LOGGER.isDebugEnabled()) {
2712-
LOGGER.debug(
2713-
"findAndModify using query: {} fields: {} sort: {} for class: {} and update: {} " + "in collection: {}",
2716+
LOGGER.debug(String.format(
2717+
"findAndModify using query: %s fields: %s sort: %s for class: %s and update: %s in collection: %s",
27142718
serializeToJsonSafely(mappedQuery), fields, sort, entityClass, serializeToJsonSafely(mappedUpdate),
2715-
collectionName);
2719+
collectionName));
27162720
}
27172721

27182722
return executeFindOneInternal(
@@ -2742,10 +2746,10 @@ protected <T> T doFindAndReplace(String collectionName, Document mappedQuery, Do
27422746
Document replacement, FindAndReplaceOptions options, Class<T> resultType) {
27432747

27442748
if (LOGGER.isDebugEnabled()) {
2745-
LOGGER.debug(
2746-
"findAndReplace using query: {} fields: {} sort: {} for class: {} and replacement: {} " + "in collection: {}",
2749+
LOGGER.debug(String.format(
2750+
"findAndReplace using query: %s fields: %s sort: %s for class: %s and replacement: %s " + "in collection: %s",
27472751
serializeToJsonSafely(mappedQuery), serializeToJsonSafely(mappedFields), serializeToJsonSafely(mappedSort),
2748-
entityType, serializeToJsonSafely(replacement), collectionName);
2752+
entityType, serializeToJsonSafely(replacement), collectionName));
27492753
}
27502754

27512755
return executeFindOneInternal(
@@ -2937,9 +2941,10 @@ public Document doInCollection(MongoCollection<Document> collection) throws Mong
29372941

29382942
if (LOGGER.isDebugEnabled()) {
29392943

2940-
LOGGER.debug("findOne using query: {} fields: {} in db.collection: {}", serializeToJsonSafely(query),
2944+
LOGGER.debug(String.format("findOne using query: %s fields: %s in db.collection: %s",
2945+
serializeToJsonSafely(query),
29412946
serializeToJsonSafely(fields.orElseGet(Document::new)),
2942-
collection.getNamespace() != null ? collection.getNamespace().getFullName() : "n/a");
2947+
collection.getNamespace() != null ? collection.getNamespace().getFullName() : "n/a"));
29432948
}
29442949

29452950
if (fields.isPresent()) {

0 commit comments

Comments
 (0)