日志bug,临时测试
This commit is contained in:
@@ -38,6 +38,10 @@ public class NacosLogbackConfigLoader implements SpringApplicationRunListener, A
|
||||
public void environmentPrepared(ConfigurableEnvironment environment) {
|
||||
String active = environment.getProperty("spring.profiles.active");
|
||||
if(!"jb".equalsIgnoreCase(active)){
|
||||
|
||||
|
||||
|
||||
|
||||
String serverAddr = environment.getProperty("spring.cloud.nacos.config.server-addr");
|
||||
String namespace = environment.getProperty("spring.cloud.nacos.config.namespace");
|
||||
String projectName = environment.getProperty("microservice.ename");
|
||||
@@ -51,18 +55,21 @@ public class NacosLogbackConfigLoader implements SpringApplicationRunListener, A
|
||||
if (response.getStatusCode().is2xxSuccessful()) {
|
||||
String logbackConfigContent = response.getBody();
|
||||
//替换项目名称
|
||||
logbackConfigContent = logbackConfigContent.replace("projectDefaultName",projectName);
|
||||
logbackConfigContent = logbackConfigContent.replace("logDefaultLevel",logLevel);
|
||||
//logbackConfigContent = logbackConfigContent.replace("projectDefaultName",projectName);
|
||||
// logbackConfigContent = logbackConfigContent.replace("logDefaultLevel",logLevel);
|
||||
// 应用获取到的Logback配置
|
||||
applyLogbackConfig(logbackConfigContent,logLevel);
|
||||
applyLogbackConfig(logbackConfigContent,logLevel,projectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyLogbackConfig(String logbackConfigContent,String logLevel) {
|
||||
private void applyLogbackConfig(String logbackConfigContent,String logLevel,String projectName) {
|
||||
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
JoranConfigurator configurator = new JoranConfigurator();
|
||||
configurator.setContext(context);
|
||||
// 注意:变量名必须与 XML 中 ${...} 内的名称完全一致
|
||||
context.putProperty("log.projectName", projectName != null ? projectName : "undefined_pqs");
|
||||
context.putProperty("log.commonLevel", logLevel != null ? logLevel : "INFO");
|
||||
context.reset();
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(logbackConfigContent.getBytes(StandardCharsets.UTF_8))) {
|
||||
configurator.doConfigure(inputStream);
|
||||
|
||||
Reference in New Issue
Block a user