You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by gu...@apache.org on 2022/04/19 05:40:39 UTC
[dubbo] branch 3.0 updated: Change to thread-safe date processing class (#9936)
This is an automated email from the ASF dual-hosted git repository.
guohao pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new bc638b5748 Change to thread-safe date processing class (#9936)
bc638b5748 is described below
commit bc638b5748aa6b71327e6cc84885316368648162
Author: Oliver <wq...@163.com>
AuthorDate: Tue Apr 19 13:40:32 2022 +0800
Change to thread-safe date processing class (#9936)
* Change to thread-safe date processing class
* restore package order
---
.../org/apache/dubbo/rpc/support/AccessLogData.java | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java
index 455a47fe02..33bf46714e 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java
@@ -16,32 +16,30 @@
*/
package org.apache.dubbo.rpc.support;
+
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcContext;
-
import com.alibaba.fastjson.JSON;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
- * AccessLogData is a container for log event data. In internally uses map and store each filed of log as value. It
- * does not generate any dynamic value e.g. time stamp, local jmv machine host address etc. It does not allow any null
+ * AccessLogData is a container for log event data. In internally uses map and store each field of log as value. It
+ * does not generate any dynamic value e.g. time stamp, local jvm machine host address etc. It does not allow any null
* or empty key.
*
- * Note: since its date formatter is a singleton, make sure to run it in single thread only.
*/
public final class AccessLogData {
private static final String MESSAGE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
- private static final DateFormat MESSAGE_DATE_FORMATTER = new SimpleDateFormat(MESSAGE_DATE_FORMAT);
-
+ private static final DateTimeFormatter MESSAGE_DATE_FORMATTER = DateTimeFormatter.ofPattern(MESSAGE_DATE_FORMAT);
private static final String VERSION = "version";
private static final String GROUP = "group";
private static final String SERVICE = "service";
@@ -194,7 +192,7 @@ public final class AccessLogData {
StringBuilder sn = new StringBuilder();
sn.append('[')
- .append(MESSAGE_DATE_FORMATTER.format(getInvocationTime()))
+ .append(LocalDateTime.ofInstant(getInvocationTime().toInstant(), ZoneId.systemDefault()).format(MESSAGE_DATE_FORMATTER))
.append("] ")
.append(get(REMOTE_HOST))
.append(':')