fix:打印sql
This commit is contained in:
parent
a7b7836523
commit
659b8c12e1
17
pom.xml
17
pom.xml
|
|
@ -41,6 +41,8 @@
|
|||
<minio.version>8.2.2</minio.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<commons-collections.version>3.2.2</commons-collections.version>
|
||||
<p6spy.version>3.9.1</p6spy.version>
|
||||
<fusesource.jansi.version>2.4.0</fusesource.jansi.version>
|
||||
<transmittable-thread-local.version>2.12.2</transmittable-thread-local.version>
|
||||
</properties>
|
||||
|
||||
|
|
@ -262,6 +264,21 @@
|
|||
<version>${ruoyi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志分析打印 -->
|
||||
<dependency>
|
||||
<groupId>p6spy</groupId>
|
||||
<artifactId>p6spy</artifactId>
|
||||
<version>${p6spy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志打印彩色 -->
|
||||
<dependency>
|
||||
<groupId>org.fusesource.jansi</groupId>
|
||||
<artifactId>jansi</artifactId>
|
||||
<version>${fusesource.jansi.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,10 @@ public class jasyptEncryptUtils {
|
|||
final static String SUFFIX = "]";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// p6spy损耗性能 生产不使用
|
||||
HashMap<String, String> dataSource = MapUtil.newHashMap();
|
||||
dataSource.put("url","jdbc:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||
dataSource.put("p6spyurl","jdbc:p6spy:mysql://175.178.38.240:9033/ry_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||
dataSource.put("username","nacos");
|
||||
dataSource.put("password","nacos2233");
|
||||
|
||||
|
|
@ -53,6 +55,7 @@ public class jasyptEncryptUtils {
|
|||
public static void decryptDataSource(Map<String,String> dataSource){
|
||||
String key = AESMybatisPlusUtils.genOrGetKey();
|
||||
String url = decryptPwd(key,dataSource.get("url"));
|
||||
String p6spyurl = decryptPwd(key,dataSource.get("p6spyurl"));
|
||||
String username = decryptPwd(key,dataSource.get("username"));
|
||||
String password = decryptPwd(key,dataSource.get("password"));
|
||||
|
||||
|
|
@ -60,6 +63,7 @@ public class jasyptEncryptUtils {
|
|||
FileWriter writer = new FileWriter(new File(FILE_PATCH_DE), CHARSET_UTF8);
|
||||
writer.write("key: "+ key + LINE,false);
|
||||
writer.write("url: " +url + LINE,true);
|
||||
writer.write("p6spyurl: " + PREFIX +p6spyurl + SUFFIX + LINE,true);
|
||||
writer.write("username: " +username + LINE,true);
|
||||
writer.write("password: " +password + LINE,true);
|
||||
}
|
||||
|
|
@ -71,12 +75,14 @@ public class jasyptEncryptUtils {
|
|||
public static void encryptionDataSource(Map<String,String> dataSource){
|
||||
String key = AESMybatisPlusUtils.genOrGetKey();
|
||||
String url = encryptPwd(key,dataSource.get("url"));
|
||||
String p6spyurl = encryptPwd(key,dataSource.get("p6spyurl"));
|
||||
String username = encryptPwd(key,dataSource.get("username"));
|
||||
String password = encryptPwd(key,dataSource.get("password"));
|
||||
//保存在目录下
|
||||
FileWriter writer = new FileWriter(new File(FILE_PATCH_ALL), CHARSET_UTF8);
|
||||
writer.write("key: "+ key + LINE,false);
|
||||
writer.write("url: " + PREFIX +url + SUFFIX + LINE,true);
|
||||
writer.write("p6spyurl: " + PREFIX +p6spyurl + SUFFIX + LINE,true);
|
||||
writer.write("username: " + PREFIX +username + SUFFIX + LINE,true);
|
||||
writer.write("password: " + PREFIX +password + SUFFIX + LINE,true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
key: aa78fcbe21d77af8
|
||||
url: PINN@[b43OeNppIVyLnbWEybBFR7ilgcIOkQz5Mkb2tWtOuugrQoTxjpf3hozwU8LRSpboCAOf4WSAB9eknmbS15qX42/e6g1XmmJCsSAwx3TswOjX9x6BgjcDiWrUcYx4ZiNS9wO79ieCkLdeWRW1AZ6msuFV0JGRQNMpsLaJjwra2BZ4Hldq88EDjyZntBvT2s58EXM/bjMKIQhynkUibEbAhw==]
|
||||
username: PINN@[WEciwJ1eT6ZjAMncoppuow==]
|
||||
password: PINN@[YZXfQ+pMtdFaMCxbKy5ey5BfxIG2RQnZ]
|
||||
url: PINN@[DeBx+L2NxMoLVRK5aFJal930HSNKNRDjyw8k9SfphiNauMBtB0BVeigeVoA4zncZl8KklrjYq6r7yvnGN/54eCZSa+/ZisvGO8LLywPKP9XXEPs0Ar4cMvX3EDMDgJsitmOUNID4VD7a4tBOEXituKYdBt2d97etv3F2SV6PUALj7i11qqI0sPWmgLcRohpWdZ8heJAmZcRKNGySQLpwWQ==]
|
||||
p6spyurl: PINN@[wwmRkyryca6C99kAK/fCHtJBxYLY++/PKLOLI/ZDZ1v1+2G9qIqtc3jN/WTBbj0vAoITV16e/f/NQ19hu970+zGfVMN37bB0kDfNQ8Jc5qDH0OOfFR1MGL231clxmCUe4TNSyIHh4ti+IiAnaeUPXNWJAxxd/oWQeaKw96GT9F9UlF0upolfNwhhigeQpFLWEC5l6k9B7/2sNAscxoeBQoQEnl8ON7rR]
|
||||
username: PINN@[cftYM6QehEHfdIe8DCLqxw==]
|
||||
password: PINN@[Yf+zXisp7902VzH2hoHqyvJD5GINf7Xh]
|
||||
|
|
|
|||
|
|
@ -23,5 +23,17 @@
|
|||
<artifactId>ruoyi-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志分析打印 -->
|
||||
<dependency>
|
||||
<groupId>p6spy</groupId>
|
||||
<artifactId>p6spy</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志打印彩色 -->
|
||||
<dependency>
|
||||
<groupId>org.fusesource.jansi</groupId>
|
||||
<artifactId>jansi</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.ruoyi.common.log.p6spy;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
|
||||
|
||||
/**
|
||||
* P6spy SQL 打印策略
|
||||
*
|
||||
* @author hubin
|
||||
* @since 2019-02-20
|
||||
*/
|
||||
public class P6SpyLogger implements MessageFormattingStrategy {
|
||||
|
||||
@Override
|
||||
public String formatMessage(int connectionId, String now, long elapsed, String category,
|
||||
String prepared, String sql, String url) {
|
||||
return StringUtils.isNotBlank(sql)
|
||||
?
|
||||
"\n Consume Time:"
|
||||
+ elapsed +
|
||||
" ms "
|
||||
+ now +
|
||||
"\n Execute SQL:"
|
||||
+"\n\t\t"+ sql.replaceAll("[\\s]+", " ")
|
||||
+ "\n Execution Result ↓↓↓"
|
||||
:
|
||||
"Not Sql Info \n";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.ruoyi.common.log.p6spy;
|
||||
|
||||
import com.ruoyi.common.log.aspect.LogAspect;
|
||||
import com.ruoyi.common.log.utils.JansiUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 输出 SQL 日志
|
||||
*
|
||||
* @author hubin
|
||||
* @since 2019-02-20
|
||||
*/
|
||||
public class StdoutLogger extends com.p6spy.engine.spy.appender.StdoutLogger {
|
||||
@Override
|
||||
public void logText(String text) {
|
||||
JansiUtils.info(text);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package com.ruoyi.common.log.utils;
|
||||
|
||||
import com.ruoyi.common.log.aspect.LogAspect;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.fusesource.jansi.Ansi.*;
|
||||
import static org.fusesource.jansi.Ansi.Color.*;
|
||||
|
||||
public class JansiUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
|
||||
|
||||
public static void info(String text){
|
||||
info(text,null);
|
||||
}
|
||||
public static void debug(String text){
|
||||
debug(text,null);
|
||||
}
|
||||
public static void warn(String text){
|
||||
warn(text,null);
|
||||
}
|
||||
public static void err(String text){
|
||||
err(text,null);
|
||||
}
|
||||
public static void trace(String text){
|
||||
trace(text,null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void info(String text,Object o){
|
||||
setColor(BLUE);
|
||||
log.info(text,o);
|
||||
reset();
|
||||
}
|
||||
public static void debug(String text,Object o){
|
||||
setColor(GREEN);
|
||||
log.debug(text,o);
|
||||
reset();
|
||||
}
|
||||
public static void warn(String text,Object o){
|
||||
setColor(YELLOW);
|
||||
log.warn(text,o);
|
||||
reset();
|
||||
}
|
||||
public static void err(String text,Object o){
|
||||
setColor(RED);
|
||||
log.error(text,o);
|
||||
reset();
|
||||
}
|
||||
public static void trace(String text,Object o){
|
||||
setColor(CYAN);
|
||||
log.trace(text,o);
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置颜色
|
||||
* @param color
|
||||
*/
|
||||
private static void setColor(Ansi.Color color){
|
||||
System.out.print(ansi().eraseScreen().fg(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭颜色输出
|
||||
*/
|
||||
private static void reset(){
|
||||
System.out.print(ansi().eraseScreen().reset());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#3.2.1????
|
||||
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||
#3.2.1?????????
|
||||
#modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||
# ???????
|
||||
logMessageFormat=com.ruoyi.common.log.p6spy.P6SpyLogger
|
||||
#????????
|
||||
appender=com.ruoyi.common.log.p6spy.StdoutLogger
|
||||
# ???????? sql
|
||||
# appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
||||
# ?? p6spy driver ??
|
||||
deregisterdrivers=true
|
||||
# ??JDBC URL??
|
||||
useprefix=true
|
||||
# ???? Log ??,????????error,info,batch,debug,statement,commit,rollback,result,resultset.
|
||||
excludecategories=info,debug,result,commit,resultset
|
||||
# ????
|
||||
dateformat=yyyy-MM-dd HH:mm:ss
|
||||
# ???????
|
||||
#driverlist=org.h2.Driver
|
||||
# ?????SQL??
|
||||
outagedetection=true
|
||||
# ?SQL???? 2 ?
|
||||
outagedetectioninterval=2
|
||||
|
|
@ -89,6 +89,17 @@
|
|||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>p6spy</groupId>
|
||||
<artifactId>p6spy</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志打印彩色 -->
|
||||
<dependency>
|
||||
<groupId>org.fusesource.jansi</groupId>
|
||||
<artifactId>jansi</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
Loading…
Reference in New Issue