增加LogExcludeLevel功能
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -142,7 +142,8 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
sb.append(ch);
|
sb.append(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.finest(info.getType().getSimpleName() + " insert sql=" + sb.toString().replaceAll("(\r|\n)", "\\n"));
|
String debugsql = sb.toString();
|
||||||
|
if (info.isLoggable(logger, Level.FINEST, debugsql)) logger.finest(info.getType().getSimpleName() + " insert sql=" + debugsql.replaceAll("(\r|\n)", "\\n"));
|
||||||
}
|
}
|
||||||
} //打印结束
|
} //打印结束
|
||||||
return CompletableFuture.completedFuture(c);
|
return CompletableFuture.completedFuture(c);
|
||||||
@@ -190,7 +191,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
conn.setReadOnly(false);
|
conn.setReadOnly(false);
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
sql += ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit()));
|
sql += ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit()));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||||
final Statement stmt = conn.createStatement();
|
final Statement stmt = conn.createStatement();
|
||||||
int c = stmt.executeUpdate(sql);
|
int c = stmt.executeUpdate(sql);
|
||||||
stmt.close();
|
stmt.close();
|
||||||
@@ -251,7 +252,8 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
sb.append(ch);
|
sb.append(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.finest(info.getType().getSimpleName() + " update sql=" + sb.toString().replaceAll("(\r|\n)", "\\n"));
|
String debugsql = sb.toString();
|
||||||
|
if (info.isLoggable(logger, Level.FINEST, debugsql)) logger.finest(info.getType().getSimpleName() + " update sql=" + debugsql.replaceAll("(\r|\n)", "\\n"));
|
||||||
} //打印结束
|
} //打印结束
|
||||||
}
|
}
|
||||||
int[] pc = prestmt.executeBatch();
|
int[] pc = prestmt.executeBatch();
|
||||||
@@ -289,7 +291,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
prestmt.close();
|
prestmt.close();
|
||||||
return CompletableFuture.completedFuture(c);
|
return CompletableFuture.completedFuture(c);
|
||||||
} else {
|
} else {
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||||
final Statement stmt = conn.createStatement();
|
final Statement stmt = conn.createStatement();
|
||||||
int c = stmt.executeUpdate(sql);
|
int c = stmt.executeUpdate(sql);
|
||||||
stmt.close();
|
stmt.close();
|
||||||
@@ -453,7 +455,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
boolean rs = set.next() ? (set.getInt(1) > 0) : false;
|
boolean rs = set.next() ? (set.getInt(1) > 0) : false;
|
||||||
set.close();
|
set.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " exists (" + rs + ") sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " exists (" + rs + ") sql=" + sql);
|
||||||
return CompletableFuture.completedFuture(rs);
|
return CompletableFuture.completedFuture(rs);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (info.tableStrategy != null && info.isTableNotExist(e)) return CompletableFuture.completedFuture(false);
|
if (info.tableStrategy != null && info.isTableNotExist(e)) return CompletableFuture.completedFuture(false);
|
||||||
@@ -479,7 +481,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
if ("mysql".equals(this.readPool.getDbtype()) || "postgresql".equals(this.readPool.getDbtype())) {
|
if ("mysql".equals(this.readPool.getDbtype()) || "postgresql".equals(this.readPool.getDbtype())) {
|
||||||
final String listsql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
final String listsql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
||||||
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + createSQLOrderby(info, flipper) + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset()));
|
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + createSQLOrderby(info, flipper) + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset()));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) {
|
if (info.isLoggable(logger, Level.FINEST, listsql)) {
|
||||||
logger.finest(info.getType().getSimpleName() + " query sql=" + listsql);
|
logger.finest(info.getType().getSimpleName() + " query sql=" + listsql);
|
||||||
}
|
}
|
||||||
PreparedStatement ps = conn.prepareStatement(listsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
PreparedStatement ps = conn.prepareStatement(listsql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||||
@@ -501,7 +503,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
}
|
}
|
||||||
final String sql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
final String sql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
||||||
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + info.createSQLOrderby(flipper);
|
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + info.createSQLOrderby(flipper);
|
||||||
if (info.isLoggable(logger, Level.FINEST)) {
|
if (info.isLoggable(logger, Level.FINEST, sql)) {
|
||||||
logger.finest(info.getType().getSimpleName() + " query sql=" + sql + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset())));
|
logger.finest(info.getType().getSimpleName() + " query sql=" + sql + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset())));
|
||||||
}
|
}
|
||||||
conn.setReadOnly(true);
|
conn.setReadOnly(true);
|
||||||
|
|||||||
@@ -479,7 +479,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
sql += FilterNode.formatToString(ids[i]);
|
sql += FilterNode.formatToString(ids[i]);
|
||||||
}
|
}
|
||||||
sql += ")";
|
sql += ")";
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||||
return deleteDB(info, null, sql);
|
return deleteDB(info, null, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,7 +498,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
String sql = "DELETE " + ("mysql".equals(this.readPool.getDbtype()) ? "a" : "") + " FROM " + info.getTable(node) + " a" + (join1 == null ? "" : (", " + join1))
|
String sql = "DELETE " + ("mysql".equals(this.readPool.getDbtype()) ? "a" : "") + " FROM " + info.getTable(node) + " a" + (join1 == null ? "" : (", " + join1))
|
||||||
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
||||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))) + info.createSQLOrderby(flipper);
|
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))) + info.createSQLOrderby(flipper);
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql="
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " delete sql="
|
||||||
+ (sql + ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit()))));
|
+ (sql + ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit()))));
|
||||||
return deleteDB(info, flipper, sql);
|
return deleteDB(info, flipper, sql);
|
||||||
}
|
}
|
||||||
@@ -1205,7 +1205,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
}
|
}
|
||||||
final String sql = "SELECT " + sb + " FROM " + info.getTable(node) + " a"
|
final String sql = "SELECT " + sb + " FROM " + info.getTable(node) + " a"
|
||||||
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " getnumbermap sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " getnumbermap sql=" + sql);
|
||||||
return getNumberMapDB(info, sql, columns);
|
return getNumberMapDB(info, sql, columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1292,7 +1292,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||||
final String sql = "SELECT " + func.getColumn((column == null || column.isEmpty() ? "*" : info.getSQLColumn("a", column))) + " FROM " + info.getTable(node) + " a"
|
final String sql = "SELECT " + func.getColumn((column == null || column.isEmpty() ? "*" : info.getSQLColumn("a", column))) + " FROM " + info.getTable(node) + " a"
|
||||||
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(entityClass.getSimpleName() + " getnumberresult sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(entityClass.getSimpleName() + " getnumberresult sql=" + sql);
|
||||||
return getNumberResultDB(info, sql, defVal, column);
|
return getNumberResultDB(info, sql, defVal, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1350,7 +1350,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||||
final String sql = "SELECT a." + sqlkey + ", " + func.getColumn((funcColumn == null || funcColumn.isEmpty() ? "*" : info.getSQLColumn("a", funcColumn)))
|
final String sql = "SELECT a." + sqlkey + ", " + func.getColumn((funcColumn == null || funcColumn.isEmpty() ? "*" : info.getSQLColumn("a", funcColumn)))
|
||||||
+ " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + " GROUP BY a." + sqlkey;
|
+ " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + " GROUP BY a." + sqlkey;
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " querycolumnmap sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " querycolumnmap sql=" + sql);
|
||||||
return queryColumnMapDB(info, sql, keyColumn);
|
return queryColumnMapDB(info, sql, keyColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1399,7 +1399,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
|
|
||||||
protected <T> CompletableFuture<T> findCompose(final EntityInfo<T> info, final SelectColumn selects, Serializable pk) {
|
protected <T> CompletableFuture<T> findCompose(final EntityInfo<T> info, final SelectColumn selects, Serializable pk) {
|
||||||
final String sql = "SELECT " + info.getQueryColumns(null, selects) + " FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
final String sql = "SELECT " + info.getQueryColumns(null, selects) + " FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
||||||
return findDB(info, sql, true, selects);
|
return findDB(info, sql, true, selects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1467,7 +1467,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
||||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||||
final String sql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
final String sql = "SELECT " + info.getQueryColumns("a", selects) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
||||||
return findDB(info, sql, false, selects);
|
return findDB(info, sql, false, selects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1536,7 +1536,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
|
|
||||||
protected <T> CompletableFuture<Serializable> findColumnCompose(final EntityInfo<T> info, String column, final Serializable defValue, final Serializable pk) {
|
protected <T> CompletableFuture<Serializable> findColumnCompose(final EntityInfo<T> info, String column, final Serializable defValue, final Serializable pk) {
|
||||||
final String sql = "SELECT " + info.getSQLColumn(null, column) + " FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
final String sql = "SELECT " + info.getSQLColumn(null, column) + " FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
||||||
return findColumnDB(info, sql, true, column, defValue);
|
return findColumnDB(info, sql, true, column, defValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1568,7 +1568,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
||||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||||
final String sql = "SELECT " + info.getSQLColumn("a", column) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
final String sql = "SELECT " + info.getSQLColumn("a", column) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " find sql=" + sql);
|
||||||
return findColumnDB(info, sql, false, column, defValue);
|
return findColumnDB(info, sql, false, column, defValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1598,7 +1598,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
|
|
||||||
protected <T> CompletableFuture<Boolean> existsCompose(final EntityInfo<T> info, Serializable pk) {
|
protected <T> CompletableFuture<Boolean> existsCompose(final EntityInfo<T> info, Serializable pk) {
|
||||||
final String sql = "SELECT COUNT(*) FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
final String sql = "SELECT COUNT(*) FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " exists sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " exists sql=" + sql);
|
||||||
return existsDB(info, sql, true);
|
return existsDB(info, sql, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1640,7 +1640,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
||||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||||
final String sql = "SELECT COUNT(" + info.getPrimarySQLColumn("a") + ") FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
final String sql = "SELECT COUNT(" + info.getPrimarySQLColumn("a") + ") FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " exists sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " exists sql=" + sql);
|
||||||
return existsDB(info, sql, false);
|
return existsDB(info, sql, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2173,7 +2173,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
final EntityCache<T> cache = info.getCache();
|
final EntityCache<T> cache = info.getCache();
|
||||||
if (readcache && cache != null && cache.isFullLoaded()) {
|
if (readcache && cache != null && cache.isFullLoaded()) {
|
||||||
if (node == null || node.isCacheUseable(this)) {
|
if (node == null || node.isCacheUseable(this)) {
|
||||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(clazz.getSimpleName() + " cache query predicate = " + (node == null ? null : node.createPredicate(cache)));
|
if (info.isLoggable(logger, Level.FINEST, " cache query predicate = ")) logger.finest(clazz.getSimpleName() + " cache query predicate = " + (node == null ? null : node.createPredicate(cache)));
|
||||||
return CompletableFuture.completedFuture(cache.querySheet(needtotal, selects, flipper, node));
|
return CompletableFuture.completedFuture(cache.querySheet(needtotal, selects, flipper, node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,9 @@ public final class EntityInfo<T> {
|
|||||||
//日志级别,从LogLevel获取
|
//日志级别,从LogLevel获取
|
||||||
private final int logLevel;
|
private final int logLevel;
|
||||||
|
|
||||||
|
//日志控制
|
||||||
|
private final Map<Integer, String[]> excludeLogLevels;
|
||||||
|
|
||||||
//Flipper.sort转换成以ORDER BY开头SQL的缓存
|
//Flipper.sort转换成以ORDER BY开头SQL的缓存
|
||||||
private final Map<String, String> sortOrderbySqls = new ConcurrentHashMap<>();
|
private final Map<String, String> sortOrderbySqls = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@@ -210,6 +213,26 @@ public final class EntityInfo<T> {
|
|||||||
|
|
||||||
LogLevel ll = type.getAnnotation(LogLevel.class);
|
LogLevel ll = type.getAnnotation(LogLevel.class);
|
||||||
this.logLevel = ll == null ? Integer.MIN_VALUE : Level.parse(ll.value()).intValue();
|
this.logLevel = ll == null ? Integer.MIN_VALUE : Level.parse(ll.value()).intValue();
|
||||||
|
Map<Integer, HashSet<String>> logmap = new HashMap<>();
|
||||||
|
for (LogExcludeLevel lel : type.getAnnotationsByType(LogExcludeLevel.class)) {
|
||||||
|
for (String onelevel : lel.levels()) {
|
||||||
|
int level = Level.parse(onelevel).intValue();
|
||||||
|
HashSet<String> set = logmap.get(level);
|
||||||
|
if (set == null) {
|
||||||
|
set = new HashSet<>();
|
||||||
|
logmap.put(level, set);
|
||||||
|
}
|
||||||
|
for (String key : lel.keys()) {
|
||||||
|
set.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (logmap.isEmpty()) {
|
||||||
|
this.excludeLogLevels = null;
|
||||||
|
} else {
|
||||||
|
this.excludeLogLevels = new HashMap<>();
|
||||||
|
logmap.forEach((l, set) -> excludeLogLevels.put(l, set.toArray(new String[set.size()])));
|
||||||
|
}
|
||||||
//---------------------------------------------
|
//---------------------------------------------
|
||||||
Table t = type.getAnnotation(Table.class);
|
Table t = type.getAnnotation(Table.class);
|
||||||
if (type.getAnnotation(VirtualEntity.class) != null) {
|
if (type.getAnnotation(VirtualEntity.class) != null) {
|
||||||
@@ -874,6 +897,26 @@ public final class EntityInfo<T> {
|
|||||||
return logger.isLoggable(l) && l.intValue() >= this.logLevel;
|
return logger.isLoggable(l) && l.intValue() >= this.logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断日志级别
|
||||||
|
*
|
||||||
|
* @param logger Logger
|
||||||
|
* @param l Level
|
||||||
|
* @param str String
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isLoggable(Logger logger, Level l, String str) {
|
||||||
|
boolean rs = logger.isLoggable(l) && l.intValue() >= this.logLevel;
|
||||||
|
if (this.excludeLogLevels == null || !rs || str == null) return rs;
|
||||||
|
String[] keys = this.excludeLogLevels.get(l.intValue());
|
||||||
|
if (keys == null) return rs;
|
||||||
|
for (String key : keys) {
|
||||||
|
if (str.contains(key)) return false;
|
||||||
|
}
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将字段值序列化为可SQL的字符串
|
* 将字段值序列化为可SQL的字符串
|
||||||
*
|
*
|
||||||
|
|||||||
46
src/org/redkale/util/LogExcludeLevel.java
Normal file
46
src/org/redkale/util/LogExcludeLevel.java
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.redkale.util;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等于level日志级别且包含keys字符串的日志才会被排除 <br>
|
||||||
|
*
|
||||||
|
* <blockquote><pre>
|
||||||
|
* @LogExcludeLevel(levels = {"FINEST"}, keys = {"SET username ="})
|
||||||
|
* public class UserRecord {
|
||||||
|
* public int userid;
|
||||||
|
* public String username = "";
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* 这样当调用DataSource对UserRecord对象进行操作时,拼接的SQL语句含"SET username ="字样的都会在FINEST日志级别过滤掉
|
||||||
|
* </pre></blockquote>
|
||||||
|
* <p>
|
||||||
|
* 详情见: https://redkale.org
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Target({TYPE})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Repeatable(LogExcludeLevel.LogExcludeLevels.class)
|
||||||
|
public @interface LogExcludeLevel {
|
||||||
|
|
||||||
|
String[] levels();
|
||||||
|
|
||||||
|
String[] keys();
|
||||||
|
|
||||||
|
@Documented
|
||||||
|
@Target({TYPE})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@interface LogExcludeLevels {
|
||||||
|
|
||||||
|
LogExcludeLevel[] value();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user