mirror of
https://github.com/chillzhuang/blade-tool
synced 2025-01-09 22:45:46 +08:00
✨ 调整 sql 日志打印
This commit is contained in:
parent
8c3a3ca173
commit
a92f479733
@ -38,9 +38,4 @@ public class BladeMybatisPlusProperties {
|
||||
*/
|
||||
private boolean sqlLog = true;
|
||||
|
||||
/**
|
||||
* sql 打印正则过滤
|
||||
*/
|
||||
private List<String> sqlLogPatterns = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.mp.config.BladeMybatisPlusProperties;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
@ -32,7 +33,6 @@ import java.sql.SQLException;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 打印可执行的 sql 日志
|
||||
@ -44,15 +44,10 @@ import java.util.regex.Pattern;
|
||||
* @author L.cm
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class SqlLogFilter extends FilterEventAdapter {
|
||||
private static final SQLUtils.FormatOption FORMAT_OPTION = new SQLUtils.FormatOption(false, false);
|
||||
private final BladeMybatisPlusProperties properties;
|
||||
private final List<Pattern> sqlLogPatternList;
|
||||
|
||||
public SqlLogFilter(BladeMybatisPlusProperties properties) {
|
||||
this.properties = properties;
|
||||
this.sqlLogPatternList = properties.getSqlLogPatterns().stream().map(Pattern::compile).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void statementExecuteBefore(StatementProxy statement, String sql) {
|
||||
@ -112,12 +107,6 @@ public class SqlLogFilter extends FilterEventAdapter {
|
||||
if (StringUtils.isEmpty(sql)) {
|
||||
return;
|
||||
}
|
||||
boolean isSqlMatch = sqlLogPatternList.stream()
|
||||
.anyMatch(pattern -> pattern.matcher(sql).matches());
|
||||
if (!isSqlMatch) {
|
||||
log.debug("sql:{} not match in SqlPatternList:{}", sql, properties.getSqlLogPatterns());
|
||||
return;
|
||||
}
|
||||
int parametersSize = statement.getParametersSize();
|
||||
List<Object> parameters = new ArrayList<>(parametersSize);
|
||||
for (int i = 0; i < parametersSize; ++i) {
|
||||
|
Loading…
Reference in New Issue
Block a user