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

refactor: use slf4j API instead of log4j-api #3755

Merged
merged 5 commits into from
Jan 19, 2021
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
15 changes: 5 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,13 @@
<artifactId>jsap</artifactId>
<version>2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<!-- doc: https://logging.apache.org/log4j/2.0/faq.html -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
Expand Down
20 changes: 1 addition & 19 deletions spoon-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</repositories>

<dependencies>

<!-- we all depend on Junit with scope=test -->
<dependency>
<groupId>org.junit.vintage</groupId>
Expand Down Expand Up @@ -102,24 +102,6 @@

<build>
<defaultGoal>clean install</defaultGoal>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>log4j.properties</include>
</includes>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/spoon/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.event.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.SpoonModelBuilder.InputType;
import spoon.compiler.Environment;
import spoon.compiler.SpoonResource;
Expand All @@ -46,6 +46,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -540,7 +541,7 @@ protected void processArguments() {

protected void reportClassPathMode() {
String cpmode = jsapActualArgs.getString("cpmode").toUpperCase();
Launcher.LOGGER.info("Running in " + cpmode + " mode (doc: http://spoon.gforge.inria.fr/launcher.html).");
factory.getEnvironment().report(null, Level.INFO, "Running in " + cpmode + " mode (doc: http://spoon.gforge.inria.fr/launcher.html).");
}

/**
Expand Down Expand Up @@ -591,7 +592,7 @@ protected JSAPResult parseArgs() {
/**
* A default logger to be used by Spoon.
*/
public static final Logger LOGGER = LogManager.getLogger();
public static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

/**
* Creates a new Spoon Java compiler in order to process and compile Java
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/spoon/MavenLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/
package spoon;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.support.compiler.SpoonPom;

import java.io.File;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.regex.Pattern;

Expand All @@ -23,7 +24,7 @@ public class MavenLauncher extends Launcher {
private SOURCE_TYPE sourceType;
private SpoonPom model;
private boolean forceRefresh = false;
private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

/**
* @return SpoonPom corresponding to the pom file used by the launcher
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/compiler/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package spoon.compiler;

import org.apache.logging.log4j.Level;
import org.slf4j.event.Level;
import spoon.OutputType;
import spoon.compiler.builder.EncodingProvider;
import spoon.processing.FileGenerator;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/processing/AbstractProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package spoon.processing;

import org.apache.logging.log4j.Level;
import org.slf4j.event.Level;
import spoon.Launcher;
import spoon.compiler.Environment;
import spoon.reflect.declaration.CtElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
package spoon.reflect.visitor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.SpoonException;
import spoon.compiler.Environment;
import spoon.experimental.CtUnresolvedImport;
Expand Down Expand Up @@ -120,6 +120,7 @@
import spoon.support.util.ModelList;

import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -244,7 +245,7 @@ public DefaultJavaPrettyPrinter setLineSeparator(String lineSeparator) {
}


protected static final Logger LOGGER = LogManager.getLogger();
protected static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String ERROR_MESSAGE_TO_STRING = "Error in printing the node. One parent isn't initialized!";
/**
* Prints an element. This method shall be called by the toString() method of an element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package spoon.reflect.visitor;

import org.apache.logging.log4j.Level;
import org.slf4j.event.Level;
import spoon.compiler.Environment;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtNamedElement;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/support/RuntimeProcessingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package spoon.support;

import org.apache.logging.log4j.Level;
import org.slf4j.event.Level;
import spoon.processing.ProcessInterruption;
import spoon.processing.ProcessingManager;
import spoon.processing.Processor;
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/spoon/support/StandardEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
package spoon.support;


import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.slf4j.event.Level;
import org.slf4j.Logger;
import spoon.Launcher;
import spoon.OutputType;
import spoon.SpoonException;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void setPrettyPrintingMode(PRETTY_PRINTING_MODE prettyPrintingMode) {

private transient Logger logger = Launcher.LOGGER;

private Level level = Level.OFF;
private Level level = Level.ERROR;

private boolean shouldCompile = false;

Expand Down Expand Up @@ -193,7 +193,13 @@ private Level toLevel(String level) {
if (level == null || level.isEmpty()) {
throw new SpoonException("Wrong level given at Spoon.");
}
return Level.toLevel(level, Level.ALL);
Level levelEnum;
try {
levelEnum = Level.valueOf(level);
} catch (IllegalArgumentException e) {
return Level.TRACE;
}
return levelEnum;
}

@Override
Expand Down Expand Up @@ -273,8 +279,18 @@ public void report(Processor<?> processor, Level level, String message) {
}

private void print(String message, Level messageLevel) {
if (messageLevel.isMoreSpecificThan(this.level)) {
logger.log(messageLevel, message);
if (messageLevel.toInt() >= this.level.toInt()) {
switch (messageLevel) {
case ERROR: logger.error(message);
break;
case WARN: logger.warn(message);
break;
case INFO: logger.info(message);
break;
case DEBUG: logger.debug(message);
break;
case TRACE: logger.trace(message);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/support/compiler/SpoonPom.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package spoon.support.compiler;

import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package spoon.support.compiler.jdt;

import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Level;
import org.slf4j.event.Level;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
package spoon.support.compiler.jdt;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import spoon.SpoonException;
Expand Down Expand Up @@ -61,6 +61,7 @@
import java.io.Reader;
import java.io.StringReader;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -71,7 +72,7 @@
*/
public class JDTCommentBuilder {

private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private final CompilationUnitDeclaration declarationUnit;
private CompilationUnit spoonUnit;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
package spoon.support.compiler.jdt;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression;
Expand Down Expand Up @@ -113,6 +112,7 @@
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.VariableBinding;
import org.slf4j.LoggerFactory;
import spoon.SpoonException;
import spoon.reflect.code.BinaryOperatorKind;
import spoon.reflect.code.CtArrayAccess;
Expand Down Expand Up @@ -159,6 +159,8 @@
import spoon.support.compiler.jdt.ContextBuilder.CastInfo;
import spoon.support.reflect.CtExtendedModifier;

import java.lang.invoke.MethodHandles;

import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.getBinaryOperatorKind;
import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.getModifiers;
import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.getUnaryOperator;
Expand Down Expand Up @@ -187,7 +189,7 @@ public static Logger getLogger() {
return LOGGER;
}

private static final Logger LOGGER = LogManager.getLogger();
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public PositionBuilder getPositionBuilder() {
return position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
package spoon.support.reflect.declaration;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spoon.reflect.ModelElementContainerDefaultCapacities;
import spoon.reflect.annotations.MetamodelPropertyField;
import spoon.reflect.code.CtBlock;
Expand Down Expand Up @@ -57,6 +57,7 @@

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -74,7 +75,7 @@
*/
public abstract class CtElementImpl implements CtElement, Serializable {
private static final long serialVersionUID = 1L;
protected static final Logger LOGGER = LogManager.getLogger();
protected static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String ERROR_MESSAGE_TO_STRING = "Error in printing the node. One parent isn't initialized!";
private static final Factory DEFAULT_FACTORY = new FactoryImpl(new DefaultCoreFactory(), new StandardEnvironment());

Expand Down
16 changes: 0 additions & 16 deletions src/main/resources/log4j.properties

This file was deleted.

Loading