use of com.alibaba.druid.filter.logging.Log4jFilter in project druid by alibaba.
the class LogFilterTest4 method test_properties_1.
public void test_properties_1() throws Exception {
System.setProperty("druid.log.conn", "false");
System.setProperty("druid.log.stmt", "false");
System.setProperty("druid.log.rs", "false");
System.setProperty("druid.log.stmt.executableSql", "true");
try {
LogFilter filter = new Log4jFilter();
Assert.assertEquals(false, filter.isConnectionLogEnabled());
Assert.assertEquals(false, filter.isStatementLogEnabled());
Assert.assertEquals(true, filter.isStatementExecutableSqlLogEnable());
Assert.assertEquals(false, filter.isResultSetLogEnabled());
Properties properties = new Properties();
properties.setProperty("druid.log.conn", "true");
properties.setProperty("druid.log.stmt", "true");
properties.setProperty("druid.log.rs", "true");
properties.setProperty("druid.log.stmt.executableSql", "false");
filter.configFromProperties(properties);
Assert.assertEquals(true, filter.isConnectionLogEnabled());
Assert.assertEquals(true, filter.isStatementLogEnabled());
Assert.assertEquals(false, filter.isStatementExecutableSqlLogEnable());
Assert.assertEquals(true, filter.isResultSetLogEnabled());
} finally {
System.clearProperty("druid.log.conn");
System.clearProperty("druid.log.stmt");
System.clearProperty("druid.log.rs");
System.clearProperty("druid.log.stmt.executableSql");
}
}
use of com.alibaba.druid.filter.logging.Log4jFilter in project druid by alibaba.
the class LogFilterTest method test_logFilter_1.
public void test_logFilter_1() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
Log4jFilter log4jFilter = new Log4jFilter();
log4jFilter.init(dataSource);
config.getFilters().add(log4jFilter);
setLogDisableAll(log4jFilter, true);
CommonsLogFilter commonLogFilter = new CommonsLogFilter() {
@Override
public boolean isDataSourceLogEnabled() {
return false;
}
@Override
public boolean isConnectionLogEnabled() {
return false;
}
@Override
public boolean isStatementLogEnabled() {
return false;
}
@Override
public boolean isResultSetLogEnabled() {
return false;
}
@Override
public boolean isResultSetLogErrorEnabled() {
return false;
}
@Override
public boolean isResultSetNextAfterLogEnabled() {
return false;
}
};
commonLogFilter.init(dataSource);
config.getFilters().add(commonLogFilter);
setLogDisableAll(commonLogFilter, true);
executeSQL(dataSource);
}
use of com.alibaba.druid.filter.logging.Log4jFilter in project druid by alibaba.
the class LogFilterTest method test_logFilter_0.
public void test_logFilter_0() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
Log4jFilter log4jFilter = new Log4jFilter();
log4jFilter.init(dataSource);
config.getFilters().add(log4jFilter);
setLogDisableAll(log4jFilter, true);
CommonsLogFilter commonLogFilter = new CommonsLogFilter() {
@Override
public boolean isDataSourceLogEnabled() {
return true;
}
@Override
public boolean isConnectionLogEnabled() {
return true;
}
@Override
public boolean isStatementLogEnabled() {
return true;
}
@Override
public boolean isResultSetLogEnabled() {
return true;
}
@Override
public boolean isResultSetLogErrorEnabled() {
return true;
}
@Override
public boolean isResultSetNextAfterLogEnabled() {
return true;
}
};
commonLogFilter.init(dataSource);
config.getFilters().add(commonLogFilter);
setLogDisableAll(commonLogFilter, false);
executeSQL(dataSource);
}
use of com.alibaba.druid.filter.logging.Log4jFilter in project druid by alibaba.
the class ResultSetProxyImplTest method test_resultset.
public void test_resultset() throws Exception {
MockDriver driver = new MockDriver();
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(driver, config);
{
StatFilter filter = new StatFilter();
filter.init(dataSource);
config.getFilters().add(filter);
}
{
Log4jFilter filter = new Log4jFilter();
filter.init(dataSource);
config.getFilters().add(filter);
}
Connection conn = dataSource.connect(null);
conn.setClientInfo("name", null);
Statement stmt = conn.createStatement();
ResultSetProxy rs = (ResultSetProxy) stmt.executeQuery(sql);
rs.insertRow();
rs.refreshRow();
rs.moveToInsertRow();
rs.moveToCurrentRow();
rs.next();
rs.updateRef(1, null);
rs.updateArray(1, null);
rs.updateRowId(1, null);
rs.updateNString(1, null);
rs.updateNClob(1, (NClob) null);
rs.updateNClob(1, (Reader) null);
rs.updateNClob(1, (Reader) null, 0);
rs.updateSQLXML(1, null);
rs.updateNCharacterStream(1, null);
rs.updateNCharacterStream(1, null, 0);
rs.getArray("1");
rs.updateRef("1", null);
rs.updateArray("1", null);
rs.updateRowId("1", null);
rs.updateNString("1", null);
rs.updateNClob("1", (NClob) null);
rs.updateNClob("1", (Reader) null);
rs.updateNClob("1", (Reader) null, 0);
rs.updateSQLXML("1", null);
rs.updateNCharacterStream("1", null);
rs.updateNCharacterStream("1", null, 0);
}
use of com.alibaba.druid.filter.logging.Log4jFilter in project druid by alibaba.
the class Log4jFilterTest method test_logger.
public void test_logger() throws Exception {
Log4jFilter filter = new Log4jFilter();
filter.setDataSourceLoggerName("_datasource_name_");
filter.setConnectionLoggerName("_connection_name_");
filter.setStatementLoggerName("_statement_name_");
filter.setResultSetLoggerName("_resultset_name_");
Assert.assertEquals(filter.getDataSourceLoggerName(), "_datasource_name_");
Assert.assertEquals(filter.getConnectionLoggerName(), "_connection_name_");
Assert.assertEquals(filter.getStatementLoggerName(), "_statement_name_");
Assert.assertEquals(filter.getResultSetLoggerName(), "_resultset_name_");
filter.setDataSourceLogger(new FakeLogger("_datasoure_", true));
filter.setConnectionLogger(new FakeLogger("_connection_", true));
filter.setStatementLogger(new FakeLogger("_statement_", true));
filter.setResultSetLogger(new FakeLogger("_resultset_", true));
Assert.assertEquals(filter.getDataSourceLoggerName(), "_datasoure_");
Assert.assertEquals(filter.getConnectionLoggerName(), "_connection_");
Assert.assertEquals(filter.getStatementLoggerName(), "_statement_");
Assert.assertEquals(filter.getResultSetLoggerName(), "_resultset_");
setLogDisableAll(filter, true);
Assert.assertTrue(filter.isDataSourceLogEnabled());
Assert.assertTrue(filter.isConnectionLogErrorEnabled());
Assert.assertTrue(filter.isConnectionConnectBeforeLogEnabled());
Assert.assertTrue(filter.isConnectionConnectAfterLogEnabled());
Assert.assertTrue(filter.isConnectionCloseAfterLogEnabled());
Assert.assertTrue(filter.isConnectionCommitAfterLogEnabled());
Assert.assertTrue(filter.isConnectionRollbackAfterLogEnabled());
Assert.assertTrue(filter.isStatementLogEnabled());
Assert.assertTrue(filter.isStatementLogErrorEnabled());
Assert.assertTrue(filter.isStatementCreateAfterLogEnabled());
Assert.assertTrue(filter.isStatementCloseAfterLogEnabled());
Assert.assertTrue(filter.isStatementExecuteAfterLogEnabled());
Assert.assertTrue(filter.isStatementExecuteBatchAfterLogEnabled());
Assert.assertTrue(filter.isStatementExecuteQueryAfterLogEnabled());
Assert.assertTrue(filter.isStatementExecuteUpdateAfterLogEnabled());
Assert.assertTrue(filter.isStatementLogErrorEnabled());
Assert.assertTrue(filter.isStatementParameterSetLogEnabled());
Assert.assertTrue(filter.isStatementPrepareAfterLogEnabled());
Assert.assertTrue(filter.isStatementPrepareCallAfterLogEnabled());
Assert.assertTrue(filter.isResultSetLogEnabled());
Assert.assertTrue(filter.isResultSetLogErrorEnabled());
Assert.assertTrue(filter.isResultSetCloseAfterLogEnabled());
Assert.assertTrue(filter.isResultSetNextAfterLogEnabled());
Assert.assertTrue(filter.isResultSetOpenAfterLogEnabled());
// ////
filter.setDataSourceLogger(new FakeLogger("_datasoure_", false));
filter.setConnectionLogger(new FakeLogger("_connection_", false));
filter.setStatementLogger(new FakeLogger("_statement_", false));
filter.setResultSetLogger(new FakeLogger("_resultset_", false));
Assert.assertFalse(filter.isDataSourceLogEnabled());
Assert.assertFalse(filter.isConnectionLogErrorEnabled());
Assert.assertFalse(filter.isConnectionConnectBeforeLogEnabled());
Assert.assertFalse(filter.isConnectionConnectAfterLogEnabled());
Assert.assertFalse(filter.isConnectionCloseAfterLogEnabled());
Assert.assertFalse(filter.isConnectionCommitAfterLogEnabled());
Assert.assertFalse(filter.isConnectionRollbackAfterLogEnabled());
Assert.assertFalse(filter.isStatementLogEnabled());
Assert.assertFalse(filter.isStatementLogErrorEnabled());
Assert.assertFalse(filter.isStatementCreateAfterLogEnabled());
Assert.assertFalse(filter.isStatementCloseAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteBatchAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteQueryAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteUpdateAfterLogEnabled());
Assert.assertFalse(filter.isStatementLogErrorEnabled());
Assert.assertFalse(filter.isStatementParameterSetLogEnabled());
Assert.assertFalse(filter.isStatementPrepareAfterLogEnabled());
Assert.assertFalse(filter.isStatementPrepareCallAfterLogEnabled());
Assert.assertFalse(filter.isResultSetLogEnabled());
Assert.assertFalse(filter.isResultSetLogErrorEnabled());
Assert.assertFalse(filter.isResultSetCloseAfterLogEnabled());
Assert.assertFalse(filter.isResultSetNextAfterLogEnabled());
Assert.assertFalse(filter.isResultSetOpenAfterLogEnabled());
// //////////////////////////////////////
setLogDisableAll(filter, false);
// ////
filter.setDataSourceLogger(new FakeLogger("_datasoure_", false));
filter.setConnectionLogger(new FakeLogger("_connection_", false));
filter.setStatementLogger(new FakeLogger("_statement_", false));
filter.setResultSetLogger(new FakeLogger("_resultset_", false));
Assert.assertFalse(filter.isDataSourceLogEnabled());
Assert.assertFalse(filter.isConnectionLogErrorEnabled());
Assert.assertFalse(filter.isConnectionConnectBeforeLogEnabled());
Assert.assertFalse(filter.isConnectionConnectAfterLogEnabled());
Assert.assertFalse(filter.isConnectionCloseAfterLogEnabled());
Assert.assertFalse(filter.isConnectionCommitAfterLogEnabled());
Assert.assertFalse(filter.isConnectionRollbackAfterLogEnabled());
Assert.assertFalse(filter.isStatementLogEnabled());
Assert.assertFalse(filter.isStatementLogErrorEnabled());
Assert.assertFalse(filter.isStatementCreateAfterLogEnabled());
Assert.assertFalse(filter.isStatementCloseAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteBatchAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteQueryAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteUpdateAfterLogEnabled());
Assert.assertFalse(filter.isStatementLogErrorEnabled());
Assert.assertFalse(filter.isStatementParameterSetLogEnabled());
Assert.assertFalse(filter.isStatementPrepareAfterLogEnabled());
Assert.assertFalse(filter.isStatementPrepareCallAfterLogEnabled());
Assert.assertFalse(filter.isResultSetLogEnabled());
Assert.assertFalse(filter.isResultSetLogErrorEnabled());
Assert.assertFalse(filter.isResultSetCloseAfterLogEnabled());
Assert.assertFalse(filter.isResultSetNextAfterLogEnabled());
Assert.assertFalse(filter.isResultSetOpenAfterLogEnabled());
// //
// ////
filter.setDataSourceLogger(new FakeLogger("_datasoure_", true));
filter.setConnectionLogger(new FakeLogger("_connection_", true));
filter.setStatementLogger(new FakeLogger("_statement_", true));
filter.setResultSetLogger(new FakeLogger("_resultset_", true));
Assert.assertFalse(filter.isDataSourceLogEnabled());
Assert.assertFalse(filter.isConnectionLogErrorEnabled());
Assert.assertFalse(filter.isConnectionConnectBeforeLogEnabled());
Assert.assertFalse(filter.isConnectionConnectAfterLogEnabled());
Assert.assertFalse(filter.isConnectionCloseAfterLogEnabled());
Assert.assertFalse(filter.isConnectionCommitAfterLogEnabled());
Assert.assertFalse(filter.isConnectionRollbackAfterLogEnabled());
Assert.assertFalse(filter.isStatementLogEnabled());
Assert.assertFalse(filter.isStatementLogErrorEnabled());
Assert.assertFalse(filter.isStatementCreateAfterLogEnabled());
Assert.assertFalse(filter.isStatementCloseAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteBatchAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteQueryAfterLogEnabled());
Assert.assertFalse(filter.isStatementExecuteUpdateAfterLogEnabled());
Assert.assertFalse(filter.isStatementLogErrorEnabled());
Assert.assertFalse(filter.isStatementParameterSetLogEnabled());
Assert.assertFalse(filter.isStatementPrepareAfterLogEnabled());
Assert.assertFalse(filter.isStatementPrepareCallAfterLogEnabled());
Assert.assertFalse(filter.isResultSetLogEnabled());
Assert.assertFalse(filter.isResultSetLogErrorEnabled());
Assert.assertFalse(filter.isResultSetCloseAfterLogEnabled());
Assert.assertFalse(filter.isResultSetNextAfterLogEnabled());
Assert.assertFalse(filter.isResultSetOpenAfterLogEnabled());
}
Aggregations