diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/ShardingDataSource.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/ShardingDataSource.java index fb63a453434d8..2b895092ebaca 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/ShardingDataSource.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/ShardingDataSource.java @@ -65,9 +65,9 @@ public ShardingDataSource(final ShardingRule shardingRule, final Properties prop private void initThreadLocalObjectContainer(final ShardingProperties shardingProperties) { if (shardingProperties.getValue(ShardingPropertiesConstant.METRICS_ENABLE)) { - long metricsMillisecondPeriod = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_MILLISECONDS_PERIOD); - String metricsPackageName = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_PACKAGE_NAME); - threadLocalObjectContainer.initItem(new MetricsContext(metricsMillisecondPeriod, metricsPackageName)); + long period = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_MILLISECONDS_PERIOD); + String loggerName = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_LOGGER_NAME); + threadLocalObjectContainer.initItem(new MetricsContext(period, loggerName)); } } diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesConstant.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesConstant.java index 2cc67ea749624..d931892e72cb1 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesConstant.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesConstant.java @@ -55,7 +55,7 @@ public enum ShardingPropertiesConstant { * 默认值: com.dangdang.ddframe.rdb.sharding.metrics *

*/ - METRICS_PACKAGE_NAME("metrics.package.name", "com.dangdang.ddframe.rdb.sharding.metrics", String.class), + METRICS_LOGGER_NAME("metrics.logger.name", "com.dangdang.ddframe.rdb.sharding.metrics", String.class), /** * 最小空闲工作线程数量. diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java index 49f0af4625e58..0c8aaa3fa3617 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java @@ -35,10 +35,10 @@ public final class MetricsContext { private final MetricRegistry metricRegistry; - public MetricsContext(final long period, final String packageName) { + public MetricsContext(final long period, final String loggerName) { metricRegistry = new MetricRegistry(); Slf4jReporter reporter = Slf4jReporter.forRegistry(metricRegistry) - .outputTo(LoggerFactory.getLogger(packageName)) + .outputTo(LoggerFactory.getLogger(loggerName)) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .withLoggingLevel(LoggingLevel.DEBUG) diff --git a/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesTest.java b/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesTest.java index 2201ef1109475..3ab9b70c6f843 100644 --- a/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesTest.java +++ b/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/api/props/ShardingPropertiesTest.java @@ -36,7 +36,7 @@ public final class ShardingPropertiesTest { public void setUp() { prop.put(ShardingPropertiesConstant.METRICS_ENABLE.getKey(), "true"); prop.put(ShardingPropertiesConstant.METRICS_MILLISECONDS_PERIOD.getKey(), "1000"); - prop.put(ShardingPropertiesConstant.METRICS_PACKAGE_NAME.getKey(), "example"); + prop.put(ShardingPropertiesConstant.METRICS_LOGGER_NAME.getKey(), "example"); prop.put(ShardingPropertiesConstant.EXECUTOR_MAX_SIZE.getKey(), "10"); shardingProperties = new ShardingProperties(prop); } @@ -46,11 +46,11 @@ public void assertGetValueForDefaultValue() { ShardingProperties shardingProperties = new ShardingProperties(new Properties()); boolean actualMetricsEnabled = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_ENABLE); long actualMetricsMillisecondsPeriod = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_MILLISECONDS_PERIOD); - String actualMetricsPackageName = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_PACKAGE_NAME); + String actualMetricsPackageName = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_LOGGER_NAME); int executorMaxSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_MAX_SIZE); assertThat(actualMetricsEnabled, is(Boolean.valueOf(ShardingPropertiesConstant.METRICS_ENABLE.getDefaultValue()))); assertThat(actualMetricsMillisecondsPeriod, is(Long.valueOf(ShardingPropertiesConstant.METRICS_MILLISECONDS_PERIOD.getDefaultValue()))); - assertThat(actualMetricsPackageName, is(ShardingPropertiesConstant.METRICS_PACKAGE_NAME.getDefaultValue())); + assertThat(actualMetricsPackageName, is(ShardingPropertiesConstant.METRICS_LOGGER_NAME.getDefaultValue())); assertThat(executorMaxSize, is(Integer.valueOf(ShardingPropertiesConstant.EXECUTOR_MAX_SIZE.getDefaultValue()))); } @@ -74,7 +74,7 @@ public void assertGetValueForLong() { @Test public void assertGetValueForString() { - String actualMetricsPackageName = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_PACKAGE_NAME); + String actualMetricsPackageName = shardingProperties.getValue(ShardingPropertiesConstant.METRICS_LOGGER_NAME); assertThat(actualMetricsPackageName, is("example")); } diff --git a/sharding-jdbc-doc/content/post/configuration.md b/sharding-jdbc-doc/content/post/configuration.md index 7714714a9a784..872c4292c536a 100644 --- a/sharding-jdbc-doc/content/post/configuration.md +++ b/sharding-jdbc-doc/content/post/configuration.md @@ -106,7 +106,7 @@ defaultTableStrategy: 默认数据表分片策略 props: 属性配置(可选) metrics.enable: 是否开启度量采集,默认值: false metrics.millisecond.period: 度量输出周期,单位: 毫秒,默认值: 30000毫秒 - metrics.package.name: 度量输出在日志中的标识名称,默认值: com.dangdang.ddframe.rdb.sharding.metrics + metrics.logger.name: 度量输出在日志中的标识名称,默认值: com.dangdang.ddframe.rdb.sharding.metrics executor.min.idle.size: 最小空闲工作线程数量,默认值: 0 executor.max.size: 最大工作线程数量,默认值: CPU核数乘2 executor.max.idle.timeout.millisecond: 工作线程空闲时超时时间,单位: 毫秒,默认值: 60000毫秒 @@ -265,7 +265,7 @@ props: 属性配置(可选) | ------------------------------------ | ------------ | ---------- | -----| ------------------------------------| | metrics.enable | 属性 | boolean | 否 | 是否开启度量采集,默认为false不开启 | | metrics.millisecond.period | 属性 | String | 否 | 度量输出周期,单位为毫秒 | -| metrics.package.name | 属性 | String | 否 | 度量输出在日志中的标识名称 | +| metrics.logger.name | 属性 | String | 否 | 度量输出在日志中的标识名称 | | executor.min.idle.size | 属性 | int | 否 | 最小空闲工作线程数量 | | executor.max.size | 属性 | int | 否 | 最大工作线程数量 | | executor.max.idle.timeout.millisecond| 属性 | int | 否 | 工作线程空闲时超时时间,默认以毫秒为单位 |