This is an automated email from the ASF dual-hosted git repository. huxing pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push: new e1f4466 Optimize the code: use logger instead of printStackTrace(). (#3202) e1f4466 is described below commit e1f4466c389c3831b1de6cb4ce8e3adcbd8491e6 Author: 于玉桔 <769213...@qq.com> AuthorDate: Mon Jan 14 23:21:29 2019 +0800 Optimize the code: use logger instead of printStackTrace(). (#3202) --- .../main/java/org/apache/dubbo/common/utils/PojoUtils.java | 11 ++++++++--- .../src/main/java/org/apache/dubbo/container/Main.java | 1 - .../remoting/transport/netty4/logging/MessageFormatter.java | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java index e9a9c63..2198709 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PojoUtils.java @@ -16,6 +16,9 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; + import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -57,6 +60,7 @@ import java.util.concurrent.ConcurrentSkipListMap; */ public class PojoUtils { + private static final Logger logger = LoggerFactory.getLogger(PojoUtils.class); private static final ConcurrentMap<String, Method> NAME_METHODS_CACHE = new ConcurrentHashMap<String, Method>(); private static final ConcurrentMap<Class<?>, ConcurrentMap<String, Field>> CLASS_FIELD_CACHE = new ConcurrentHashMap<Class<?>, ConcurrentMap<String, Field>>(); @@ -457,9 +461,10 @@ public class PojoUtils { try { method.invoke(dest, value); } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Failed to set pojo " + dest.getClass().getSimpleName() + " property " + name - + " value " + value + "(" + value.getClass() + "), cause: " + e.getMessage(), e); + String exceptionDescription = "Failed to set pojo " + dest.getClass().getSimpleName() + " property " + name + + " value " + value + "(" + value.getClass() + "), cause: " + e.getMessage(); + logger.error(exceptionDescription, e); + throw new RuntimeException(exceptionDescription, e); } } else if (field != null) { value = realize0(value, field.getType(), field.getGenericType(), history); diff --git a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java index 80646ae..5462d52 100644 --- a/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java +++ b/dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java @@ -88,7 +88,6 @@ public class Main { } System.out.println(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]").format(new Date()) + " Dubbo service server started!"); } catch (RuntimeException e) { - e.printStackTrace(); logger.error(e.getMessage(), e); System.exit(1); } diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java index f860875..9bc3ff9 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/logging/MessageFormatter.java @@ -16,6 +16,9 @@ */ package org.apache.dubbo.remoting.transport.netty4.logging; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; + import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; @@ -86,6 +89,7 @@ import java.util.Map; * {@link #arrayFormat(String, Object[])} methods for more details. */ final class MessageFormatter { + private static final Logger logger = LoggerFactory.getLogger(MessageFormatter.class); static final char DELIM_START = '{'; static final char DELIM_STOP = '}'; static final String DELIM_STR = "{}"; @@ -279,7 +283,7 @@ final class MessageFormatter { System.err .println("SLF4J: Failed toString() invocation on an object of type [" + o.getClass().getName() + ']'); - t.printStackTrace(); + logger.error(t.getMessage(), t); sbuf.append("[FAILED toString()]"); } }