From abd24d0ec68e9b8dc557b9c060ebfc8a59dd163c Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 24 Jun 2014 10:22:28 +0200 Subject: [PATCH 1/2] DATAMONGO-961 - Improve logging message handling in MongoDbUtils. Prepare issue branch. --- pom.xml | 2 +- spring-data-mongodb-cross-store/pom.xml | 4 ++-- spring-data-mongodb-distribution/pom.xml | 2 +- spring-data-mongodb-log4j/pom.xml | 2 +- spring-data-mongodb/pom.xml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index a0f2a85952..3ee4dd1d3d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 1.6.0.BUILD-SNAPSHOT + 1.6.0.DATAMONGO-961-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-cross-store/pom.xml b/spring-data-mongodb-cross-store/pom.xml index df9b2107a0..255c522d42 100644 --- a/spring-data-mongodb-cross-store/pom.xml +++ b/spring-data-mongodb-cross-store/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-mongodb-parent - 1.6.0.BUILD-SNAPSHOT + 1.6.0.DATAMONGO-961-SNAPSHOT ../pom.xml @@ -48,7 +48,7 @@ org.springframework.data spring-data-mongodb - 1.6.0.BUILD-SNAPSHOT + 1.6.0.DATAMONGO-961-SNAPSHOT diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index 90e912f679..df89823894 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -13,7 +13,7 @@ org.springframework.data spring-data-mongodb-parent - 1.6.0.BUILD-SNAPSHOT + 1.6.0.DATAMONGO-961-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-log4j/pom.xml b/spring-data-mongodb-log4j/pom.xml index 82ecfa46d5..65e78e372f 100644 --- a/spring-data-mongodb-log4j/pom.xml +++ b/spring-data-mongodb-log4j/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 1.6.0.BUILD-SNAPSHOT + 1.6.0.DATAMONGO-961-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index 25453a7917..9baca0ad83 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -11,7 +11,7 @@ org.springframework.data spring-data-mongodb-parent - 1.6.0.BUILD-SNAPSHOT + 1.6.0.DATAMONGO-961-SNAPSHOT ../pom.xml From 538ac3cc9444e7fbdf20020dfc0946554682806a Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 24 Jun 2014 10:25:19 +0200 Subject: [PATCH 2/2] DATAMONGO-961 - Improve logging message handling in MongoDbUtils. Added guards to check whether the logging is enabled or not. Original pull request: #194. --- .../data/mongodb/core/MongoDbUtils.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbUtils.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbUtils.java index 11a46bda61..493baa1128 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbUtils.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2010-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,7 +94,9 @@ private static DB doGetDB(Mongo mongo, String databaseName, UserCredentials cred // DB found but not yet synchronized if (db != null && !dbHolder.isSynchronizedWithTransaction()) { - LOGGER.debug("Registering Spring transaction synchronization for existing MongoDB {}.", databaseName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Registering Spring transaction synchronization for existing MongoDB {}.", databaseName); + } TransactionSynchronizationManager.registerSynchronization(new MongoSynchronization(dbHolder, mongo)); dbHolder.setSynchronizedWithTransaction(true); @@ -106,7 +108,9 @@ private static DB doGetDB(Mongo mongo, String databaseName, UserCredentials cred } // Lookup fresh database instance - LOGGER.debug("Getting Mongo Database name=[{}]", databaseName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Getting Mongo Database name=[{}]", databaseName); + } DB db = mongo.getDB(databaseName); boolean credentialsGiven = credentials.hasUsername() && credentials.hasPassword(); @@ -130,7 +134,9 @@ private static DB doGetDB(Mongo mongo, String databaseName, UserCredentials cred // TX sync active, bind new database to thread if (TransactionSynchronizationManager.isSynchronizationActive()) { - LOGGER.debug("Registering Spring transaction synchronization for MongoDB instance {}.", databaseName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Registering Spring transaction synchronization for MongoDB instance {}.", databaseName); + } DbHolder holderToUse = dbHolder; @@ -185,11 +191,15 @@ public static boolean isDBTransactional(DB db, Mongo mongo) { public static void closeDB(DB db) { if (db != null) { - LOGGER.debug("Closing Mongo DB object"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Closing Mongo DB object"); + } try { db.requestDone(); } catch (Throwable ex) { - LOGGER.debug("Unexpected exception on closing Mongo DB object", ex); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Unexpected exception on closing Mongo DB object", ex); + } } } }