diff --git a/eladmin-common/src/main/java/me/zhengjie/config/CustomP6SpyLogger.java b/eladmin-common/src/main/java/me/zhengjie/config/CustomP6SpyLogger.java
new file mode 100644
index 00000000..c23de95d
--- /dev/null
+++ b/eladmin-common/src/main/java/me/zhengjie/config/CustomP6SpyLogger.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2019-2020 Zheng Jie
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package me.zhengjie.config;
+
+import cn.hutool.core.util.StrUtil;
+import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author Zheng Jie
+ * @description 自定义 p6spy sql输出格式
+ * @date 2024-12-26
+ **/
+@Slf4j
+public class CustomP6SpyLogger implements MessageFormattingStrategy {
+
+ // 重置颜色
+ private static final String RESET = "\u001B[0m";
+ // 红色
+ private static final String RED = "\u001B[31m";
+ // 绿色
+ private static final String GREEN = "\u001B[32m";
+
+ /**
+ * 格式化 sql
+ * @param connectionId 连接id
+ * @param now 当前时间
+ * @param elapsed 执行时长
+ * @param category sql分类
+ * @param prepared 预编译sql
+ * @param sql 执行sql
+ * @param url 数据库连接url
+ * @return 格式化后的sql
+ */
+ @Override
+ public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
+ // 去掉换行和多余空格
+ if(StrUtil.isNotBlank(sql)){
+ sql = sql.replaceAll("\\s+", " ").trim();
+ }
+
+ // 格式化并加上颜色
+ return String.format(
+ "%s[Time: %dms]%s - %s%s%s;",
+ GREEN, elapsed, RESET, RED, sql, RESET
+ );
+ }
+}
+
diff --git a/eladmin-system/src/main/resources/config/application-dev.yml b/eladmin-system/src/main/resources/config/application-dev.yml
index bb5317f6..fa8b7ede 100644
--- a/eladmin-system/src/main/resources/config/application-dev.yml
+++ b/eladmin-system/src/main/resources/config/application-dev.yml
@@ -3,10 +3,10 @@ spring:
datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
- driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
- url: jdbc:log4jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:eladmin}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
- username: ${DB_USER:root}
- password: ${DB_PWD:123456}
+ driverClassName: com.p6spy.engine.spy.P6SpyDriver
+ url: jdbc:p6spy:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
+ username: root
+ password: 123456
# 初始连接数,建议设置为与最小空闲连接数相同
initial-size: 20
# 最小空闲连接数,保持足够的空闲连接以应对请求
@@ -86,9 +86,9 @@ jwt:
# 令牌过期时间 此处单位/毫秒 ,默认4小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds: 14400000
# 在线用户key
- online-key: "online-token:"
+ online-key: "online_token:"
# 验证码
- code-key: "captcha-code:"
+ code-key: "captcha_code:"
# token 续期检查时间范围(默认30分钟,单位毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
detect: 1800000
# 续期时间范围,默认1小时,单位毫秒
diff --git a/eladmin-system/src/main/resources/config/application-prod.yml b/eladmin-system/src/main/resources/config/application-prod.yml
index 291e20e7..4d9d2aab 100644
--- a/eladmin-system/src/main/resources/config/application-prod.yml
+++ b/eladmin-system/src/main/resources/config/application-prod.yml
@@ -3,8 +3,8 @@ spring:
datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
- driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
- url: jdbc:log4jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:eladmin}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
+ driverClassName: com.mysql.cj.jdbc.Driver
+ url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:eladmin}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: ${DB_USER:root}
password: ${DB_PWD:123456}
# 初始连接数,建议设置为与最小空闲连接数相同
@@ -90,9 +90,9 @@ jwt:
# 令牌过期时间 此处单位/毫秒 ,默认2小时,可在此网站生成 https://www.convertworld.com/zh-hans/time/milliseconds.html
token-validity-in-seconds: 7200000
# 在线用户key
- online-key: "online-token:"
+ online-key: "online_token:"
# 验证码
- code-key: "captcha-code:"
+ code-key: "captcha_code:"
# token 续期检查时间范围(默认30分钟,单位默认毫秒),在token即将过期的一段时间内用户操作了,则给用户的token续期
detect: 1800000
# 续期时间范围,默认 1小时,这里单位毫秒
diff --git a/eladmin-system/src/main/resources/log4jdbc.log4j2.properties b/eladmin-system/src/main/resources/log4jdbc.log4j2.properties
deleted file mode 100644
index 302525ff..00000000
--- a/eladmin-system/src/main/resources/log4jdbc.log4j2.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
-log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
-log4jdbc.auto.load.popular.drivers=false
-log4jdbc.drivers=com.mysql.cj.jdbc.Driver
\ No newline at end of file
diff --git a/eladmin-system/src/main/resources/logback.xml b/eladmin-system/src/main/resources/logback.xml
index 3f8f9d8f..db910fdd 100644
--- a/eladmin-system/src/main/resources/logback.xml
+++ b/eladmin-system/src/main/resources/logback.xml
@@ -16,30 +16,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
diff --git a/eladmin-system/src/main/resources/spy.properties b/eladmin-system/src/main/resources/spy.properties
new file mode 100644
index 00000000..7b60caf6
--- /dev/null
+++ b/eladmin-system/src/main/resources/spy.properties
@@ -0,0 +1,29 @@
+# 应用的拦截模块
+modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
+
+# 自定义日志打印
+logMessageFormat=me.zhengjie.config.CustomP6SpyLogger
+
+# 日志输出到控制台
+appender=com.p6spy.engine.spy.appender.Slf4JLogger
+
+# 日期格式
+dateformat=yyyy-MM-dd HH:mm:ss
+
+# 实际驱动可多个
+driverlist=com.mysql.cj.jdbc.Driver
+
+# 是否开启慢SQL记录
+outagedetection=true
+
+# 慢SQL记录标准 2 秒
+outagedetectioninterval=2
+
+# 是否过滤 Log
+filter=true
+
+# 过滤 Log 时所排除的 sql 关键字,以逗号分隔
+exclude=select 1
+
+# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
+excludecategories=info,debug,result,commit,resultset
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 4f741d0d..f6ac3402 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,5 @@
-
+
4.0.0
me.zhengjie
@@ -32,7 +30,6 @@
UTF-8
UTF-8
1.8
- 1.16
2.9.2
1.2.83
1.2.19
@@ -98,9 +95,9 @@
- org.bgee.log4jdbc-log4j2
- log4jdbc-log4j2-jdbc4.1
- ${log4jdbc.version}
+ p6spy
+ p6spy
+ 3.9.1