简体   繁体   English

将 AEM 6.4 之间的依赖关系更新为 6.5 后,单元测试日志级别更改为 DEBUG

[英]Unit test log level changes to DEBUG after updating dependencies between AEM 6.4 to 6.5

I have a project generated a couple of years ago, based on the AEM Project Archetype, that is currently using AEM 6.4 and getting upgraded to AEM 6.5.我有一个几年前生成的项目,该项目基于 AEM Project Archetype,目前使用 AEM 6.4 并正在升级到 AEM 6.5。

<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.5.10</version>
    <scope>provided</scope>
</dependency>

After upgrading the AEM uber jar dependency from 6.4.8.2 to 6.5.10, we started seeing lots of DEBUG level messages printed in the console while tests, specifically ones based on the Sling Testing library, are executed.将 AEM uber jar 依赖项从 6.4.8.2 升级到 6.5.10 后,我们开始看到在执行测试(特别是基于Sling 测试库的测试)时控制台中打印出大量 DEBUG 级别消息。 Apparently, all of them pertain to registering adapters for the purpose of mocking Sling.显然,它们都与为 mocking Sling 注册适配器有关。

14:36:32.141 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.SlingHttpServletRequest] and adapters : [com.example.XXXXXXX]
14:36:32.146 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.resource.Resource] and adapters : [com.example.XXXXXXX]
14:36:32.151 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.resource.Resource] and adapters : [com.adobe.acs.commons.workflow.bulk.execution.model.Config]
14:36:32.155 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.resource.Resource] and adapters : [com.example.XXXXXXX]
14:36:32.158 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.resource.Resource] and adapters : [com.adobe.cq.wcm.core.components.models.form.Button, com.adobe.cq.export.json.ComponentExporter]
14:36:32.159 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.resource.Resource] and adapters : [com.example.XXXXXXX]
14:36:32.160 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.resource.Resource] and adapters : [com.adobe.acs.commons.reports.models.QueryReportConfig]
14:36:32.161 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.resource.Resource, org.apache.sling.api.SlingHttpServletRequest] and adapters : [com.example.XXXXXXX]
14:36:32.165 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.SlingHttpServletRequest] and adapters : [com.adobe.cq.wcm.core.components.models.form.Text, com.adobe.cq.export.json.ComponentExporter]
14:36:32.165 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.resource.Resource] and adapters : [com.example.XXXXXXX]
14:36:32.167 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.resource.Resource] and adapters : [com.example.XXXXXXX]
14:36:32.168 [main] DEBUG org.apache.sling.testing.mock.sling.MockAdapterManagerImpl - Registered service org.apache.sling.adapter.Adaption with adaptables : [org.apache.sling.api.SlingHttpServletRequest] and adapters : [com.adobe.cq.wcm.core.components.models.form.Field, com.adobe.cq.export.json.ComponentExporter]
... and it goes on

At first, I thought this was happening because of a new SLF4J binding appearing on the classpath .起初,我认为这是因为类路径上出现了一个新的 SLF4J 绑定 The output does mention this being a problem. output 确实提到这是一个问题。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/foo/.m2/repository/com/adobe/aem/uber-jar/6.5.10/uber-jar-6.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/foo/.m2/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/foo/.m2/repository/uk/org/lidalia/slf4j-test/1.0.1/slf4j-test-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

However, I've managed to get this warning to disappear by excluding different versions of SLF4J in the pom, and the DEBUG-level logging is still there.但是,我已经通过在 pom 中排除不同版本的 SLF4J 设法使此警告消失,并且 DEBUG 级别的日志记录仍然存在。

I've also generated a fresh AEM 6.5 project based on the Archetype and I can't reproduce the issue, despite multiple bindings being found.我还基于原型生成了一个新的 AEM 6.5 项目,尽管发现了多个绑定,但我无法重现该问题。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/foo/.m2/repository/uk/org/lidalia/slf4j-test/1.0.1/slf4j-test-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/foo/.m2/repository/com/adobe/aem/uber-jar/6.5.10/uber-jar-6.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [uk.org.lidalia.slf4jtest.TestLoggerFactory]

One thing I've noticed is that as soon as I use the 6.5 jar, the type of the binding actually used becomes different.我注意到的一件事是,一旦我使用 6.5 jar,实际使用的绑定类型就会变得不同。 In the fresh new project, it's uk.org.lidalia.slf4jtest.TestLoggerFactory and in my actual project, it's ch.qos.logback.classic.util.ContextSelectorStaticBinder , which does appear to be coming from the Uber Jar (I can see the class inside it)在全新的项目中,它是uk.org.lidalia.slf4jtest.TestLoggerFactory在我的实际项目中,它是ch.qos.logback.classic.util.ContextSelectorStaticBinder ,它似乎来自 Uber Jar(我可以看到class 里面)

检查 IntelliJ 中的 uber jar,显示包含 ContextSeletorStaticBinder 类

This class seems to be just added to the archive, rather than as a transitive dependency so I can't find a way to exclude it.这个 class 似乎只是添加到存档中,而不是作为传递依赖项,所以我找不到排除它的方法。

Changing the Uber Jar version back from 6.5.10 to 6.4.8.4, with no other changes to the codebase or dependencies, causes the unit tests to stop printing these DEBUG level messages.将 Uber Jar 版本从 6.5.10 改回 6.4.8.4,而不对代码库或依赖项进行其他更改,导致单元测试停止打印这些 DEBUG 级别消息。

I've tried adding https://wcm.io/testing/logging/logback/ and https://github.com/apache/sling-org-apache-sling-testing-logging-mock as dependencies but this also doesn't seem to help.我尝试添加https://wcm.io/testing/logging/logback/https://github.com/apache/sling-org-apache-sling-testing-logging-mock作为依赖项,但这也没有似乎没有帮助。

What controls this log level and how does changing the uber-jar alter it?什么控制这个日志级别以及更改 uber-jar 如何改变它?

Adding the following dependency fixed the issue for us.添加以下依赖项为我们解决了这个问题。

<dependency>
    <groupId>io.wcm</groupId>
    <artifactId>io.wcm.testing.logging.logback</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

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

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