druid的版本,以及日志框架使用的是最近震惊世界的log4j2-2.17.0:

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

druid数据源配置中修改一下如下配置:

  connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000;druid.log.conn=false;druid.log.stmt=true;druid.log.rs=false;druid.log.stmt.executableSql=true

解释:
druid.log.stmt.executableSql这个配置代表开启打印可执行sql,就是sql和参数拼好的sql,拷贝出来就能执行;

出处:
com.alibaba.druid.filter.logging.LogFilter中configFromProperties方法,这个方法会执行两次,第一次从系统变量中读取配置,第二次从数据源的connectionProperties属性中读取配置:

   public void configFromProperties(Properties properties) {
        {
            String prop = properties.getProperty("druid.log.conn");
            if ("false".equals(prop)) {
                connectionLogEnabled = false;
            } else if ("true".equals(prop)) {
                connectionLogEnabled = true;
            }
        }
        {
            String prop = properties.getProperty("druid.log.stmt");
            if ("false".equals(prop)) {
                statementLogEnabled = false;
            } else if ("true".equals(prop)) {
                statementLogEnabled = true;
            }
        }
        {
            String prop = properties.getProperty("druid.log.rs");
            if ("false".equals(prop)) {
                resultSetLogEnabled = false;
            } else if ("true".equals(prop)) {
                resultSetLogEnabled = true;
            }
        }
        {
            String prop = properties.getProperty("druid.log.stmt.executableSql");
            if ("true".equals(prop)) {
                statementExecutableSqlLogEnable = true;
            } else if ("false".equals(prop)) {
                statementExecutableSqlLogEnable = false;
            }
        }
    }
GitHub 加速计划 / druid / druid
6
4
下载
阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
最近提交(Master分支:4 个月前 )
933dee04 - 13 天前
3246166f - Add constructor with SQLParserFeature support to SparkStatementParser - Fix SQLParserUtils to pass features parameter to SparkStatementParser, CKStatementParser and StarRocksStatementParser 23 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐