logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

LOG4J2-3193 Configuration precedence fix

Open david-burke-securian opened this issue 3 years ago • 8 comments

For https://issues.apache.org/jira/browse/LOG4J2-3193

I can't get the project to build locally, even with a clean copy of master. I will work on that (could be user error--I have more experience with Gradle than Maven) and I also intend to add unit tests for my change.

david-burke-securian avatar Nov 22 '21 22:11 david-burke-securian

You are on the master branch. That requires Java 11 (it may work with later versions as well, I haven't tried). In addition, the build currently only works from the command line. Just run "mvn clean install".

rgoers avatar Nov 22 '21 22:11 rgoers

Is master the correct branch to base this PR on?

When I build on a clean copy of master with ./mvnw clean install on Java 11, I get:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for org.apache.logging.log4j:log4j-jakarta-web:2.15.0-SNAPSHOT: Could not find artifact org.apache.logging.log4j:log4j:pom:2.15.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 20, column 11
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project org.apache.logging.log4j:log4j-jakarta-web:2.15.0-SNAPSHOT (C:\appdev\repos\public\logging-log4j2\log4j-jakarta-web\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for org.apache.logging.log4j:log4j-jakarta-web:2.15.0-SNAPSHOT: Could not find artifact org.apache.logging.log4j:log4j:pom:2.15.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 20, column 11 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

If I update log4j-jakarta-web/pom.xml like so:

     <parent>
       <artifactId>log4j</artifactId>
       <groupId>org.apache.logging.log4j</groupId>
  -    <version>2.15.0-SNAPSHOT</version>
  +    <version>3.0.0-SNAPSHOT</version>
     </parent>

Then I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project log4j-api: Compilation failure -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :log4j-api

david-burke-securian avatar Nov 23 '21 13:11 david-burke-securian

@david-burke-securian, if you are fixing a problem in the Log4j 2, you better target release-2.x branch. Building release-2.x is kind of a hassle due to the JPMS integration. I'd advise you do practice the following steps:

  1. Make sure you have two JDKs installed in your system: 8 and 9+ (11, 17, etc.)
  2. Make sure you have a working ~/.m2/toolchains.xml. (See the root of Log4j project for sample files.)
  3. Run ./mvnw clean package -DskipTests in the root directory of the project. Note that you must run this command using JDK 8 in release-2.x branch! The modules requiring JDK 9+ will access to that JDK using your toolchains.xml.

Let me repeat again: run ./mvnw using JDK 8!

vy avatar Nov 23 '21 19:11 vy

Thanks. This is my fault. I applied a PR that was targeted to the release-2.x branch to master and forgot to change the version when I did. I would have caught the compile errors had I done that.

I have fixed the problems and pushed them to master so your build should now work.

Ralph

On Nov 23, 2021, at 6:58 AM, david-burke-securian @.***> wrote:

Is master the correct branch to base this PR on?

When I build on a clean copy of master with ./mvnw clean install on Java 11, I get:

[INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for org.apache.logging.log4j:log4j-jakarta-web:2.15.0-SNAPSHOT: Could not find artifact org.apache.logging.log4j:log4j:pom:2.15.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 20, column 11 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project org.apache.logging.log4j:log4j-jakarta-web:2.15.0-SNAPSHOT (C:\appdev\repos\public\logging-log4j2\log4j-jakarta-web\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for org.apache.logging.log4j:log4j-jakarta-web:2.15.0-SNAPSHOT: Could not find artifact org.apache.logging.log4j:log4j:pom:2.15.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 20, column 11 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException If I update log4j-jakarta-web/pom.xml like so:

 <parent>
   <artifactId>log4j</artifactId>
   <groupId>org.apache.logging.log4j</groupId>
  • 2.15.0-SNAPSHOT
  • 3.0.0-SNAPSHOT Then I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project log4j-api: Compilation failure -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn -rf :log4j-api — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apache/logging-log4j2/pull/601#issuecomment-976574629, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5MX4R27C4KENMZXODEB3UNOMYHANCNFSM5ISCLCXQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

rgoers avatar Nov 24 '21 05:11 rgoers

@rgoers @vy Thanks! I got my build working on both master and release-2.x branches. I am fixing a problem in Log4j2 and ideally I'd like it released in a 2.x.x version so I rebased on release-2.x and updated this PR to target that. I'll try to write some tests and then this should be ready to go.

david-burke-securian avatar Nov 24 '21 15:11 david-burke-securian

I think this is ready to go. A couple notes:

In the JIRA issue I talked about updating the TreeSet in PropertiesUtil.Environment (using Comparator.reverse()), but since that appears to be the only place that PropertySource.Comparator is used, I decided it seemed like a better idea to reverse the behavior of the comparator itself to more accurately reflect the order of precedence for PropertySources. Happy to do it the other way if you disagree.

Also, the unit test for the PropertiesUtil change doesn't really test the change I made. As far as I can tell my change is untestable because you can't set environment variables from within a test. I added the test anyway because it seemed like a good way to demonstrate/validate the flexibility of the 'get' methods on PropertiesUtil. If there's a better way to test, let me know.

I can verify that this build fixed the problem in my project that prompted me to open a ticket.

david-burke-securian avatar Nov 25 '21 05:11 david-burke-securian

To test environment variables in JUnit you can do something like:

  @Rule
  public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
  
    @Before
  public void setUp() throws Exception {
    environmentVariables.set("NC_PORT", NC_PORT);
  }

rgoers avatar Nov 30 '21 05:11 rgoers

@rgoers Is that from system-rules? That seems to be for JUnit 4 and isn't a current dependency of the project. I can add it if you think it will work, but if we're adding a dependency then system-lambda might be a better choice for Java 8 and JUnit 5. What do you think?

david-burke-securian avatar Nov 30 '21 13:11 david-burke-securian

I am closing this since #742 refactored the property caching code and also fixed property priority.

ppkarwasz avatar Jan 16 '23 05:01 ppkarwasz