only perform the extra work if logging level is enabled
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/687a27ef Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/687a27ef Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/687a27ef Branch: refs/heads/GROOVY_2_4_X Commit: 687a27ef8c7ca81b6a08e8ee4800e20b51609a79 Parents: f4fbe35 Author: John Wagenleitner <[email protected]> Authored: Mon Mar 5 18:59:30 2018 -0800 Committer: John Wagenleitner <[email protected]> Committed: Mon Mar 5 19:08:44 2018 -0800 ---------------------------------------------------------------------- .../groovy-sql/src/main/java/groovy/sql/Sql.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/687a27ef/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java ---------------------------------------------------------------------- diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java index ceaf8b2..283ed54 100644 --- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java +++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java @@ -47,6 +47,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -598,14 +599,16 @@ public class Sql { LOG.fine("url = " + url); if (props != null) { connection = DriverManager.getConnection(url.toString(), props); - if (!props.containsKey("password")) { - LOG.fine("props = " + props); - } else { - // don't log the password - Properties propsCopy = new Properties(); - propsCopy.putAll(props); - propsCopy.setProperty("password", "***"); - LOG.fine("props = " + propsCopy); + if (LOG.isLoggable(Level.FINE)) { + if (!props.containsKey("password")) { + LOG.fine("props = " + props); + } else { + // don't log the password + Properties propsCopy = new Properties(); + propsCopy.putAll(props); + propsCopy.setProperty("password", "***"); + LOG.fine("props = " + propsCopy); + } } } else if (sqlArgs.containsKey("user")) { Object user = sqlArgs.remove("user");
