This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 622a48e   JAV-559 Removed the log4j dependency (#459)
622a48e is described below

commit 622a48e4758f48d3f8526926f9459a933d45670c
Author: zhengyangyong <yangyong.zh...@huawei.com>
AuthorDate: Fri Dec 22 20:17:01 2017 +0800

     JAV-559 Removed the log4j dependency (#459)
    
    * Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com>
    (cherry picked from commit 26667d42d4077a3e2270e80731942ebd54be0b1d)
    Apply 0.5.x metrics patch to 0.6.0-SNAPSHOT
---
 .../output/servo/RollingMetricsFileOutput.java     |  34 +--
 .../servo/SimpleMetricsContentFormatter.java       |   2 -
 samples/bmi/calculator/pom.xml                     |  10 +-
 .../bmi/calculator/src/main/resources/log4j2.xml   | 227 +++++++++++++++++++++
 .../src/main/resources/microservice.yaml           |   7 +-
 5 files changed, 243 insertions(+), 37 deletions(-)

diff --git 
a/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/RollingMetricsFileOutput.java
 
b/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/RollingMetricsFileOutput.java
index cb2fc18..2e63439 100644
--- 
a/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/RollingMetricsFileOutput.java
+++ 
b/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/RollingMetricsFileOutput.java
@@ -17,48 +17,28 @@
 
 package io.servicecomb.foundation.metrics.output.servo;
 
-import java.nio.file.Paths;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.spi.LoggingEvent;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
-import io.servicecomb.foundation.common.utils.RollingFileAppenderExt;
 import io.servicecomb.foundation.metrics.output.MetricsFileOutput;
 
 @Component
 public class RollingMetricsFileOutput extends MetricsFileOutput {
-  private final Map<String, RollingFileAppenderExt> metricsAppenders = new 
HashMap<>();
 
-  @Autowired
+  private final Map<String, Logger> allLoggers = new ConcurrentHashMap<>();
+
   public RollingMetricsFileOutput() {
   }
 
   @Override
   public void output(Map<String, String> metrics) {
     for (String metricName : metrics.keySet()) {
-      final String fileName = String.join(".", getNamePrefix(), metricName, 
"dat");
-      RollingFileAppenderExt appender = 
metricsAppenders.computeIfAbsent(metricName, (key) -> {
-        String finalPath = Paths.get(getRollingRootFilePath(), 
fileName).toString();
-        RollingFileAppenderExt fileAppender = new RollingFileAppenderExt();
-        fileAppender.setLogPermission("rw-------");
-        fileAppender.setFile(finalPath);
-        fileAppender.setLayout(new PatternLayout("%m%n"));
-        fileAppender.setAppend(true);
-        fileAppender.setMaxFileSize(getMaxRollingFileSize());
-        fileAppender.setMaxBackupIndex(getMaxRollingFileCount());
-        fileAppender.activateOptions();
-        return fileAppender;
-      });
-
-      LoggingEvent event = new LoggingEvent(fileName, 
Logger.getLogger(fileName), Level.ALL,
-          metrics.get(metricName), null);
-      appender.append(event);
+      Logger logger = allLoggers.computeIfAbsent(metricName, l -> 
LoggerFactory.getLogger(metricName));
+      logger.error(metrics.get(metricName));
     }
   }
 }
diff --git 
a/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/SimpleMetricsContentFormatter.java
 
b/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/SimpleMetricsContentFormatter.java
index 11d816e..8c4e60a 100644
--- 
a/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/SimpleMetricsContentFormatter.java
+++ 
b/foundations/foundation-metrics/src/main/java/io/servicecomb/foundation/metrics/output/servo/SimpleMetricsContentFormatter.java
@@ -24,7 +24,6 @@ import java.util.stream.Collectors;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.StringUtils;
 
@@ -45,7 +44,6 @@ public class SimpleMetricsContentFormatter implements 
MetricsContentFormatter {
 
   private String hostName;
 
-  @Autowired
   public SimpleMetricsContentFormatter() {
     hostName = NetUtils.getHostName();
     if (StringUtils.isEmpty(hostName)) {
diff --git a/samples/bmi/calculator/pom.xml b/samples/bmi/calculator/pom.xml
index cd70aa1..ffd84f1 100644
--- a/samples/bmi/calculator/pom.xml
+++ b/samples/bmi/calculator/pom.xml
@@ -32,15 +32,19 @@
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter</artifactId>
-      
<!--Metric使用log4j输出,屏蔽掉spring-boot-starter中的log4j-over-slf4j,因为log4j-over-slf4j没有实现完整的RollingFileAppender-->
       <exclusions>
         <exclusion>
-          <groupId>org.slf4j</groupId>
-          <artifactId>log4j-over-slf4j</artifactId>
+          <groupId>org.springframework.boot</groupId>
+          <artifactId>spring-boot-starter-logging</artifactId>
         </exclusion>
       </exclusions>
     </dependency>
     <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-log4j2</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>io.servicecomb</groupId>
       <artifactId>spring-boot-starter-provider</artifactId>
     </dependency>
diff --git a/samples/bmi/calculator/src/main/resources/log4j2.xml 
b/samples/bmi/calculator/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..ac1f2a7
--- /dev/null
+++ b/samples/bmi/calculator/src/main/resources/log4j2.xml
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<configuration status="error" monitorInterval="300">
+  <Properties>
+    <!--metrics文件Rolling单文件最大大小(KB,MB,GB)-->
+    <Property name="maxFileSize">10MB</Property>
+    <!--metrics文件Rolling保存数量-->
+    <Property name="maxFileCount">10</Property>
+    <!--metrics文件存储目录-->
+    <Property 
name="filePath">./samples/bmi/calculator/target/metric/</Property>
+    <!--metrics文件名前缀-->
+    <Property name="filePrefix">bmi.calculator</Property>
+  </Properties>
+
+  <Appenders>
+    <RollingFile name="averageServiceExecutionTime" 
fileName="${filePath}${filePrefix}.averageServiceExecutionTime.dat"
+      
filePattern="${filePath}${filePrefix}.averageServiceExecutionTime-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="averageTimeInQueue" 
fileName="${filePath}${filePrefix}.averageTimeInQueue.dat"
+      filePattern="${filePath}${filePrefix}.averageTimeInQueue-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="countInQueue" 
fileName="${filePath}${filePrefix}.countInQueue.dat"
+      filePattern="${filePath}${filePrefix}.countInQueue-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="cpuLoad" fileName="${filePath}${filePrefix}.cpuLoad.dat"
+      filePattern="${filePath}${filePrefix}.cpuLoad-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="cpuRunningThreads" 
fileName="${filePath}${filePrefix}.cpuRunningThreads.dat"
+      filePattern="${filePath}${filePrefix}.cpuRunningThreads-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="heapCommit" 
fileName="${filePath}${filePrefix}.heapCommit.dat"
+      filePattern="${filePath}${filePrefix}.heapCommit-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="heapInit" 
fileName="${filePath}${filePrefix}.heapInit.dat"
+      filePattern="${filePath}${filePrefix}.heapInit-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="heapMax" fileName="${filePath}${filePrefix}.heapMax.dat"
+      filePattern="${filePath}${filePrefix}.heapMax-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="heapUsed" 
fileName="${filePath}${filePrefix}.heapUsed.dat"
+      filePattern="${filePath}${filePrefix}.heapUsed-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="latency" fileName="${filePath}${filePrefix}.latency.dat"
+      filePattern="${filePath}${filePrefix}.latency-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="maxLifeTimeInQueue" 
fileName="${filePath}${filePrefix}.maxLifeTimeInQueue.dat"
+      filePattern="${filePath}${filePrefix}.maxLifeTimeInQueue-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="minLifeTimeInQueue" 
fileName="${filePath}${filePrefix}.minLifeTimeInQueue.dat"
+      filePattern="${filePath}${filePrefix}.minLifeTimeInQueue-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="nonHeapCommit" 
fileName="${filePath}${filePrefix}.nonHeapCommit.dat"
+      filePattern="${filePath}${filePrefix}.nonHeapCommit-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="nonHeapInit" 
fileName="${filePath}${filePrefix}.nonHeapInit.dat"
+      filePattern="${filePath}${filePrefix}.nonHeapInit-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="nonHeapMax" 
fileName="${filePath}${filePrefix}.nonHeapMax.dat"
+      filePattern="${filePath}${filePrefix}.nonHeapMax-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="nonHeapUsed" 
fileName="${filePath}${filePrefix}.nonHeapUsed.dat"
+      filePattern="${filePath}${filePrefix}.nonHeapUsed-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="totalFailedRequestsPerProvider"
+      fileName="${filePath}${filePrefix}.totalFailedRequestsPerProvider.dat"
+      
filePattern="${filePath}${filePrefix}.totalFailedRequestsPerProvider-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="totalFailRequestsPerConsumer"
+      fileName="${filePath}${filePrefix}.totalFailRequestsPerConsumer.dat"
+      
filePattern="${filePath}${filePrefix}.totalFailRequestsPerConsumer-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="totalRequestsPerConsumer" 
fileName="${filePath}${filePrefix}.totalRequestsPerConsumer.dat"
+      filePattern="${filePath}${filePrefix}.totalRequestsPerConsumer-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="totalRequestsPerProvider" 
fileName="${filePath}${filePrefix}.totalRequestsPerProvider.dat"
+      filePattern="${filePath}${filePrefix}.totalRequestsPerProvider-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+    <RollingFile name="tps" fileName="${filePath}${filePrefix}.tps.dat"
+      filePattern="${filePath}${filePrefix}.tps-%i.dat">
+      <PatternLayout pattern="%m%n"/>
+      <SizeBasedTriggeringPolicy size="${maxFileSize}"/>
+      <DefaultRolloverStrategy max="${maxFileCount}"/>
+    </RollingFile>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="averageServiceExecutionTime" level="error" 
additivity="false">
+      <AppenderRef ref="averageServiceExecutionTime"/>
+    </Logger>
+    <Logger name="averageTimeInQueue" level="error" additivity="false">
+      <AppenderRef ref="averageTimeInQueue"/>
+    </Logger>
+    <Logger name="countInQueue" level="error" additivity="false">
+      <AppenderRef ref="countInQueue"/>
+    </Logger>
+    <Logger name="cpuLoad" level="error" additivity="false">
+      <AppenderRef ref="cpuLoad"/>
+    </Logger>
+    <Logger name="cpuRunningThreads" level="error" additivity="false">
+      <AppenderRef ref="cpuRunningThreads"/>
+    </Logger>
+    <Logger name="heapCommit" level="error" additivity="false">
+      <AppenderRef ref="heapCommit"/>
+    </Logger>
+    <Logger name="heapInit" level="error" additivity="false">
+      <AppenderRef ref="heapInit"/>
+    </Logger>
+    <Logger name="heapMax" level="error" additivity="false">
+      <AppenderRef ref="heapMax"/>
+    </Logger>
+    <Logger name="heapUsed" level="error" additivity="false">
+      <AppenderRef ref="heapUsed"/>
+    </Logger>
+    <Logger name="latency" level="error" additivity="false">
+      <AppenderRef ref="latency"/>
+    </Logger>
+    <Logger name="maxLifeTimeInQueue" level="error" additivity="false">
+      <AppenderRef ref="maxLifeTimeInQueue"/>
+    </Logger>
+    <Logger name="minLifeTimeInQueue" level="error" additivity="false">
+      <AppenderRef ref="minLifeTimeInQueue"/>
+    </Logger>
+    <Logger name="nonHeapCommit" level="error" additivity="false">
+      <AppenderRef ref="nonHeapCommit"/>
+    </Logger>
+    <Logger name="nonHeapInit" level="error" additivity="false">
+      <AppenderRef ref="nonHeapInit"/>
+    </Logger>
+    <Logger name="nonHeapMax" level="error" additivity="false">
+      <AppenderRef ref="nonHeapMax"/>
+    </Logger>
+    <Logger name="nonHeapUsed" level="error" additivity="false">
+      <AppenderRef ref="nonHeapUsed"/>
+    </Logger>
+    <Logger name="totalFailedRequestsPerProvider" level="error" 
additivity="false">
+      <AppenderRef ref="totalFailedRequestsPerProvider"/>
+    </Logger>
+    <Logger name="totalFailRequestsPerConsumer" level="error" 
additivity="false">
+      <AppenderRef ref="totalFailRequestsPerConsumer"/>
+    </Logger>
+    <Logger name="totalRequestsPerConsumer" level="error" additivity="false">
+      <AppenderRef ref="totalRequestsPerConsumer"/>
+    </Logger>
+    <Logger name="totalRequestsPerProvider" level="error" additivity="false">
+      <AppenderRef ref="totalRequestsPerProvider"/>
+    </Logger>
+    <Logger name="tps" level="error" additivity="false">
+      <AppenderRef ref="tps"/>
+    </Logger>
+  </Loggers>
+</configuration>
\ No newline at end of file
diff --git a/samples/bmi/calculator/src/main/resources/microservice.yaml 
b/samples/bmi/calculator/src/main/resources/microservice.yaml
index aae0f15..8069b46 100644
--- a/samples/bmi/calculator/src/main/resources/microservice.yaml
+++ b/samples/bmi/calculator/src/main/resources/microservice.yaml
@@ -1,3 +1,4 @@
+#
 ## ---------------------------------------------------------------------------
 ## Licensed to the Apache Software Foundation (ASF) under one or more
 ## contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +16,6 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-
 # all interconnected microservices must belong to an application wth the same 
ID
 APPLICATION_ID: bmi
 service_description:
@@ -41,8 +41,5 @@ servicecomb:
     round_places: 1
     file:
       enabled: true
-      root_path: D:/Temp
       #metrics file name prefix setting,default value is "metrics"
-      name_prefix: bmi.calculator
-      max_rolling_size: 10MB
-      max_rolling_count: 10
+      name_prefix: bmi.calculator
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <commits@servicecomb.apache.org>'].

Reply via email to