diff --git a/src/main/java/org/jdbcdslog/ConfigurationParameters.java b/src/main/java/org/jdbcdslog/ConfigurationParameters.java index dc0978f..149f1b6 100644 --- a/src/main/java/org/jdbcdslog/ConfigurationParameters.java +++ b/src/main/java/org/jdbcdslog/ConfigurationParameters.java @@ -23,7 +23,8 @@ public class ConfigurationParameters { static boolean logDetailAfterStatement = true; static boolean logAddBatchDetail = true; static boolean logAddBatch = true; - static boolean logExecuteBatchDetail =true; + static boolean logExecuteBatchDetail = true; + static boolean logExceptions = true; static { ClassLoader loader = ConfigurationParameters.class.getClassLoader(); @@ -47,6 +48,7 @@ public class ConfigurationParameters { initLogAddBatch(); initLogAddBatchDetail(); initLogExecuteBatchDetail(); + initLogExceptions(); } catch (Exception e) { logger.error(e.getMessage(), e); @@ -143,5 +145,8 @@ private static void initLogExecuteBatchDetail() { logExecuteBatchDetail = "true".equalsIgnoreCase(props.getProperty("jdbcdslog.logExecuteBatchDetail", "false")); } + private static void initLogExceptions() { + logExceptions = "true".equalsIgnoreCase(props.getProperty("jdbcdslog.logExceptions", "false")); + } /* init parameters end. */ } diff --git a/src/main/java/org/jdbcdslog/LogUtils.java b/src/main/java/org/jdbcdslog/LogUtils.java index dd279bc..ca2188f 100755 --- a/src/main/java/org/jdbcdslog/LogUtils.java +++ b/src/main/java/org/jdbcdslog/LogUtils.java @@ -11,13 +11,10 @@ import java.util.regex.Pattern; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.slf4j.MDC; public class LogUtils { - static Logger logger = LoggerFactory.getLogger(LogUtils.class); - public final static String CONNECTION_ID_MDC_KEY = "jdbcdslog.connectionId"; private final static String NAMED_PARAMETERS_PREFIX = ":"; @@ -27,16 +24,14 @@ public static void handleException(Throwable e, Logger l, StringBuilder msg) thr e = ((InvocationTargetException) e).getTargetException(); } - l.error(msg.toString(), e); + if (ConfigurationParameters.logExceptions) { + l.error(msg.toString(), e); + } throw e; } /** * Append Elapsed Time to log message if it is configured to be included. - * - * @param sb - * @param elapsedTimeInNano - * @return */ public static StringBuilder appendElapsedTime(StringBuilder sb, long elapsedTimeInNano) { if (ConfigurationParameters.showTime) { @@ -80,7 +75,7 @@ public static StringBuilder appendStackTrace(StringBuilder sb) { } public static int firstNonJdbcDsLogStackIndex(StackTraceElement[] stackTraces) { - int i = 0; + int i; for (i = 0; i < stackTraces.length; ++i) { if ( ! stackTraces[i].getClassName().startsWith("org.jdbcdslog")) { break; @@ -270,7 +265,6 @@ protected static String replaceEach(String text, String[] searchList, String[] r // index on index that the match was found int textIndex = -1; int replaceIndex = -1; - int tempIndex = -1; // index of replace array that will replace the search string found // NOTE: logic duplicated below START @@ -279,7 +273,7 @@ protected static String replaceEach(String text, String[] searchList, String[] r searchList[i].length() == 0 || replacementList[i] == null) { continue; } - tempIndex = text.indexOf(searchList[i]); + int tempIndex = text.indexOf(searchList[i]); // see if we need to keep searching for this if (tempIndex == -1) { @@ -329,7 +323,7 @@ protected static String replaceEach(String text, String[] searchList, String[] r textIndex = -1; replaceIndex = -1; - tempIndex = -1; + int tempIndex; // find the next earliest match // NOTE: logic mostly duplicated above START for (int i = 0; i < searchLength; i++) { diff --git a/src/main/java/org/jdbcdslog/ResultSetLoggingHandler.java b/src/main/java/org/jdbcdslog/ResultSetLoggingHandler.java index 97a1e9f..3939919 100644 --- a/src/main/java/org/jdbcdslog/ResultSetLoggingHandler.java +++ b/src/main/java/org/jdbcdslog/ResultSetLoggingHandler.java @@ -15,6 +15,7 @@ public class ResultSetLoggingHandler extends LoggingHandlerSupport { public ResultSetLoggingHandler(LogMetaData logMetaData, ResultSet target) { super(target); + this.logMetaData = logMetaData; } @Override