From d5204bb6a40f14f76a21ad4c4768b4072f0449dd Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Wed, 27 Mar 2019 10:55:04 +0800 Subject: [PATCH] Ensure Error caught in InitExecutor and do not exit when error occurs in LogBase (#613) to avoid affecting normal logic of users Signed-off-by: Eric Zhao --- .../java/com/alibaba/csp/sentinel/init/InitExecutor.java | 7 +++---- .../main/java/com/alibaba/csp/sentinel/log/LogBase.java | 6 +++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/init/InitExecutor.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/init/InitExecutor.java index 99272b92..0d84ad78 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/init/InitExecutor.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/init/InitExecutor.java @@ -50,16 +50,15 @@ public final class InitExecutor { } for (OrderWrapper w : initList) { w.func.init(); - RecordLog.info(String.format("[InitExecutor] Initialized: %s with order %d", + RecordLog.info(String.format("[InitExecutor] Executing %s with order %d", w.func.getClass().getCanonicalName(), w.order)); } } catch (Exception ex) { - RecordLog.warn("[InitExecutor] Init failed", ex); + RecordLog.warn("[InitExecutor] WARN: Initialization failed", ex); ex.printStackTrace(); } catch (Error error) { - RecordLog.warn("[InitExecutor] Init failed with fatal error", error); + RecordLog.warn("[InitExecutor] ERROR: Initialization failed with fatal error", error); error.printStackTrace(); - throw error; } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java index afa9d977..ae71b1a4 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/LogBase.java @@ -32,11 +32,15 @@ import com.alibaba.csp.sentinel.util.PidUtil; * @author leyou */ public class LogBase { + public static final String LOG_CHARSET = "utf-8"; + private static final String DIR_NAME = "logs" + File.separator + "csp"; private static final String USER_HOME = "user.home"; + public static final String LOG_DIR = "csp.sentinel.log.dir"; public static final String LOG_NAME_USE_PID = "csp.sentinel.log.use.pid"; + private static boolean logNameUsePid = false; private static String logBaseDir; @@ -45,8 +49,8 @@ public class LogBase { try { init(); } catch (Throwable t) { + System.err.println("[LogBase] FATAL ERROR when initializing log class"); t.printStackTrace(); - System.exit(-1); } }