阅读更多
1 Slf4jLogFilter
Slf4jLogFilter的日志级别都是DEBUG的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| @Bean public Slf4jLogFilter logFilter() { Slf4jLogFilter filter = new Slf4jLogFilter(); filter.setDataSourceLogger(LOGGER); filter.setStatementLogger(LOGGER); filter.setConnectionLogger(LOGGER); filter.setResultSetLogger(LOGGER);
return filter; }
|
2 StatFilter
StatFilter 与 Slf4jLogFilter 无关,StatFilter有自己的Logger,即
1 2 3 4
| public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
private final static Log LOG = LogFactory.getLog(StatFilter.class); }
|
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| @Bean public StatFilter statFilter() { StatFilter statFilter = new StatFilter(); statFilter.setLogSlowSql(true); statFilter.setSlowSqlMillis(50); statFilter.setMergeSql(true); return statFilter; }
@Bean public DataSource dataSource() { DruidDataSource dataSource = new DruidDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/test"); dataSource.setUsername("liuye"); dataSource.setPassword("123456"); dataSource.setMaxActive(50); dataSource.setMaxWait(3000); dataSource.setProxyFilters(Collections.singletonList(statFilter())); return dataSource; }
|
3 参考