You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/04/28 09:37:48 UTC

[GitHub] beiwei30 closed pull request #1704: issue#1447: NettyHelper in netty extension populated Logger "InternalLogger" in netty.

beiwei30 closed pull request #1704: issue#1447: NettyHelper in netty extension populated Logger "InternalLogger" in netty.
URL: https://github.com/apache/incubator-dubbo/pull/1704
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/LoggerFactory.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/LoggerFactory.java
index 5ab42236a9..fc40fd4435 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/LoggerFactory.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/LoggerFactory.java
@@ -119,6 +119,15 @@ public static Logger getLogger(String key) {
         return logger;
     }
 
+    public static Logger getLogger(String key, boolean appendContext) {
+        FailsafeLogger logger = LOGGERS.get(key);
+        if (logger == null) {
+            LOGGERS.putIfAbsent(key, new FailsafeLogger(LOGGER_ADAPTER.getLogger(key), appendContext));
+            logger = LOGGERS.get(key);
+        }
+        return logger;
+    }
+
     /**
      * Get logging level
      *
diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/support/FailsafeLogger.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/support/FailsafeLogger.java
index f37579fbc0..22d2b2f61b 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/support/FailsafeLogger.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/logger/support/FailsafeLogger.java
@@ -23,11 +23,17 @@
 public class FailsafeLogger implements Logger {
 
     private Logger logger;
+    private boolean append = true;
 
     public FailsafeLogger(Logger logger) {
         this.logger = logger;
     }
 
+    public FailsafeLogger(Logger logger, boolean append) {
+        this.logger = logger;
+        this.append = append;
+    }
+
     public Logger getLogger() {
         return logger;
     }
@@ -37,7 +43,8 @@ public void setLogger(Logger logger) {
     }
 
     private String appendContextMessage(String msg) {
-        return " [DUBBO] " + msg + ", dubbo version: " + Version.getVersion() + ", current host: " + NetUtils.getLocalHost();
+        return append ? " [DUBBO] " + msg + ", dubbo version: " + Version.getVersion() + ", current host: " +
+                NetUtils.getLocalHost() : msg;
     }
 
     @Override
diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java
index 715aa6479d..72ecbb342a 100644
--- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java
+++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/logging/NettyHelper.java
@@ -35,7 +35,7 @@ public static void setNettyLoggerFactory() {
 
         @Override
         public InternalLogger newInstance(String name) {
-            return new DubboLogger(LoggerFactory.getLogger(name));
+            return new DubboLogger(LoggerFactory.getLogger(name, name.startsWith("com.alibaba.dubbo.")));
         }
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org