Repository: alibaba/Sentinel
Pull request #1357 (2020-03-23 08:14:14)

Improve standard output content in LogBase
resolve https://github.com/alibaba/Sentinel/issues/1348

codecov-io: # [Codecov](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=h1) Report
> Merging [#1357](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=desc) into [master](https://codecov.io/gh/alibaba/Sentinel/commit/1eee2c80b42d72beaf06c9d0e3edc2f16d844c29&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `80.00%`.

[![Impacted file tree graph](https://codecov.io/gh/alibaba/Sentinel/pull/1357/graphs/tree.svg?width=650&height=150&src=pr&token=zLyT83T2P3)](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=tree)

```diff
@@             Coverage Diff              @@
##             master    #1357      +/-   ##
============================================
- Coverage     42.61%   42.57%   -0.04%     
- Complexity     1644     1645       +1     
============================================
  Files           364      364              
  Lines         10496    10496              
  Branches       1404     1404              
============================================
- Hits           4473     4469       -4     
- Misses         5465     5468       +3     
- Partials        558      559       +1     
```


| [Impacted Files](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
|---|---|---|---|
| [...ain/java/com/alibaba/csp/sentinel/log/LogBase.java](https://codecov.io/gh/alibaba/Sentinel/pull/1357/diff?src=pr&el=tree#diff-c2VudGluZWwtY29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2NzcC9zZW50aW5lbC9sb2cvTG9nQmFzZS5qYXZh) | `69.44% <80.00%> (ø)` | `8.00 <0.00> (ø)` | |
| [...p/sentinel/datasource/consul/ConsulDataSource.java](https://codecov.io/gh/alibaba/Sentinel/pull/1357/diff?src=pr&el=tree#diff-c2VudGluZWwtZXh0ZW5zaW9uL3NlbnRpbmVsLWRhdGFzb3VyY2UtY29uc3VsL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvY3NwL3NlbnRpbmVsL2RhdGFzb3VyY2UvY29uc3VsL0NvbnN1bERhdGFTb3VyY2UuamF2YQ==) | `63.76% <0.00%> (-5.80%)` | `7.00% <0.00%> (ø%)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=footer). Last update [1eee2c8...e879cca](https://codecov.io/gh/alibaba/Sentinel/pull/1357?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pom.xml b/pom.xml
index 2d80de93..c9936615 100755
--- a/pom.xml
+++ b/pom.xml
@@ -42,10 +42,11 @@
     <properties>
         <!-- Compile libs -->
         <fastjson.version>1.2.62</fastjson.version>
+        <javax.annotation-api.version>1.3.2</javax.annotation-api.version>
 
         <!-- Test libs -->
         <junit.version>4.12</junit.version>
-        <mockito.version>2.21.0</mockito.version>
+        <mockito.version>2.28.2</mockito.version>
         <assertj.version>3.12.1</assertj.version>
         <awaitility.version>3.1.5</awaitility.version>
         <powermock.version>2.0.0</powermock.version>
@@ -76,6 +77,7 @@
         <module>sentinel-demo</module>
         <module>sentinel-benchmark</module>
         <module>sentinel-cluster</module>
+        <module>sentinel-logging</module>
     </modules>
 
     <dependencyManagement>
diff --git a/sentinel-adapter/sentinel-grpc-adapter/pom.xml b/sentinel-adapter/sentinel-grpc-adapter/pom.xml
index 7f4f9f13..05add497 100755
--- a/sentinel-adapter/sentinel-grpc-adapter/pom.xml
+++ b/sentinel-adapter/sentinel-grpc-adapter/pom.xml
@@ -43,7 +43,7 @@
         <dependency>
             <groupId>javax.annotation</groupId>
             <artifactId>javax.annotation-api</artifactId>
-            <version>1.2</version>
+            <version>${javax.annotation-api.version}</version>
         </dependency>
 
 
diff --git a/sentinel-adapter/sentinel-spring-webmvc-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/AbstractSentinelInterceptor.java b/sentinel-adapter/sentinel-spring-webmvc-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/AbstractSentinelInterceptor.java
index eab24e14..b065c54c 100644
--- a/sentinel-adapter/sentinel-spring-webmvc-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/AbstractSentinelInterceptor.java
+++ b/sentinel-adapter/sentinel-spring-webmvc-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/AbstractSentinelInterceptor.java
@@ -67,7 +67,11 @@ public abstract class AbstractSentinelInterceptor implements HandlerInterceptor
             }
             return true;
         } catch (BlockException e) {
-            handleBlockException(request, response, e);
+            try {
+                handleBlockException(request, response, e);
+            } finally {
+                ContextUtil.exit();
+            }
             return false;
         }
     }
diff --git a/sentinel-cluster/sentinel-cluster-server-envoy-rls/pom.xml b/sentinel-cluster/sentinel-cluster-server-envoy-rls/pom.xml
index 3c84641c..e967f7ab 100644
--- a/sentinel-cluster/sentinel-cluster-server-envoy-rls/pom.xml
+++ b/sentinel-cluster/sentinel-cluster-server-envoy-rls/pom.xml
@@ -35,6 +35,11 @@
             <groupId>com.alibaba.csp</groupId>
             <artifactId>sentinel-transport-simple-http</artifactId>
         </dependency>
+        <dependency>
+            <groupId>javax.annotation</groupId>
+            <artifactId>javax.annotation-api</artifactId>
+            <version>${javax.annotation-api.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>io.grpc</groupId>
diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java
index 16641ffd..091ce15e 100755
--- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java
+++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java
@@ -84,10 +84,10 @@ public class LogBase {
         if (!LOG_OUTPUT_TYPE_FILE.equalsIgnoreCase(logOutputType) && !LOG_OUTPUT_TYPE_CONSOLE.equalsIgnoreCase(logOutputType)) {
             logOutputType = LOG_OUTPUT_TYPE_FILE;
         }
-        System.out.println("INFO: log output type is: " + logOutputType);
+        System.out.println("INFO: Sentinel log output type is: " + logOutputType);
 
         logCharSet = properties.getProperty(LOG_CHARSET) == null ? logCharSet : properties.getProperty(LOG_CHARSET);
-        System.out.println("INFO: log charset is: " + logCharSet);
+        System.out.println("INFO: Sentinel log charset is: " + logCharSet);
 
 
         logBaseDir = properties.getProperty(LOG_DIR) == null ? logBaseDir : properties.getProperty(LOG_DIR);
@@ -95,14 +95,14 @@ public class LogBase {
         File dir = new File(logBaseDir);
         if (!dir.exists()) {
             if (!dir.mkdirs()) {
-                System.err.println("ERROR: create log base dir error: " + logBaseDir);
+                System.err.println("ERROR: create Sentinel log base directory error: " + logBaseDir);
             }
         }
-        System.out.println("INFO: log base dir is: " + logBaseDir);
+        System.out.println("INFO: Sentinel log base directory is: " + logBaseDir);
 
         String usePid = properties.getProperty(LOG_NAME_USE_PID);
         logNameUsePid = "true".equalsIgnoreCase(usePid);
-        System.out.println("INFO: log name use pid is: " + logNameUsePid);
+        System.out.println("INFO: Sentinel log name use pid is: " + logNameUsePid);
     }
 
 
diff --git a/sentinel-demo/sentinel-demo-zuul2-gateway/pom.xml b/sentinel-demo/sentinel-demo-zuul2-gateway/pom.xml
index 01e562a7..525a65dd 100644
--- a/sentinel-demo/sentinel-demo-zuul2-gateway/pom.xml
+++ b/sentinel-demo/sentinel-demo-zuul2-gateway/pom.xml
@@ -26,6 +26,11 @@
             <artifactId>zuul-core</artifactId>
             <version>2.1.5</version>
         </dependency>
+        <dependency>
+            <groupId>javax.annotation</groupId>
+            <artifactId>javax.annotation-api</artifactId>
+            <version>${javax.annotation-api.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.slf4j</groupId>
diff --git a/sentinel-extension/pom.xml b/sentinel-extension/pom.xml
index 6d96dcce..72bd6d92 100755
--- a/sentinel-extension/pom.xml
+++ b/sentinel-extension/pom.xml
@@ -22,7 +22,6 @@
         <module>sentinel-datasource-spring-cloud-config</module>
         <module>sentinel-datasource-consul</module>
         <module>sentinel-datasource-etcd</module>
-        <module>sentinel-logging-extension-slf4j</module>
     </modules>
 
 </project>
diff --git a/sentinel-logging/pom.xml b/sentinel-logging/pom.xml
new file mode 100755
index 00000000..c058c667
--- /dev/null
+++ b/sentinel-logging/pom.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.alibaba.csp</groupId>
+        <artifactId>sentinel-parent</artifactId>
+        <version>1.7.2-SNAPSHOT</version>
+    </parent>
+    <artifactId>sentinel-logging</artifactId>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>sentinel-logging-slf4j</module>
+    </modules>
+
+</project>
diff --git a/sentinel-extension/sentinel-logging-extension-slf4j/README.md b/sentinel-logging/sentinel-logging-slf4j/README.md
similarity index 61%
rename from sentinel-extension/sentinel-logging-extension-slf4j/README.md
rename to sentinel-logging/sentinel-logging-slf4j/README.md
index 6abf29b1..ca629721 100644
--- a/sentinel-extension/sentinel-logging-extension-slf4j/README.md
+++ b/sentinel-logging/sentinel-logging-slf4j/README.md
@@ -1,22 +1,19 @@
 # Sentinel Logging Extension SLF4J
 
-To use Sentinel Logging Extension SLF4J with Log4j2, you should add the following dependency firstly:
+To integrate logs of sentinel into your project which uses slf4j for bridge of logging you can
+simply introduce following dependency to your project:
 
 ```xml
 <dependency>
     <groupId>com.alibaba.csp</groupId>
-    <artifactId>sentinel-logging-extension-slf4j</artifactId>
-    <version>x.y.z</version>
-</dependency>
-<dependency>
-    <groupId>org.slf4j</groupId>
-    <artifactId>slf4j-api</artifactId>
-    <version>${slf4j.version}</version>
+    <artifactId>sentinel-logging-slf4j</artifactId>
+    <version>${sentinel.version}</version>
 </dependency>
 ```
-If you want to use Slf4j with Log4j2, you can add dependencies of Log4j2 and the binding about Log4j2 and SLF4J.
-Then you should provide logging configuration as specification of the logging framework. 
-And you can add Sentinel's Loggers that it name is `sentinelRecordLogger` or `sentinelCommandCenterLogger` for your needs. For example: 
+
+And if you want to control level of logging special for sentinel the loggers that sentinel uses
+are called `sentinelRecordLogger` and `sentinelCommandCenterLogger`. For example in XML configration
+coming with log4j2 implementation:
 
 ```xml
 <?xml version="1.0" encoding="UTF-8" ?>
@@ -45,5 +42,3 @@ And you can add Sentinel's Loggers that it name is `sentinelRecordLogger` or `se
     </Loggers>
 </Configuration>
 ```
-
-
diff --git a/sentinel-extension/sentinel-logging-extension-slf4j/pom.xml b/sentinel-logging/sentinel-logging-slf4j/pom.xml
similarity index 94%
rename from sentinel-extension/sentinel-logging-extension-slf4j/pom.xml
rename to sentinel-logging/sentinel-logging-slf4j/pom.xml
index 351904bd..645900a3 100644
--- a/sentinel-extension/sentinel-logging-extension-slf4j/pom.xml
+++ b/sentinel-logging/sentinel-logging-slf4j/pom.xml
@@ -3,13 +3,13 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>sentinel-parent</artifactId>
+        <artifactId>sentinel-logging</artifactId>
         <groupId>com.alibaba.csp</groupId>
         <version>1.7.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
-    <artifactId>sentinel-logging-extension-slf4j</artifactId>
+    <artifactId>sentinel-logging-slf4j</artifactId>
     <packaging>jar</packaging>
 
     <properties>
@@ -57,4 +57,4 @@
         </dependency>
 
     </dependencies>
-</project>
\ No newline at end of file
+</project>


Test patch:
diff --git a/sentinel-adapter/sentinel-spring-webmvc-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/SentinelSpringMvcIntegrationTest.java b/sentinel-adapter/sentinel-spring-webmvc-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/SentinelSpringMvcIntegrationTest.java
index f6a4b30f..f1ddb937 100644
--- a/sentinel-adapter/sentinel-spring-webmvc-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/SentinelSpringMvcIntegrationTest.java
+++ b/sentinel-adapter/sentinel-spring-webmvc-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/spring/webmvc/SentinelSpringMvcIntegrationTest.java
@@ -71,18 +71,21 @@ public class SentinelSpringMvcIntegrationTest {
         final String headerName = "S-User";
         configureRulesFor(springMvcPathVariableUrl, 0, limitOrigin);
 
+        // This will be passed since the caller is different: userB
         this.mvc.perform(get("/foo/1").accept(MediaType.TEXT_PLAIN).header(headerName, "userB"))
                 .andExpect(status().isOk())
                 .andExpect(content().string("foo 1"));
 
-        // This will be blocked and reponse json.
+        // This will be blocked since the caller is same: userA
         this.mvc.perform(
                 get("/foo/2").accept(MediaType.APPLICATION_JSON).header(headerName, limitOrigin))
                 .andExpect(status().isOk())
                 .andExpect(content().json(ResultWrapper.blocked().toJsonString()));
+
+        // This will be passed since the caller is different: ""
         this.mvc.perform(get("/foo/3").accept(MediaType.APPLICATION_JSON))
                 .andExpect(status().isOk())
-                .andExpect(content().string(ResultWrapper.blocked().toJsonString()));
+                .andExpect(content().string("foo 3"));
 
         FlowRuleManager.loadRules(null);
     }
@@ -115,7 +118,7 @@ public class SentinelSpringMvcIntegrationTest {
             assertEquals(i + 1, cn.passQps(), 0.01);
         }
 
-        // This will be blocked and reponse json.
+        // This will be blocked and response json.
         this.mvc.perform(get(url))
                 .andExpect(status().isOk())
                 .andExpect(content().string(ResultWrapper.blocked().toJsonString()));