简体   繁体   English

使用 log4j 在 Wildfly 中启用 spring 安全性日志记录

[英]Enable logging of spring security in Wildfly with log4j

I would like to log anything related to Spring security (4.2.16) with Log4j.我想用 Log4j 记录与 Spring 安全性 (4.2.16) 相关的任何内容。

It is an EAR file deployed in Wildfly 10.1.0 with the log4j.xml deployed into WEB-INF/classes of a WAR file included in the EAR它是部署在 Wildfly 10.1.0 中的 EAR 文件,其中 log4j.xml 部署到 EAR 中包含的 WAR 文件的 WEB-INF/类中

log4.xml has the following category: log4.xml 有以下类别:

<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
    <param name="Threshold" value="debug" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern"
               value="%d{HH:mm:ss} %p [%t]:%c{3}.%M()%L - %m%n" />
    </layout>
</appender>

<category name="org.springframework.security" additivity="false">
    <priority value="TRACE" />
    <appender-ref ref="STDOUT"/>
</category>

Logs are printed for any of the project classes, but the Log4j configuration is not working for spring security.为任何项目类打印日志,但 Log4j 配置不适用于 spring 安全性。

After debugging, logger.isDebugEnabled() returns false in the AffirmativeBased class调试后 logger.isDebugEnabled() 在 AffirmativeBased class 中返回 false

How to get the logs for anything related to spring security?如何获取与 spring 安全相关的任何日志?

It seems (from what I have tested) that logging of third-party dependencies (at least, Spring) is not configured with the project's log4.xml but within Wildfly's logging subsystem.似乎(根据我的测试)第三方依赖项(至少是 Spring)的日志记录没有使用项目的 log4.xml 配置,而是在 Wildfly 的日志记录子系统中。

I have added the lines below to the standalone-full.xml (inside the logging subsystem definition) and it is logging now:我已将以下几行添加到standalone-full.xml(在日志子系统定义内),它现在正在记录:

<logger category="org.springframework.security">
  <level name="TRACE"/>
  <handlers>
    <handler name="CONSOLE"/>
  </handlers>
</logger>

I have not tried, but may work (and is as a better solution) to indicate in the EAR's jboss-deployment-structure.xml that the application excludes Wildfly's own logging subsystem and relies all logging (including third-party dependencies) to log4j.我没有尝试过,但可能有效(并且作为更好的解决方案)在 EAR 的 jboss-deployment-structure.xml 中表明该应用程序不包括 Wildfly 自己的日志记录子系统,并将所有日志记录(包括第三方依赖项)依赖于 log4j。 See Override logging in WildFly .请参阅覆盖 WildFly中的日志记录。

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

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