From e4769293dcab5903ddbd81584cffb383cabf7789 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 16 Mar 2020 22:30:29 +0800 Subject: [PATCH] Move CommandCenterLog to sentinel-transport-common and polish related code (#1341) Signed-off-by: Eric Zhao --- .../demo/log/logback/CommandCenterLogLoggerImpl.java | 2 +- .../csp/sentinel/demo/log/logback/CommandCenterLogTest.java | 2 +- .../csp/sentinel/transport}/log/CommandCenterLog.java | 3 ++- .../sentinel/transport/command/NettyHttpCommandCenter.java | 3 +-- .../csp/sentinel/transport/command/netty/HttpServer.java | 4 ++-- .../sentinel/transport/command/netty/HttpServerHandler.java | 2 +- .../sentinel/transport/command/SimpleHttpCommandCenter.java | 2 +- .../csp/sentinel/transport/command/http/HttpEventTask.java | 4 ++-- .../transport/heartbeat/client/SimpleHttpClient.java | 5 ++--- 9 files changed, 13 insertions(+), 14 deletions(-) rename {sentinel-core/src/main/java/com/alibaba/csp/sentinel => sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport}/log/CommandCenterLog.java (96%) diff --git a/sentinel-demo/sentinel-demo-log-logback/src/main/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogLoggerImpl.java b/sentinel-demo/sentinel-demo-log-logback/src/main/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogLoggerImpl.java index 1f6c57dc..78ca6812 100644 --- a/sentinel-demo/sentinel-demo-log-logback/src/main/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogLoggerImpl.java +++ b/sentinel-demo/sentinel-demo-log-logback/src/main/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogLoggerImpl.java @@ -15,7 +15,7 @@ */ package com.alibaba.csp.sentinel.demo.log.logback; -import com.alibaba.csp.sentinel.log.CommandCenterLog; +import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; import com.alibaba.csp.sentinel.log.LogTarget; import com.alibaba.csp.sentinel.log.Logger; import org.slf4j.LoggerFactory; diff --git a/sentinel-demo/sentinel-demo-log-logback/src/test/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogTest.java b/sentinel-demo/sentinel-demo-log-logback/src/test/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogTest.java index 5004131b..f8569586 100644 --- a/sentinel-demo/sentinel-demo-log-logback/src/test/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogTest.java +++ b/sentinel-demo/sentinel-demo-log-logback/src/test/java/com/alibaba/csp/sentinel/demo/log/logback/CommandCenterLogTest.java @@ -15,7 +15,7 @@ */ package com.alibaba.csp.sentinel.demo.log.logback; -import com.alibaba.csp.sentinel.log.CommandCenterLog; +import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/CommandCenterLog.java b/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/log/CommandCenterLog.java similarity index 96% rename from sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/CommandCenterLog.java rename to sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/log/CommandCenterLog.java index 17e6d26e..c4054c75 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/CommandCenterLog.java +++ b/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/log/CommandCenterLog.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.csp.sentinel.log; +package com.alibaba.csp.sentinel.transport.log; +import com.alibaba.csp.sentinel.log.LoggerSpiProvider; import com.alibaba.csp.sentinel.log.jul.JavaLoggingAdapter; /** diff --git a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/NettyHttpCommandCenter.java b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/NettyHttpCommandCenter.java index 29adb01f..16db0df1 100755 --- a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/NettyHttpCommandCenter.java +++ b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/NettyHttpCommandCenter.java @@ -49,9 +49,8 @@ public class NettyHttpCommandCenter implements CommandCenter { try { server.start(); } catch (Exception ex) { - RecordLog.info("Start netty server error", ex); + RecordLog.warn("[NettyHttpCommandCenter] Failed to start Netty transport server", ex); ex.printStackTrace(); - System.exit(-1); } } }); diff --git a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServer.java b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServer.java index 9f8f5776..4d57b4ea 100755 --- a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServer.java +++ b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServer.java @@ -21,7 +21,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import com.alibaba.csp.sentinel.command.CommandHandler; -import com.alibaba.csp.sentinel.log.CommandCenterLog; +import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.transport.config.TransportConfig; import com.alibaba.csp.sentinel.util.StringUtil; @@ -78,7 +78,7 @@ public final class HttpServer { break; } catch (Exception e) { TimeUnit.MILLISECONDS.sleep(30); - RecordLog.warn("[HttpServer] Netty server bind error, port={0}, retry={1}", newPort, retryCount); + RecordLog.warn("[HttpServer] Netty server bind error, port={}, retry={}", newPort, retryCount); retryCount ++; } } diff --git a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServerHandler.java b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServerHandler.java index 36146c2f..a77e6a6b 100755 --- a/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServerHandler.java +++ b/sentinel-transport/sentinel-transport-netty-http/src/main/java/com/alibaba/csp/sentinel/transport/command/netty/HttpServerHandler.java @@ -25,7 +25,7 @@ import com.alibaba.csp.sentinel.command.CommandHandler; import com.alibaba.csp.sentinel.command.CommandRequest; import com.alibaba.csp.sentinel.command.CommandResponse; import com.alibaba.csp.sentinel.config.SentinelConfig; -import com.alibaba.csp.sentinel.log.CommandCenterLog; +import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; import com.alibaba.csp.sentinel.transport.command.codec.CodecRegistry; import com.alibaba.csp.sentinel.transport.command.codec.Encoder; import com.alibaba.csp.sentinel.transport.util.HttpCommandUtils; diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java index 382f1398..484b8b69 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java @@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit; import com.alibaba.csp.sentinel.command.CommandHandler; import com.alibaba.csp.sentinel.command.CommandHandlerProvider; import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; -import com.alibaba.csp.sentinel.log.CommandCenterLog; +import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; import com.alibaba.csp.sentinel.transport.CommandCenter; import com.alibaba.csp.sentinel.transport.command.http.HttpEventTask; import com.alibaba.csp.sentinel.transport.config.TransportConfig; diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java index ba65d46b..57ad7762 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java @@ -19,7 +19,7 @@ import com.alibaba.csp.sentinel.command.CommandHandler; import com.alibaba.csp.sentinel.command.CommandRequest; import com.alibaba.csp.sentinel.command.CommandResponse; import com.alibaba.csp.sentinel.config.SentinelConfig; -import com.alibaba.csp.sentinel.log.CommandCenterLog; +import com.alibaba.csp.sentinel.transport.log.CommandCenterLog; import com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter; import com.alibaba.csp.sentinel.transport.command.exception.RequestException; import com.alibaba.csp.sentinel.transport.util.HttpCommandUtils; @@ -126,7 +126,7 @@ public class HttpEventTask implements Runnable { printWriter.flush(); } } catch (Exception e1) { - CommandCenterLog.warn("[SimpleHttpCommandCenter] Close server socket failed", e); + CommandCenterLog.warn("Failed to write error response", e1); } } finally { closeResource(inputStream); diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/client/SimpleHttpClient.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/client/SimpleHttpClient.java index 8c20ca75..6befd46f 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/client/SimpleHttpClient.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/client/SimpleHttpClient.java @@ -25,7 +25,6 @@ import java.nio.charset.Charset; import java.util.Map; import java.util.Map.Entry; -import com.alibaba.csp.sentinel.log.CommandCenterLog; import com.alibaba.csp.sentinel.log.RecordLog; /** @@ -125,7 +124,7 @@ public class SimpleHttpClient { try { socket.close(); } catch (Exception ex) { - CommandCenterLog.info("Error when closing " + type + " request to " + socketAddress + ": ", ex); + RecordLog.warn("Error when closing {} request to {} in SimpleHttpClient", type, socketAddress, ex); } } } @@ -177,7 +176,7 @@ public class SimpleHttpClient { } return paramsBuilder.toString(); } catch (Throwable e) { - RecordLog.info("Encode request params fail", e); + RecordLog.warn("Encode request params fail", e); return ""; } }