dubbo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] diecui1202 closed pull request #2272: bugfix to 1713_team7
Date Wed, 15 Aug 2018 05:56:53 GMT
diecui1202 closed pull request #2272: bugfix to 1713_team7
URL: https://github.com/apache/incubator-dubbo/pull/2272
 
 
   

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/pom.xml b/dubbo-common/pom.xml
index 72d43da6f5..ee8debe127 100644
--- a/dubbo-common/pom.xml
+++ b/dubbo-common/pom.xml
@@ -67,5 +67,14 @@
             <groupId>de.ruedigermoeller</groupId>
             <artifactId>fst</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java
index 7848224d95..987bf63af8 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/LoggerFactory.java
@@ -20,6 +20,7 @@
 import org.apache.dubbo.common.logger.jcl.JclLoggerAdapter;
 import org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter;
 import org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter;
+import org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter;
 import org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter;
 import org.apache.dubbo.common.logger.support.FailsafeLogger;
 
@@ -39,7 +40,9 @@
     // search common-used logging frameworks
     static {
         String logger = System.getProperty("dubbo.application.logger");
-        if ("slf4j".equals(logger)) {
+        if("log4j2".equals(logger)){
+            setLoggerAdapter(new Log4j2LoggerAdapter());
+        }else if ("slf4j".equals(logger)) {
             setLoggerAdapter(new Slf4jLoggerAdapter());
         } else if ("jcl".equals(logger)) {
             setLoggerAdapter(new JclLoggerAdapter());
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/log4j2/Log4j2Logger.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/log4j2/Log4j2Logger.java
new file mode 100644
index 0000000000..572e8e8bbb
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/log4j2/Log4j2Logger.java
@@ -0,0 +1,112 @@
+package org.apache.dubbo.common.logger.log4j2;
+
+import org.apache.dubbo.common.logger.Logger;
+
+public class Log4j2Logger implements Logger {
+    private final org.apache.logging.log4j.Logger logger;
+
+    public Log4j2Logger(org.apache.logging.log4j.Logger logger){
+        this.logger = logger;
+    }
+
+
+    @Override
+    public void trace(String msg) {
+        logger.trace(msg);
+    }
+
+    @Override
+    public void trace(Throwable e) {
+        logger.trace(e.getMessage());
+    }
+
+    @Override
+    public void trace(String msg, Throwable e) {
+        logger.trace(msg, e);
+    }
+
+    @Override
+    public void debug(String msg) {
+        logger.debug(msg);
+    }
+
+    @Override
+    public void debug(Throwable e) {
+        logger.debug(e);
+    }
+
+    @Override
+    public void debug(String msg, Throwable e) {
+        logger.debug(msg, e);
+    }
+
+    @Override
+    public void info(String msg) {
+        logger.info(msg);
+    }
+
+    @Override
+    public void info(Throwable e) {
+        logger.info(e);
+    }
+
+    @Override
+    public void info(String msg, Throwable e) {
+        logger.info(msg, e);
+    }
+
+    @Override
+    public void warn(String msg) {
+        logger.warn(msg);
+    }
+
+    @Override
+    public void warn(Throwable e) {
+        logger.warn(e);
+    }
+
+    @Override
+    public void warn(String msg, Throwable e) {
+        logger.warn(msg, e);
+    }
+
+    @Override
+    public void error(String msg) {
+        logger.error(msg);
+    }
+
+    @Override
+    public void error(Throwable e) {
+        logger.error(e);
+    }
+
+    @Override
+    public void error(String msg, Throwable e) {
+        logger.error(msg, e);
+    }
+
+    @Override
+    public boolean isTraceEnabled() {
+        return logger.isTraceEnabled();
+    }
+
+    @Override
+    public boolean isDebugEnabled() {
+        return logger.isDebugEnabled();
+    }
+
+    @Override
+    public boolean isInfoEnabled() {
+        return logger.isInfoEnabled();
+    }
+
+    @Override
+    public boolean isWarnEnabled() {
+        return logger.isWarnEnabled();
+    }
+
+    @Override
+    public boolean isErrorEnabled() {
+        return logger.isErrorEnabled();
+    }
+}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/log4j2/Log4j2LoggerAdapter.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/log4j2/Log4j2LoggerAdapter.java
new file mode 100644
index 0000000000..8972318b7a
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/log4j2/Log4j2LoggerAdapter.java
@@ -0,0 +1,78 @@
+package org.apache.dubbo.common.logger.log4j2;
+
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerAdapter;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.config.Configurator;
+
+import java.io.File;
+
+public class Log4j2LoggerAdapter implements LoggerAdapter {
+    private File file;
+    @Override
+    public Logger getLogger(Class<?> key) {
+        return new Log4j2Logger(LogManager.getLogger(key));
+    }
+
+    @Override
+    public Logger getLogger(String key) {
+        return new Log4j2Logger(LogManager.getLogger(key));
+    }
+
+    @Override
+    public org.apache.dubbo.common.logger.Level getLevel() {
+        return fromLog4j2Level(LogManager.getRootLogger().getLevel());
+    }
+
+    private org.apache.dubbo.common.logger.Level fromLog4j2Level(org.apache.logging.log4j.Level
level) {
+        if (level == org.apache.logging.log4j.Level.ALL)
+            return org.apache.dubbo.common.logger.Level.ALL;
+        if (level == org.apache.logging.log4j.Level.TRACE)
+            return org.apache.dubbo.common.logger.Level.TRACE;
+        if (level == org.apache.logging.log4j.Level.DEBUG)
+            return org.apache.dubbo.common.logger.Level.DEBUG;
+        if (level == org.apache.logging.log4j.Level.INFO)
+            return org.apache.dubbo.common.logger.Level.INFO;
+        if (level == org.apache.logging.log4j.Level.WARN)
+            return org.apache.dubbo.common.logger.Level.WARN;
+        if (level == org.apache.logging.log4j.Level.ERROR)
+            return org.apache.dubbo.common.logger.Level.ERROR;
+        return org.apache.dubbo.common.logger.Level.OFF;
+    }
+
+    @Override
+    public File getFile() {
+        return file;
+    }
+
+    @Override
+    public void setFile(File file) {
+    }
+
+    @Override
+    public void setLevel(org.apache.dubbo.common.logger.Level level) {
+        Configurator.setLevel(LogManager.ROOT_LOGGER_NAME, toLog4j2Level(level));
+        return;
+    }
+
+    public void setRootLevel(org.apache.dubbo.common.logger.Level level){
+        Configurator.setRootLevel(toLog4j2Level(level));
+    }
+
+    private Level toLog4j2Level(org.apache.dubbo.common.logger.Level level) {
+        if (level == org.apache.dubbo.common.logger.Level.ALL)
+            return org.apache.logging.log4j.Level.ALL;
+        if (level == org.apache.dubbo.common.logger.Level.TRACE)
+            return org.apache.logging.log4j.Level.TRACE;
+        if (level == org.apache.dubbo.common.logger.Level.DEBUG)
+            return org.apache.logging.log4j.Level.DEBUG;
+        if (level == org.apache.dubbo.common.logger.Level.INFO)
+            return org.apache.logging.log4j.Level.INFO;
+        if (level == org.apache.dubbo.common.logger.Level.WARN)
+            return org.apache.logging.log4j.Level.WARN;
+        if (level == org.apache.dubbo.common.logger.Level.ERROR)
+            return org.apache.logging.log4j.Level.ERROR;
+        return org.apache.logging.log4j.Level.OFF;
+    }
+}
diff --git a/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter
b/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter
index fb0b3d8f96..47cdfd5e32 100644
--- a/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter
+++ b/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.logger.LoggerAdapter
@@ -1,4 +1,5 @@
 slf4j=org.apache.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
 jcl=org.apache.dubbo.common.logger.jcl.JclLoggerAdapter
 log4j=org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter
-jdk=org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter
\ No newline at end of file
+jdk=org.apache.dubbo.common.logger.jdk.JdkLoggerAdapter
+log4j2=org.apache.dubbo.common.logger.log4j2.Log4j2LoggerAdapter
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-demo-consumer/src/main/java/org/apache/dubbo/demo/consumer/Consumer.java
b/dubbo-demo/dubbo-demo-consumer/src/main/java/org/apache/dubbo/demo/consumer/Consumer.java
index 8ad330e978..abe135d8d9 100644
--- a/dubbo-demo/dubbo-demo-consumer/src/main/java/org/apache/dubbo/demo/consumer/Consumer.java
+++ b/dubbo-demo/dubbo-demo-consumer/src/main/java/org/apache/dubbo/demo/consumer/Consumer.java
@@ -16,6 +16,8 @@
  */
 package org.apache.dubbo.demo.consumer;
 
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.demo.DemoService;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
@@ -29,10 +31,16 @@
     public static void main(String[] args) {
         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
         context.start();
+        //get logger
+        Logger logger = LoggerFactory.getLogger(Consumer.class);
         DemoService demoService = (DemoService) context.getBean("demoService"); // get remote
service proxy
+        int i = 0;
         while (true) {
             try {
                 Thread.sleep(1000);
+                logger.error("hello:times:" + (i++));
+                logger.info("infoLevel:times:" + (i++));
+                logger.debug("debugLevel:times:" + (i++));
                 String hello = demoService.sayHello("world"); // call remote method
                 System.out.println(hello); // get result
             } catch (Throwable throwable) {
diff --git a/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
b/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
index a56a10ee7e..43b8da4c0c 100644
--- a/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
+++ b/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
@@ -26,7 +26,7 @@
     <dubbo:application name="demo-consumer"/>
 
     <!-- use multicast registry center to discover service -->
-    <dubbo:registry address="multicast://224.5.6.7:1234"/>
+    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
 
     <!-- generate proxy for the remote service, then demoService can be used in the same
way as the
     local regular interface -->
diff --git a/dubbo-demo/dubbo-demo-consumer/src/main/resources/dubbo.properties b/dubbo-demo/dubbo-demo-consumer/src/main/resources/dubbo.properties
index 8c3cb2559c..bfe065d6e6 100644
--- a/dubbo-demo/dubbo-demo-consumer/src/main/resources/dubbo.properties
+++ b/dubbo-demo/dubbo-demo-consumer/src/main/resources/dubbo.properties
@@ -1 +1,3 @@
 dubbo.application.qos.port=33333
+#set logger type
+dubbo.application.logger=log4j2
diff --git a/dubbo-demo/dubbo-demo-consumer/src/main/resources/log4j2.xml b/dubbo-demo/dubbo-demo-consumer/src/main/resources/log4j2.xml
new file mode 100644
index 0000000000..d2537eca64
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-consumer/src/main/resources/log4j2.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- log4j2 configuration-->
+<Configuration status="ERROR">
+    <!-- 日志文件目录和压缩文件目录配置 -->
+    <Properties>
+        <Property name="fileName">/Users/bubing/Downloads</Property>
+        <Property name="fileGz">/Users/bubing/Downloads</Property>
+    </Properties>
+    <Appenders>
+        <!-- 输出控制台日志的配置 -->
+        <Console name="console" target="SYSTEM_OUT" follow="true">
+            <!-- 输出日志的格式 -->
+            <PatternLayout>
+                <pattern>%d %p %C{1.} [%t] %m%n</pattern>
+            </PatternLayout>
+        </Console>
+        <!-- 存储所有error信息 -->
+        <RollingRandomAccessFile name="errorFile" fileName="${fileName}/mic-error.log"
+                                 filePattern="${fileGz}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.mic-error.gz">
+            <PatternLayout>
+                <pattern>%d %p %C{1.} [%t] %m%n</pattern>
+            </PatternLayout>
+            <Policies>
+                <TimeBasedTriggeringPolicy interval="6" modulate="true" />
+                <SizeBasedTriggeringPolicy size="10 MB"/>
+            </Policies>
+            <!-- 指定每天的最大压缩包个数,默认7个,超过了会覆盖之前的
-->
+            <DefaultRolloverStrategy max="50"/>
+        </RollingRandomAccessFile>
+    </Appenders>
+    <!-- 全局配置,默认所有的Logger都继承此配置 -->
+    <Loggers>
+        <Logger name="org.apache.catalina.util.LifecycleBase" level="info" />
+        <Logger name="org.apache.coyote.http11.Http11NioProtocol" level="info" />
+        <Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="info" />
+        <Logger name="org.hibernate.validator.internal.util.Version" level="info" />
+        <Logger name="org.springframework" level="ERROR" />
+        <Logger name="com.github" level="ERROR" />
+        <Root level="info">
+            <AppenderRef ref="errorFile" />
+        </Root>
+    </Loggers>
+</Configuration>
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
b/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
index c2ab4a21e0..ed08464c88 100644
--- a/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
+++ b/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
@@ -25,7 +25,7 @@
     <dubbo:application name="demo-provider"/>
 
     <!-- use multicast registry center to export service -->
-    <dubbo:registry address="multicast://224.5.6.7:1234"/>
+    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
 
     <!-- use dubbo protocol to export service on port 20880 -->
     <dubbo:protocol name="dubbo" port="20880"/>
diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml
index 29ca7a7c5e..9dfddaa51c 100644
--- a/dubbo-dependencies-bom/pom.xml
+++ b/dubbo-dependencies-bom/pom.xml
@@ -112,6 +112,7 @@
         <activation_version>1.2.0</activation_version>
         <hessian_lite_version>3.2.3</hessian_lite_version>
         <swagger_version>1.5.19</swagger_version>
+        <log4j2_version>2.5</log4j2_version>
     </properties>
 
     <dependencyManagement>
@@ -332,6 +333,17 @@
                 <version>${logback_version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.apache.logging.log4j</groupId>
+                <artifactId>log4j-core</artifactId>
+                <version>${log4j2_version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.logging.log4j</groupId>
+                <artifactId>log4j-api</artifactId>
+                <version>${log4j2_version}</version>
+            </dependency>
+
             <!-- for dubbo-rpc-webservice -->
             <dependency>
                 <groupId>javax.xml.bind</groupId>


 

----------------------------------------------------------------
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


Mime
View raw message