Closed qixiaobo closed 10 months ago
从代码中可以看到 LogbackReInitializer支持reinit 因此biz加载时会执行 但是其持有的是通一个LoggingContext 导致后续logging会出现依赖检查duplicate出现失败【可以理解成共享变量】
private boolean innerCheckForFileNamePatternCollisionInPreviousRFA(FileNamePattern fileNamePattern) {
boolean collisionsDetected = false;
@SuppressWarnings("unchecked")
Map<String, FileNamePattern> map = (Map<String, FileNamePattern>) context.getObject(CoreConstants.RFA_FILENAME_PATTERN_COLLISION_MAP);
if (map == null) {
return collisionsDetected;
}
for (Entry<String, FileNamePattern> entry : map.entrySet()) {
if (fileNamePattern.equals(entry.getValue())) {
addErrorForCollision("FileNamePattern", entry.getValue().toString(), entry.getKey());
collisionsDetected = true;
}
}
if (name != null) {
map.put(getName(), fileNamePattern);
}
return collisionsDetected;
}
可以看到实际可以通过更换 logback.ContextSelector
/**
* FOR INTERNAL USE. This method is intended for use by StaticLoggerBinder.
*
* @param defaultLoggerContext
* @throws ClassNotFoundException
* @throws NoSuchMethodException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public void init(LoggerContext defaultLoggerContext, Object key) throws ClassNotFoundException, NoSuchMethodException, InstantiationException,
IllegalAccessException, InvocationTargetException {
if (this.key == null) {
this.key = key;
} else if (this.key != key) {
throw new IllegalAccessException("Only certain classes can access this method.");
}
String contextSelectorStr = OptionHelper.getSystemProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR);
if (contextSelectorStr == null) {
contextSelector = new DefaultContextSelector(defaultLoggerContext);
} else if (contextSelectorStr.equals("JNDI")) {
// if jndi is specified, let's use the appropriate class
contextSelector = new ContextJNDISelector(defaultLoggerContext);
} else {
contextSelector = dynamicalContextSelector(defaultLoggerContext, contextSelectorStr);
}
}
目前看到已经有pr在跟进了 https://github.com/sofastack/sofa-serverless/pull/305
Describe the question or bug
ark-serverless 0.5.5 之后支持了arklet并行加速静态发布 https://github.com/sofastack/sofa-serverless/pull/324 当biz使用logback组件时出现logback冲突 导致biz启动失败
Expected behavior
biz正常启动
Actual behavior
部分biz会报错
Steps to reproduce
Steps to reproduce the problem:
Screenshots
If applicable, add screenshots to help explain your problem.
Minimal yet complete reproducer code (or GitHub URL to code)
Environment
java -version
):uname -a
):