[MNG-8512] Fix org.slf4j.simpleLogger.defaultLogLevel Configuration conflict#2042
[MNG-8512] Fix org.slf4j.simpleLogger.defaultLogLevel Configuration conflict#2042CrazyHZM merged 1 commit intoapache:masterfrom
Conversation
elharo
left a comment
There was a problem hiding this comment.
I know it's tricky with system properties, but anyway this can be tested? Maybe with an IT?
Also, rerun the failing CI suite. It's known flaky.
| String current = System.getProperty(defaultLogLevelKey); | ||
| if (current == null) { | ||
| System.setProperty(defaultLogLevelKey, value); | ||
| } else { |
There was a problem hiding this comment.
what if the levels are the same? Then there shouldn't be a warning.
There was a problem hiding this comment.
When the value is the same, It doesn't cause -Dorg slf4j.SimpleLogger.DefaultLogLevel configuration affects the maven command line configuration failure.
@elharo
There was a problem hiding this comment.
I'm not sure I follow. Can you rephrase?
There was a problem hiding this comment.
For example, we run the command mvn clean install -Dorg slf4j.SimpleLogger.DefaultLogLevel -X, it will lead to effective -X, and -Dorgslf4j.SimpleLogger.DefaultLogLevel failure (I think I said against the above)
There was a problem hiding this comment.
You're probably correct, but I do not understand what you are saying.
There was a problem hiding this comment.
➜ maven git:(feat/MNG-8512) ✗ ~/work/git/maven/apache-maven/target/apache-maven-4.0.0-rc-3-SNAPSHOT/bin/mvn -X -Dorg.slf4j.simpleLogger.defaultLogLevel=debug
[WARNING] System property 'org.slf4j.simpleLogger.defaultLogLevel' is already set to 'debug' - ignoring log level from -X/-e/-q options
Apache Maven 4.0.0-rc-3-SNAPSHOT (cc9dc285f04d254e786b9e727ebea1d368bca400)
...
I think what @elharo means is that we don't want to print a warning if we're using -X and the system property is already set to the correct value.
There was a problem hiding this comment.
Maybe we should compare and use the lowest level ? And simply ignore if the two values are the same?
There was a problem hiding this comment.
Actually, I'm not sure we want user properties to take precedence over CLI options.
We use the same behavior for color for example:
There was a problem hiding this comment.
Yes, you're right. That could be done in a single call as System.setProperty returns the previous value. So we could check and if non null and different from the new value, log something at info level.
impl/maven-cli/src/main/java/org/apache/maven/cling/logging/impl/MavenSimpleConfiguration.java
Outdated
Show resolved
Hide resolved
41a3ff3 to
cc9dc28
Compare
| String current = System.getProperty(defaultLogLevelKey); | ||
| if (current == null) { | ||
| System.setProperty(defaultLogLevelKey, value); | ||
| } else { |
There was a problem hiding this comment.
I'm not sure I follow. Can you rephrase?
| System.setProperty(defaultLogLevelKey, value); | ||
| } else { | ||
| LOGGER.warn( | ||
| "System property '{}' is already set to '{}' - ignoring log level from -X/-e/-q options", |
There was a problem hiding this comment.
should we specify what the log level that's being ignored is? that is, add a third parameter?
Also, it's really easy to mix parameters up. Simple string concatenation is preferable.
There was a problem hiding this comment.
No third parameter is added here, but now some Maven command-line parameters and the slf4j configuration conflict. I agree that the concatenation is better, but automatic formatting by IDEA is uncomfortable.
There was a problem hiding this comment.
Use mvn spotless:apply and it should fix anything IntelliJ does wrong. And you can always edit in vi or whatever plain text editor you prefer.
impl/maven-cli/src/main/java/org/apache/maven/cling/logging/impl/MavenSimpleConfiguration.java
Outdated
Show resolved
Hide resolved
2928669 to
dfb1acc
Compare
| }; | ||
| System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", value); | ||
|
|
||
| String current = System.getProperty(MavenSimpleLogger.DEFAULT_LOG_LEVEL_KEY); |
There was a problem hiding this comment.
| String current = System.getProperty(MavenSimpleLogger.DEFAULT_LOG_LEVEL_KEY); | |
| String current = System.setProperty(MavenSimpleLogger.DEFAULT_LOG_LEVEL_KEY, value); | |
| if (current != null && !value.equalsIgnoreCase(current)) { |
There was a problem hiding this comment.
Does this logically seem to be maven command options taking precedence over slf4j config?
@gnodet
There was a problem hiding this comment.
Yes, a CLI option seems more explicit to me that a value from system properties. CLI options are usually set by the user for a given invocation, while system properties can come from various sources (also from CLI, that's right).
I think this would be in line with the example I pasted a few days ago:
String styleColor = mavenOptions
.color()
.orElse(userProperties.getOrDefault(
Constants.MAVEN_STYLE_COLOR_PROPERTY, userProperties.getOrDefault("style.color", "auto")));
where the color option comes first from the CLI options, then user properties (in that case, we have the new, then the legacy property).
There was a problem hiding this comment.
The log msg also needs to be adjusted.
…onflict Signed-off-by: crazyhzm <[email protected]>
dfb1acc to
dc4328b
Compare
|
@CrazyHZM feel free to squash/merge this PR. |
|
Resolve #9377 |
JIRA issue: MNG-8512