简体   繁体   English

Spring 日志记录优先级

[英]Spring logging priority

The Spring logging documentation is available here and describes the different logging possibilities. Spring 日志记录文档可在此处获得,它描述了不同的日志记录可能性。 However, something I have not been able to find is the priority of the different configurations.但是,我无法找到的是不同配置的优先级。 More concretely, in application.properties I enabled logging for showing basic authentication failures by doing:更具体地说,在application.properties中,我通过执行以下操作启用了显示基本身份验证失败的日志记录:

logging.level.org.springframework.security.web.authentication.www=DEBUG

This works fines and enabled the logs I expect to see.这很好用并启用了我希望看到的日志。 Then I checked if I could override the configuration above via log4j2.xml by including:然后我检查是否可以通过log4j2.xml覆盖上面的配置,包括:

<Logger name="org.springframework.security.web.authentication.www" level="ERROR" additivity="false">
    <AppenderRef ref="CONSOLE"/>
</Logger>

The change in log4j2.xml did not cause any effect. log4j2.xml中的更改没有造成任何影响。 So my impression is that the logging configuration included in applications.properties takes priority over log4j2.xml (or it is read after).所以我的印象是applications.properties中包含的日志记录配置优先于log4j2.xml (或之后读取)。 The only note I can see in the documentation that may be related is:我在文档中看到的唯一可能相关的注释是:

Since logging is initialized before the ApplicationContext is created, it is not possible to control logging from @PropertySources in Spring @Configuration files.由于日志记录是在创建 ApplicationContext 之前初始化的,因此无法控制来自 Spring @Configuration 文件中的 @PropertySources 的日志记录。 The only way to change the logging system or disable it entirely is through System properties.更改日志记录系统或完全禁用它的唯一方法是通过系统属性。

So my assumption is that the following will happen:所以我的假设是会发生以下情况:

  1. Logging is configured according to log4j2.xml .日志记录根据log4j2.xml配置。
  2. Spring loads the Application context and then the logging configuration in application.properties is taken and "wins". Spring 加载应用程序上下文,然后获取application.properties中的日志记录配置并“获胜”。

So my question is, if someone knows how this is supposed to work without guessing (a link will be appreciated).所以我的问题是,如果有人知道这应该如何工作而无需猜测(链接将不胜感激)。 NOTE: I am interested because I want to be sure that no log4j2.xml will disable the spring-security logging.注意:我很感兴趣,因为我想确保没有log4j2.xml会禁用 spring-security 日志记录。

Thanks in advance!提前致谢!

application.properties/application.yaml take precedence over log4j2.xml - search for precedence here application.properties/application.yaml 优先于 log4j2.xml - 在此处搜索优先级

Environment variables take precedence over application.properties/application.yaml环境变量优先于 application.properties/application.yaml

A fuller precedence list is here更完整的优先级列表在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM