mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
make the log level configurable in StatFilter
This commit is contained in:
@@ -61,35 +61,38 @@ import com.alibaba.druid.support.profile.Profiler;
|
||||
*/
|
||||
public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(StatFilter.class);
|
||||
private final static Log LOG = LogFactory.getLog(StatFilter.class);
|
||||
|
||||
private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql";
|
||||
private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis";
|
||||
private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql";
|
||||
private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql";
|
||||
private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis";
|
||||
private static final String SYS_PROP_SLOW_SQL_LOG_LEVEL = "druid.stat.slowSqlLogLevel";
|
||||
private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql";
|
||||
|
||||
public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn";
|
||||
public final static String ATTR_TRANSACTION = "stat.tx";
|
||||
public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn";
|
||||
public final static String ATTR_TRANSACTION = "stat.tx";
|
||||
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
// protected JdbcDataSourceStat dataSourceStat;
|
||||
|
||||
@Deprecated
|
||||
protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat();
|
||||
protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat();
|
||||
|
||||
@Deprecated
|
||||
protected final JdbcResultSetStat resultSetStat = JdbcStatManager.getInstance().getResultSetStat();
|
||||
protected final JdbcResultSetStat resultSetStat = JdbcStatManager.getInstance().getResultSetStat();
|
||||
|
||||
private boolean connectionStackTraceEnable = false;
|
||||
private boolean connectionStackTraceEnable = false;
|
||||
|
||||
// 3 seconds is slow sql
|
||||
protected long slowSqlMillis = 3 * 1000;
|
||||
protected long slowSqlMillis = 3 * 1000;
|
||||
|
||||
protected boolean logSlowSql = false;
|
||||
protected boolean logSlowSql = false;
|
||||
|
||||
protected String slowSqlLogLevel = "ERROR";
|
||||
|
||||
private DbType dbType;
|
||||
|
||||
private boolean mergeSql = false;
|
||||
private boolean mergeSql = false;
|
||||
|
||||
public StatFilter(){
|
||||
}
|
||||
@@ -138,6 +141,14 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
this.mergeSql = mergeSql;
|
||||
}
|
||||
|
||||
public String getSlowSqlLogLevel() {
|
||||
return slowSqlLogLevel;
|
||||
}
|
||||
|
||||
public void setSlowSqlLogLevel(String slowSqlLogLevel) {
|
||||
this.slowSqlLogLevel = slowSqlLogLevel;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String mergeSql(String sql) {
|
||||
return this.mergeSql(sql, dbType);
|
||||
@@ -210,6 +221,19 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
this.logSlowSql = false;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
String property = properties.getProperty(SYS_PROP_SLOW_SQL_LOG_LEVEL);
|
||||
if ("error".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "ERROR";
|
||||
} else if ("warn".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "WARN";
|
||||
} else if ("info".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "INFO";
|
||||
} else if ("debug".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "DEBUG";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
|
||||
@@ -484,7 +508,20 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
String lastExecSql = statement.getLastExecuteSql();
|
||||
if (logSlowSql) {
|
||||
LOG.error("slow sql " + millis + " millis. " + lastExecSql + "" + slowParameters);
|
||||
String msg = "slow sql " + millis + " millis. " + lastExecSql + "" + slowParameters;
|
||||
switch (slowSqlLogLevel) {
|
||||
case "WARN":
|
||||
LOG.warn(msg);
|
||||
break;
|
||||
case "INFO":
|
||||
LOG.info(msg);
|
||||
break;
|
||||
case "DEBUG":
|
||||
LOG.debug(msg);
|
||||
break;
|
||||
default:
|
||||
LOG.error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
handleSlowSql(statement);
|
||||
|
||||
Reference in New Issue
Block a user