Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8512] Fix org.slf4j.simpleLogger.defaultLogLevel Configuration conflict #2042

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import org.apache.maven.cling.logging.BaseSlf4jConfiguration;
import org.apache.maven.slf4j.MavenLoggerFactory;
import org.apache.maven.slf4j.MavenSimpleLogger;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
Expand All @@ -29,6 +31,8 @@
* @since 3.1.0
*/
public class MavenSimpleConfiguration extends BaseSlf4jConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(MavenSimpleConfiguration.class);

@Override
public void setRootLoggerLevel(Level level) {
String value =
Expand All @@ -37,7 +41,14 @@ public void setRootLoggerLevel(Level level) {
case INFO -> "info";
default -> "error";
};
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", value);

String current = System.setProperty(MavenSimpleLogger.DEFAULT_LOG_LEVEL_KEY, value);
if (current != null && !value.equalsIgnoreCase(current)) {
LOGGER.info(
"System property '" + MavenSimpleLogger.DEFAULT_LOG_LEVEL_KEY + "' is already set to '" + current
+ "' - ignoring system property and get log level from -X/-e/-q options, log level will be set to"
+ value);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.maven.logging.api.LogLevelRecorder;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

/**
* LogFactory for Maven which can create a simple logger or one which, if set, fails the build on a severity threshold.
*/
public class MavenLoggerFactory implements org.apache.maven.logging.api.LogLevelRecorder, ILoggerFactory {
public class MavenLoggerFactory implements LogLevelRecorder, ILoggerFactory {
final DefaultLogLevelRecorder logLevelRecorder = new DefaultLogLevelRecorder();
final ConcurrentMap<String, Logger> loggerMap = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class MavenSimpleLogger extends MavenBaseLogger {

static Consumer<String> logSink;

public static final String DEFAULT_LOG_LEVEL_KEY = "org.slf4j.simpleLogger.defaultLogLevel";

public static void setLogSink(Consumer<String> logSink) {
MavenSimpleLogger.logSink = logSink;
}
Expand Down
Loading