Search in sources :

Example 1 with Log4jFilter

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");
    }
}
Also used : Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter) Properties(java.util.Properties) LogFilter(com.alibaba.druid.filter.logging.LogFilter)

Example 2 with Log4jFilter

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);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) CommonsLogFilter(com.alibaba.druid.filter.logging.CommonsLogFilter) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter)

Example 3 with Log4jFilter

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);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) CommonsLogFilter(com.alibaba.druid.filter.logging.CommonsLogFilter) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter)

Example 4 with Log4jFilter

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);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Statement(java.sql.Statement) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter) StatFilter(com.alibaba.druid.filter.stat.StatFilter) Connection(java.sql.Connection) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy)

Example 5 with Log4jFilter

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());
}
Also used : Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter)

Aggregations

Log4jFilter (com.alibaba.druid.filter.logging.Log4jFilter)7 MockDriver (com.alibaba.druid.mock.MockDriver)4 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)4 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)4 CommonsLogFilter (com.alibaba.druid.filter.logging.CommonsLogFilter)3 LogFilter (com.alibaba.druid.filter.logging.LogFilter)2 Properties (java.util.Properties)2 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 StatFilter (com.alibaba.druid.filter.stat.StatFilter)1 MockResultSet (com.alibaba.druid.mock.MockResultSet)1 MockResultSetMetaData (com.alibaba.druid.mock.MockResultSetMetaData)1 MockStatement (com.alibaba.druid.mock.MockStatement)1 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)1 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)1 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)1 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)1 StatementProxyImpl (com.alibaba.druid.proxy.jdbc.StatementProxyImpl)1 Connection (java.sql.Connection)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1