rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ding...@apache.org
Subject [rocketmq] branch develop updated: Delay plant log appender in client loggger (#1266)
Date Tue, 18 Jun 2019 09:51:49 GMT
This is an automated email from the ASF dual-hosted git repository.

dinglei pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new ea88c4b  Delay plant log appender in client loggger (#1266)
ea88c4b is described below

commit ea88c4b73fc0d80007dbe93ff7ef0f5b730d8290
Author: dinglei <libya_003@163.com>
AuthorDate: Tue Jun 18 17:51:43 2019 +0800

    Delay plant log appender in client loggger (#1266)
---
 .../apache/rocketmq/client/log/ClientLogger.java   | 35 +++++++++++++++++-----
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java
index c62b385..b40f6a5 100644
--- a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java
+++ b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java
@@ -25,6 +25,7 @@ import org.apache.rocketmq.logging.inner.Layout;
 import org.apache.rocketmq.logging.inner.Level;
 import org.apache.rocketmq.logging.inner.Logger;
 import org.apache.rocketmq.logging.inner.LoggingBuilder;
+import org.apache.rocketmq.logging.inner.LoggingEvent;
 import org.apache.rocketmq.remoting.common.RemotingHelper;
 
 public class ClientLogger {
@@ -43,7 +44,7 @@ public class ClientLogger {
 
     private static final boolean CLIENT_USE_SLF4J;
 
-    private static Appender rocketmqClientAppender = null;
+    //private static Appender rocketmqClientAppender = null;
 
     static {
         CLIENT_USE_SLF4J = Boolean.parseBoolean(System.getProperty(CLIENT_LOG_USESLF4J, "false"));
@@ -57,7 +58,7 @@ public class ClientLogger {
         }
     }
 
-    private static synchronized void createClientAppender() {
+    private static synchronized Appender createClientAppender() {
         String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home")
+ "/logs/rocketmqlogs");
         String clientLogMaxIndex = System.getProperty(CLIENT_LOG_MAXINDEX, "10");
         String clientLogFileName = System.getProperty(CLIENT_LOG_FILENAME, "rocketmq_client.log");
@@ -71,11 +72,12 @@ public class ClientLogger {
 
         Layout layout = LoggingBuilder.newLayoutBuilder().withDefaultLayout().build();
 
-        rocketmqClientAppender = LoggingBuilder.newAppenderBuilder()
+        Appender rocketmqClientAppender = LoggingBuilder.newAppenderBuilder()
             .withRollingFileAppender(logFileName, maxFileSize, maxFileIndex)
             .withAsync(false, queueSize).withName(ROCKETMQ_CLIENT_APPENDER_NAME).withLayout(layout).build();
 
         Logger.getRootLogger().addAppender(rocketmqClientAppender);
+        return rocketmqClientAppender;
     }
 
     private static InternalLogger createLogger(final String loggerName) {
@@ -85,11 +87,11 @@ public class ClientLogger {
         InnerLoggerFactory.InnerLogger innerLogger = (InnerLoggerFactory.InnerLogger) logger;
         Logger realLogger = innerLogger.getLogger();
 
-        if (rocketmqClientAppender == null) {
-            createClientAppender();
-        }
+        //if (rocketmqClientAppender == null) {
+        //   createClientAppender();
+        //}
 
-        realLogger.addAppender(rocketmqClientAppender);
+        realLogger.addAppender(new AppenderProxy());
         realLogger.setLevel(Level.toLevel(clientLogLevel));
         realLogger.setAdditivity(additive);
         return logger;
@@ -98,4 +100,23 @@ public class ClientLogger {
     public static InternalLogger getLog() {
         return CLIENT_LOGGER;
     }
+
+    static class AppenderProxy extends Appender {
+        private Appender proxy;
+
+        @Override
+        protected void append(LoggingEvent event) {
+            if (null == proxy) {
+                proxy = ClientLogger.createClientAppender();
+            }
+            proxy.doAppend(event);
+        }
+
+        @Override
+        public void close() {
+            if (null != proxy) {
+                proxy.close();
+            }
+        }
+    }
 }


Mime
View raw message