release: sql输出

release-2024-04-25
huangyw 3 months ago
parent 5073c129d9
commit f369e648e3

@ -0,0 +1,47 @@
package com.luoo.user.config;
/**
* @program: luoo_parent
* @description:
* @author: yawei.huang
* @create: 2024-09-04 10:02
**/
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import java.text.SimpleDateFormat;
import java.util.Date;
public class P6SpyLogger implements MessageFormattingStrategy {
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
/**
* sql
*
* @param connectionId
* @param now
* @param elapsed ms
* @param category statement
* @param prepared sql
* @param sql sql
* @param s4 url
* @return {@link String}
*/
@Override
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String s4) {
System.out.println();
if (!"".equals(sql.trim())) {
String sqlBegin = "============== SQL LOGGER BEGIN ==============";
String sqlExecuteTime = "SQL 执行时间 :" + this.format.format(new Date()) + "\n";
String elapsedStr = "SQL 执行毫秒 :" + elapsed + "ms" + "\n";
String sqlPrint = "SQL 执行语句 :" + sql;
//String sqlPrint = !"".equals(sql.trim()) ? this.format.format(new Date()) + " | took " + elapsed + "ms | " + category + " | connection " + connectionId + "\n " + sql + ";" : "";
String sqlEnd = "============== SQL LOGGER END ==============";
return sqlBegin + "\r\n" + sqlExecuteTime + elapsedStr + sqlPrint + "\r\n" + sqlEnd;
}
return "";
}
}

@ -0,0 +1,10 @@
module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory
appender=com.p6spy.engine.spy.appender.StdoutLogger
excludecategories=info,debug,result,batc,resultset
deregisterdrivers=true
dateformat=yyyy-MM-dd HH:mm:ss
outagedetection=true
outagedetectioninterval=2
#???SQL?????
logMessageFormat=com.luoo.user.config.P6SpyLogger
Loading…
Cancel
Save