From bd816a0dc31f63e982ac69b689e9e89cae88e86d Mon Sep 17 00:00:00 2001 From: TLPC <470193496@qq.com> Date: Wed, 6 Dec 2023 11:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TLPC <470193496@qq.com> --- .../sermant/core/AgentCoreEntrance.java | 3 +++ .../sermant/core/common/LoggerFactory.java | 21 ++++++++++--------- .../plugin/classloader/PluginClassLoader.java | 7 +++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java index 755151a693..7d2c99e210 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/AgentCoreEntrance.java @@ -87,6 +87,9 @@ public static void install(String artifact, Map argsMap, Instrum artifactCache = artifact; adviserCache = new DefaultAdviser(); + // 初始化默认日志 + LoggerFactory.initDefaultLogger(artifact); + // 初始化框架类加载器 ClassLoaderManager.init(argsMap); diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/common/LoggerFactory.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/common/LoggerFactory.java index 4606a9046b..3c6bab5e5b 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/common/LoggerFactory.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/common/LoggerFactory.java @@ -36,13 +36,23 @@ public class LoggerFactory { private static final String LOGGER_INIT_METHOD = "init"; - private static volatile Logger defaultLogger; + private static Logger defaultLogger; private static volatile Logger sermantLogger; private LoggerFactory() { } + /** + * 初始化默认日志 + * + * @param artifact 归属产品 + */ + public static void initDefaultLogger(String artifact) { + // defaultLogger的name必须为sermant.artifact,需和sermantLogger保持一致 + defaultLogger = java.util.logging.Logger.getLogger("sermant." + artifact); + } + /** * 初始化logback配置文件路径 * @@ -77,15 +87,6 @@ public static Logger getLogger() { if (sermantLogger != null) { return sermantLogger; } - - // 避免日志重复获取 - if (defaultLogger == null) { - synchronized (LoggerFactory.class) { - if (defaultLogger == null) { - defaultLogger = java.util.logging.Logger.getLogger("sermant"); - } - } - } return defaultLogger; } } \ No newline at end of file diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/classloader/PluginClassLoader.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/classloader/PluginClassLoader.java index 926941a8bd..0b8523de05 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/classloader/PluginClassLoader.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/plugin/classloader/PluginClassLoader.java @@ -104,8 +104,7 @@ public Class loadClass(String name, boolean resolve) throws ClassNotFoundExce clazz = super.loadClass(name, resolve); } catch (ClassNotFoundException e) { // 捕获类找不到的异常,下一步会进入localLoader中去加载类 - // ignored - LOGGER.log(Level.WARNING, "load class failed, msg is {0}", e.getMessage()); + LOGGER.log(Level.FINE, "Load class failed, msg is {0}", e.getMessage()); } } @@ -123,7 +122,7 @@ public Class loadClass(String name, boolean resolve) throws ClassNotFoundExce clazz = loader.loadClass(name); } catch (ClassNotFoundException e) { // 无法找到类,忽略,后续抛出异常 - LOGGER.log(Level.WARNING, "load class failed, msg is {0}", e.getMessage()); + LOGGER.log(Level.FINE, "Load class failed, msg is {0}", e.getMessage()); } } } @@ -157,7 +156,7 @@ public Class loadSermantClass(String name) throws ClassNotFoundException { clazz = super.loadClass(name, false); } catch (ClassNotFoundException e) { // 无法找到类,忽略,后续抛出异常 - LOGGER.log(Level.WARNING, "load sermant class failed, msg is {0}", e.getMessage()); + LOGGER.log(Level.FINE, "Load sermant class failed, msg is {0}", e.getMessage()); } }