/** * Formats a log message for the logging module * * @param connectionId the id of the connection * @param now the current ime expressing in milliseconds * @param elapsed the time in milliseconds that the operation took to complete * @param category the category of the operation * @param prepared the SQL statement with all bind variables replaced with actual values * @param sql the sql statement executed * @param url the database url where the sql statement executed * @return the formatted log message */ @Override public String formatMessage(final int connectionId, final String now, final long elapsed, final String category, final String prepared, final String sql, final String url) { return now + "|" + elapsed + "|" + category + "|connection " + connectionId + "|url " + url + "|" + P6Util.singleLine(prepared) + "|" + P6Util.singleLine(sql); } }
.replaceAll(Pattern.quote(CATEGORY), category) .replaceAll(Pattern.quote(EFFECTIVE_SQL), Matcher.quoteReplacement(prepared)) .replaceAll(Pattern.quote(EFFECTIVE_SQL_SINGLELINE), Matcher.quoteReplacement(P6Util.singleLine(prepared))) .replaceAll(Pattern.quote(SQL), Matcher.quoteReplacement(sql)) .replaceAll(Pattern.quote(SQL_SINGLE_LINE), Matcher.quoteReplacement(P6Util.singleLine(sql))) .replaceAll(Pattern.quote(URL), url);
@Test public void testSingleLine() { Assert.assertEquals("abc efg", P6Util.singleLine("abc\nefg")); Assert.assertEquals("abc efg", P6Util.singleLine("abc\n\nefg")); Assert.assertEquals("abc efg", P6Util.singleLine("abc\r\n\nefg")); } @Test
/** * Formats a log message for the logging module * * @param connectionId the id of the connection * @param now the current ime expressing in milliseconds * @param elapsed the time in milliseconds that the operation took to complete * @param category the category of the operation * @param prepared the SQL statement with all bind variables replaced with actual values * @param sql the sql statement executed * @param url the database url where the sql statement executed * @return the formatted log message */ @Override public String formatMessage(final int connectionId, final String now, final long elapsed, final String category, final String prepared, final String sql, final String url) { return now + "|" + elapsed + "|" + category + "|connection " + connectionId + "|url " + url + "|" + P6Util.singleLine(prepared) + "|" + P6Util.singleLine(sql); } }
P6LogOptions.getActiveInstance().unSetSQLExpression(); assertEquals(1, super.getLogEntriesCount()); assertTrue(super.getLastLogEntry().contains(P6Util.singleLine(queryMultiline)));
.replaceAll(Pattern.quote(CATEGORY), category) .replaceAll(Pattern.quote(EFFECTIVE_SQL), Matcher.quoteReplacement(prepared)) .replaceAll(Pattern.quote(EFFECTIVE_SQL_SINGLELINE), Matcher.quoteReplacement(P6Util.singleLine(prepared))) .replaceAll(Pattern.quote(SQL), Matcher.quoteReplacement(sql)) .replaceAll(Pattern.quote(SQL_SINGLE_LINE), Matcher.quoteReplacement(P6Util.singleLine(sql))) .replaceAll(Pattern.quote(URL), url);