forked from phoedos/pmd
Downgrade slf4j to 1.7.36
This commit is contained in:
@ -239,7 +239,7 @@ public class PMDTaskImpl {
|
||||
Slf4jSimpleConfiguration.installJulBridge();
|
||||
// need to reload the logger with the new configuration
|
||||
Logger log = LoggerFactory.getLogger(PMDTaskImpl.class);
|
||||
log.atLevel(level).log("Logging is at {}", level);
|
||||
log.info("Logging is at {}", level);
|
||||
try {
|
||||
doTask();
|
||||
} finally {
|
||||
|
@ -5,20 +5,17 @@
|
||||
package net.sourceforge.pmd.internal;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.LoggerFactoryFriend;
|
||||
import org.slf4j.PmdLoggerFactoryFriend;
|
||||
import org.slf4j.bridge.SLF4JBridgeHandler;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
public final class Slf4jSimpleConfiguration {
|
||||
private static final String SIMPLE_LOGGER_FACTORY_CLASS = "org.slf4j.simple.SimpleLoggerFactory";
|
||||
private static final String SIMPLE_LOGGER_CLASS = "org.slf4j.simple.SimpleLogger";
|
||||
private static final String SIMPLE_LOGGER_FACTORY_CLASS = "org.slf4j.impl.SimpleLoggerFactory";
|
||||
private static final String SIMPLE_LOGGER_CLASS = "org.slf4j.impl.SimpleLogger";
|
||||
|
||||
private Slf4jSimpleConfiguration() { }
|
||||
|
||||
@ -43,22 +40,39 @@ public final class Slf4jSimpleConfiguration {
|
||||
Method initMethod = simpleLoggerClass.getDeclaredMethod("init");
|
||||
initMethod.setAccessible(true);
|
||||
initMethod.invoke(null);
|
||||
|
||||
// Call SimpleLoggerFactory.reset() by reflection.
|
||||
Method resetMethod = loggerFactoryClass.getDeclaredMethod("reset");
|
||||
resetMethod.setAccessible(true);
|
||||
resetMethod.invoke(loggerFactory);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
System.err.println("Error while initializing logging: " + ex);
|
||||
}
|
||||
|
||||
LoggerFactoryFriend.reset();
|
||||
PmdLoggerFactoryFriend.reset();
|
||||
}
|
||||
|
||||
public static Level getDefaultLogLevel() {
|
||||
Logger rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||
List<Level> enabledLogLevels = Arrays.asList(Level.values()).stream()
|
||||
.filter(rootLogger::isEnabledForLevel).collect(Collectors.toList());
|
||||
if (enabledLogLevels.isEmpty()) {
|
||||
|
||||
// check the lowest log level first
|
||||
if (rootLogger.isTraceEnabled()) {
|
||||
return Level.TRACE;
|
||||
}
|
||||
if (rootLogger.isDebugEnabled()) {
|
||||
return Level.DEBUG;
|
||||
}
|
||||
if (rootLogger.isInfoEnabled()) {
|
||||
return Level.INFO;
|
||||
}
|
||||
// return the lowest (last) level
|
||||
return enabledLogLevels.get(enabledLogLevels.size() - 1);
|
||||
if (rootLogger.isWarnEnabled()) {
|
||||
return Level.WARN;
|
||||
}
|
||||
if (rootLogger.isErrorEnabled()) {
|
||||
return Level.ERROR;
|
||||
}
|
||||
|
||||
return Level.INFO;
|
||||
}
|
||||
|
||||
public static void disableLogging(Class<?> clazz) {
|
||||
|
@ -83,7 +83,25 @@ public interface SemanticErrorReporter {
|
||||
|
||||
private String logMessage(Level level, Node location, String message, Object[] args) {
|
||||
String fullMessage = makeMessage(location, message, args);
|
||||
logger.atLevel(level).log(fullMessage);
|
||||
switch (level) {
|
||||
case ERROR:
|
||||
logger.error(fullMessage);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(fullMessage);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(fullMessage);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(fullMessage);
|
||||
break;
|
||||
case TRACE:
|
||||
logger.trace(fullMessage);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Invalid log level: " + level);
|
||||
}
|
||||
return fullMessage;
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,42 @@ public class SimpleMessageReporter extends MessageReporterBase implements Messag
|
||||
|
||||
@Override
|
||||
protected boolean isLoggableImpl(Level level) {
|
||||
return backend.isEnabledForLevel(level);
|
||||
switch (level) {
|
||||
case ERROR:
|
||||
return backend.isErrorEnabled();
|
||||
case WARN:
|
||||
return backend.isWarnEnabled();
|
||||
case INFO:
|
||||
return backend.isInfoEnabled();
|
||||
case DEBUG:
|
||||
return backend.isDebugEnabled();
|
||||
case TRACE:
|
||||
return backend.isTraceEnabled();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logImpl(Level level, String message, Object[] formatArgs) {
|
||||
backend.atLevel(level).log(message, formatArgs);
|
||||
switch (level) {
|
||||
case ERROR:
|
||||
backend.error(message, formatArgs);
|
||||
break;
|
||||
case WARN:
|
||||
backend.warn(message, formatArgs);
|
||||
break;
|
||||
case INFO:
|
||||
backend.info(message, formatArgs);
|
||||
break;
|
||||
case DEBUG:
|
||||
backend.debug(message, formatArgs);
|
||||
break;
|
||||
case TRACE:
|
||||
backend.trace(message, formatArgs);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Invalid log level: " + level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
pmd-core/src/main/java/org/slf4j/PmdLoggerFactoryFriend.java
Normal file
26
pmd-core/src/main/java/org/slf4j/PmdLoggerFactoryFriend.java
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package org.slf4j;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
|
||||
/**
|
||||
* This class is for internal use only.
|
||||
* <p>
|
||||
* It is needed to reinitialize the underlying logging in case the configuration is changed.
|
||||
* </p>
|
||||
* @deprecated internal, do not use
|
||||
*/
|
||||
@Deprecated
|
||||
@InternalApi
|
||||
public final class PmdLoggerFactoryFriend {
|
||||
private PmdLoggerFactoryFriend() {
|
||||
// helper
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
LoggerFactory.reset();
|
||||
}
|
||||
}
|
@ -195,19 +195,22 @@ public class CoreCliTest {
|
||||
|
||||
@Test
|
||||
public void debugLogging() {
|
||||
runPmdSuccessfully("--debug", "--no-cache", "--dir", srcDir, "--rulesets", DUMMY_RULESET);
|
||||
Path reportFile = tempRoot().resolve("out/reportFile.txt");
|
||||
runPmdSuccessfully("--debug", "--no-cache", "--dir", srcDir, "--rulesets", DUMMY_RULESET, "-r", reportFile);
|
||||
assertThat(errStreamCaptor.getLog(), containsString("[main] INFO net.sourceforge.pmd.PMD - Log level is at TRACE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultLogging() {
|
||||
runPmdSuccessfully("--no-cache", "--dir", srcDir, "--rulesets", DUMMY_RULESET);
|
||||
Path reportFile = tempRoot().resolve("out/reportFile.txt");
|
||||
runPmdSuccessfully("--no-cache", "--dir", srcDir, "--rulesets", DUMMY_RULESET, "-r", reportFile);
|
||||
assertThat(errStreamCaptor.getLog(), containsString("[main] INFO net.sourceforge.pmd.PMD - Log level is at INFO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecatedRulesetSyntaxOnCommandLine() {
|
||||
runPmd(StatusCode.VIOLATIONS_FOUND, "--no-cache", "--dir", srcDir, "--rulesets", "dummy-basic");
|
||||
Path reportFile = tempRoot().resolve("out/reportFile.txt");
|
||||
runPmd(StatusCode.VIOLATIONS_FOUND, "--no-cache", "--dir", srcDir, "--rulesets", "dummy-basic", "-r", reportFile);
|
||||
MatcherAssert.assertThat(errStreamCaptor.getLog(), containsString("Ruleset reference 'dummy-basic' uses a deprecated form, use 'rulesets/dummy/basic.xml' instead"));
|
||||
}
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -98,7 +98,7 @@
|
||||
<ant.version>1.10.12</ant.version>
|
||||
<javadoc.plugin.version>3.2.0</javadoc.plugin.version>
|
||||
<antlr.version>4.8</antlr.version>
|
||||
<slf4j.version>2.0.0-alpha6</slf4j.version>
|
||||
<slf4j.version>1.7.36</slf4j.version>
|
||||
<saxon.version>10.7</saxon.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
Reference in New Issue
Block a user