2424import java .util .concurrent .TimeUnit ;
2525import java .util .stream .Collectors ;
2626
27+ import org .apache .commons .logging .Log ;
28+ import org .apache .commons .logging .LogFactory ;
2729import org .bson .Document ;
2830import org .bson .conversions .Bson ;
29- import org .slf4j .Logger ;
30- import org .slf4j .LoggerFactory ;
3131
3232import org .springframework .beans .BeansException ;
3333import org .springframework .context .ApplicationContext ;
163163 */
164164public 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