Skip to content

Commit

Permalink
日志bug修复
Browse files Browse the repository at this point in the history
Signed-off-by: TLPC <470193496@qq.com>
  • Loading branch information
TangLeDaily committed Dec 6, 2023
1 parent b3d1022 commit bd816a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public static void install(String artifact, Map<String, Object> argsMap, Instrum
artifactCache = artifact;
adviserCache = new DefaultAdviser();

// 初始化默认日志
LoggerFactory.initDefaultLogger(artifact);

// 初始化框架类加载器
ClassLoaderManager.init(argsMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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配置文件路径
*
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}
}
Expand Down Expand Up @@ -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());
}
}

Expand Down

0 comments on commit bd816a0

Please sign in to comment.