Spring security 使用Spring云配置的外部日志记录配置

Spring security 使用Spring云配置的外部日志记录配置,spring-security,log4j2,spring-cloud,Spring Security,Log4j2,Spring Cloud,我刚刚体验了SpringCloud配置,在我的项目之外有一些配置文件。我按照说明设置了一个客户端和一个服务器(链接到git),效果非常好 基本上,我的每个配置文件都有不同的application.yml,在这些文件中有一个服务器端口属性,还有一个日志配置文件的URL(每个配置文件一个log4j2.yml),它也在我的git存储库中。 在没有身份验证的情况下,它工作得很好:客户机向服务器请求与其配置文件匹配的application.yml文件。然后,服务器找到该文件并将端口和log4j2配置文件返


我刚刚体验了SpringCloud配置,在我的项目之外有一些配置文件。我按照说明设置了一个客户端和一个服务器(链接到git),效果非常好
基本上,我的每个配置文件都有不同的application.yml,在这些文件中有一个服务器端口属性,还有一个日志配置文件的URL(每个配置文件一个log4j2.yml),它也在我的git存储库中。 在没有身份验证的情况下,它工作得很好:客户机向服务器请求与其配置文件匹配的application.yml文件。然后,服务器找到该文件并将端口和log4j2配置文件返回给客户端。
我得到了我想要的,这是一个不同级别的日志记录,具体取决于客户端的配置文件。
当我使用spring security设置身份验证时(使用默认用户名和简单密码),客户端会恢复端口,但当它尝试访问log4j2配置文件时,服务器返回401错误,表示客户端无权访问此文件。
这可能是因为客户端不知道访问application.yml中文件的凭据,我不知道是否可以在logging.config属性中插入凭据

我尝试过类似的方法,但效果不太好:

logging:
 config: http://user:password@localhost:8888/....../log4j2.yml
可能有一种替代方法,就是当URL是该文件时,告诉服务器忽略安全性,但如果有一天我必须进行身份验证才能访问它,我将无法这样做

这是我的文件:

GIT

application-dev.yml

server:
 port: 55556

logging:
 config: http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml
客户端

boostrap.yml

spring:
  application:
    name: ConfigExtClient
  profiles:
    active: dev
  cloud:
    config:
      uri: http://localhost:8888
      username: user
      password: foo
依赖项(pom.xml)

bootstrap.yml

spring:
  application:
    name: ConfigExtServer
依赖项(pom.xml)

我跟踪了错误,它出现在重新初始化LoggingSystem中的PropertySourceBootstrapConfiguration类中:

它进入catch,例外情况是:

Server returned HTTP response code: 401 for URL: http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml
提前感谢您的帮助,

Romain

您可以像在GitHub中一样设置配置客户端

它需要
log4j2.component.properties
bootstrap.yml
配置

bootstrap.yml

logging:
  config: http://configServerAddress:8888/yourAppName/yourSpringProfile/gitBranch/log4j2.xml
log4j2.component.properties

log4j.configurationFile=http://configServerAddress:8888/yourAppName/yourSpringProfile/gitBranch/log4j2.xml
log4j2.configurationUserName=guest
log4j2.configurationPassword=guest

你找到解决问题的办法了吗??
Logging config file location 'http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml' cannot be opened and will be ignored
try {
            ResourceUtils.getURL(logConfig).openStream().close();
            system.initialize(new LoggingInitializationContext(environment),
                    logConfig, logFile);
        }
        catch (Exception ex) {
            PropertySourceBootstrapConfiguration.logger
                    .warn("Logging config file location '" + logConfig
                            + "' cannot be opened and will be ignored");
        }
Server returned HTTP response code: 401 for URL: http://localhost:8888/ConfigExtClient/dev/master/log4j2.yml
logging:
  config: http://configServerAddress:8888/yourAppName/yourSpringProfile/gitBranch/log4j2.xml
log4j.configurationFile=http://configServerAddress:8888/yourAppName/yourSpringProfile/gitBranch/log4j2.xml
log4j2.configurationUserName=guest
log4j2.configurationPassword=guest