Skip to content

add log4j-core for test logging#3000

Merged
cshannon merged 4 commits intoapache:mainfrom
EdColeman:add_log4j_core_for_testing
Oct 7, 2022
Merged

add log4j-core for test logging#3000
cshannon merged 4 commits intoapache:mainfrom
EdColeman:add_log4j_core_for_testing

Conversation

@EdColeman
Copy link
Contributor

Updates to log4j versions require log4j-core to be present for test logging.

@dlmarion
Copy link
Contributor

dlmarion commented Oct 6, 2022

If you put this in the parent pom, in the dependencies section (not dependencyManagement), then I believe that each module will automatically inherit it. Just thinking that we could make the change in one place.

@EdColeman
Copy link
Contributor Author

Would the proper scope still be test - or is provided more appropriate - it needs to make it to the class paths for tests - not sure what is required for "normal" logging

@dlmarion
Copy link
Contributor

dlmarion commented Oct 6, 2022

I tested with the test scope, and that failed. The monitor needs it apparently. I'm testing now with the provided scope.

@dlmarion
Copy link
Contributor

dlmarion commented Oct 6, 2022

So, I added the following to the parent pom:

@@ -695,6 +695,13 @@
       <artifactId>spotbugs-annotations</artifactId>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <!-- needed because https://issues.apache.org/jira/browse/LOG4J2-3601 -->
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>

and removed the dependency declaration in assemble/pom.xml, core/pom.xml, and server/monitor/pom.xml. mvn clean package completed successfully, but log4j-core is not in the assembly (I assume it's supposed to be there for the monitor). So, the declaration in assemble/pom.xml may need to remain. Further tests are likely needed with this approach.

@EdColeman
Copy link
Contributor Author

What I first noticed was when running a test in an ide - the warning about it missing and using SimpleLogger was printed - but no logs showed up in the ide run pane

@dlmarion
Copy link
Contributor

dlmarion commented Oct 6, 2022

What I first noticed was when running a test in an ide - the warning about it missing and using SimpleLogger was printed - but no logs showed up in the ide run pane

Yes, I had the same issue in accumulo-classloaders yesterday. Adding log4j-core resolved the issue.

@EdColeman
Copy link
Contributor Author

Moving the declaration to main pom.xml with test scope seems to work for logging in the IDE and mvn clean package passed for me. To confirm the logging I used a single IT test - so not really comprehensive, but this seem to move us closer.

@dlmarion
Copy link
Contributor

dlmarion commented Oct 6, 2022

Did you mean to add log4j-slf4j2-impl to the main pom? I thought you were adding log4j-core ?

@EdColeman
Copy link
Contributor Author

log4j-slf4j2-impl was inadvertent - running a mvn clean now to see if that changes things.

test/pom.xml Outdated
Comment on lines 223 to 227
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be on the class path. It's brought in transitively through accumulo-monitor, and we shouldn't have any direct dependencies on it, only transitive runtime dependencies on it. The test module has a direct dependency on the accumulo-monitor.

Ultimately, this should be fixed by 2.19.1, which should re-add the transitive dependency for log4j-slf4j2-impl (https://issues.apache.org/jira/browse/LOG4J2-3601), but it hasn't been done yet, and some of the devs seemed confused about why they needed to fix that. So, I don't know when it will happen.

If this helps fix something during testing in an IDE, I'm fine with adding it. It's not going to hurt.

@cshannon
Copy link
Contributor

cshannon commented Oct 7, 2022

The current version of this change doesn't actually solve anything because as @ctubbsii pointed out the dependency is already transitive from accumulo-monitor. I can see the dependency is pulled in transitively both in Intellij and the command line and running tests from the test module from Intellij logging is working fine in the test module.

However, where I do see a problem is other modules. For example, running BulkImporterTest doesn't have logging as there is not longer a transitive dependency on log4j-core for server/base module.

I will go through and update the PR and push a commit to fix this.

Due to https://issues.apache.org/jira/browse/LOG4J2-3601 we need to add
log4j-core to all modules that have a test dependency on
log4j-slf4j2-impl, but not a dependency on accumulo-monitor, as
log4j-slf4j2-impl no longer has a runtime dependency on log4j-core.
@cshannon
Copy link
Contributor

cshannon commented Oct 7, 2022

This has been fixed with my latest commit. Essentially, due to the bug, we have to add a test scope dependency for log4j-core everywhere we already have a dependency for log4j-slf4j2-impl unless there is already a dependency on accumulo-monitor which pulls in log4j-core already. Notably, the test and accumulo-minicluster modules already pull in accumulo-monitor and don't need log4j-core.

@cshannon cshannon merged commit d2fd3d7 into apache:main Oct 7, 2022
@EdColeman EdColeman deleted the add_log4j_core_for_testing branch October 25, 2022 21:41
@ctubbsii ctubbsii added this to the 2.1.0 milestone Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants