Skip to content

Commit

Permalink
Resolve #703
Browse files Browse the repository at this point in the history
Fix logging configuration for CLI
  • Loading branch information
dfuchss committed Nov 8, 2022
1 parent 4a60a5e commit ba15aed
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
public final class CLI {

private static final Logger logger = LoggerFactory.getLogger("JPlag");
private static final Logger logger = LoggerFactory.getLogger(CLI.class);

private static final Random RANDOM = new SecureRandom();

Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/LanguageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Dominik Fuchss
*/
public final class LanguageLoader {
private static final Logger logger = LoggerFactory.getLogger("JPlag");
private static final Logger logger = LoggerFactory.getLogger(LanguageLoader.class);

private static Map<String, Language> cachedLanguageInstances = null;

Expand Down
11 changes: 10 additions & 1 deletion cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public final class CollectedLogger extends MarkerIgnoringBase {
private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;

/**
* The default log level that shall be used for external libraries (like Stanford Core NLP)
*/
private static final int LOG_LEVEL_FOR_EXTERNAL_LIBRARIES = LOG_LEVEL_ERROR;

private static final int CURRENT_LOG_LEVEL = LOG_LEVEL_INFO;

/**
Expand Down Expand Up @@ -117,7 +122,11 @@ private String computeShortName() {
}

private boolean isLevelEnabled(int logLevel) {
return logLevel >= CURRENT_LOG_LEVEL;
return isJPlagLog() ? logLevel >= CURRENT_LOG_LEVEL : logLevel >= LOG_LEVEL_FOR_EXTERNAL_LIBRARIES;
}

private boolean isJPlagLog() {
return this.name.startsWith("de.jplag.");
}

private String renderLevel(int level) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/de/jplag/options/JPlagOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<Fil
public static final SimilarityMetric DEFAULT_SIMILARITY_METRIC = SimilarityMetric.AVG;
public static final Charset CHARSET = StandardCharsets.UTF_8;

private static final Logger logger = LoggerFactory.getLogger(JPlag.class);
private static final Logger logger = LoggerFactory.getLogger(JPlagOptions.class);

public JPlagOptions(Language language, Set<File> submissionDirectories, Set<File> oldSubmissionDirectories) {
this(language, null, submissionDirectories, oldSubmissionDirectories, null, null, null, null, DEFAULT_SIMILARITY_METRIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import de.jplag.TokenType;

class MinimalCSharpTest {
private final Logger logger = LoggerFactory.getLogger("JPlag-Test");
private final Logger logger = LoggerFactory.getLogger(MinimalCSharpTest.class);

private static final Path BASE_PATH = Path.of("src", "test", "resources", "de", "jplag", "csharp");
private static final String TEST_SUBJECT = "TestClass.cs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import de.jplag.testutils.TokenUtils;

class MinimalDynamicMetamodelTest {
private final Logger logger = LoggerFactory.getLogger("JPlag-Test");
private final Logger logger = LoggerFactory.getLogger(MinimalDynamicMetamodelTest.class);

private static final Path BASE_PATH = Path.of("src", "test", "resources", "de", "jplag", "models");
private static final String[] TEST_SUBJECTS = {"bookStore.ecore", "bookStoreExtended.ecore", "bookStoreRenamed.ecore"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import de.jplag.testutils.TokenUtils;

class MinimalMetamodelTest {
private final Logger logger = LoggerFactory.getLogger("JPlag-Test");
private final Logger logger = LoggerFactory.getLogger(MinimalMetamodelTest.class);

private static final Path BASE_PATH = Path.of("src", "test", "resources", "de", "jplag", "models");
private static final String[] TEST_SUBJECTS = {"bookStore.ecore", "bookStoreExtended.ecore", "bookStoreRenamed.ecore"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GoLanguageTest {
*/
private static final String DELIMITED_COMMENT_END = ".*\\*/\\s*$";

private final Logger logger = LoggerFactory.getLogger("GoLang language test");
private final Logger logger = LoggerFactory.getLogger(GoLanguageTest.class);
private final String[] testFiles = new String[] {COMPLETE_TEST_FILE};
private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "golang").toFile();
private Language language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class KotlinLanguageTest {
*/
private static final String DELIMITED_COMMENT_END = ".*\\*/\\s*$";

private final Logger logger = LoggerFactory.getLogger("Kotlin language test");
private final Logger logger = LoggerFactory.getLogger(KotlinLanguageTest.class);
private final String[] testFiles = new String[] {COMPLETE_TEST_FILE, "Game.kt"};
private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "kotlin").toFile();
private Language language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RLanguageTest {
*/
private static final String COMPLETE_TEST_FILE = "Complete.R";

private final Logger logger = LoggerFactory.getLogger("R language test");
private final Logger logger = LoggerFactory.getLogger(RLanguageTest.class);
private final String[] testFiles = new String[] {"Game.R", COMPLETE_TEST_FILE};
private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "rlang").toFile();
private Language language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RustLanguageTest {
private static final double EPSILON = 1E-6;
public static final double BASELINE_COVERAGE = 0.75;

private final Logger logger = LoggerFactory.getLogger("Rust language test");
private final Logger logger = LoggerFactory.getLogger(RustLanguageTest.class);
private final String[] testFiles = new String[] {"deno_core_runtime.rs", COMPLETE_TEST_FILE};
private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "rust").toFile();
private Language language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ScalaLanguageTest {
private static final String DELIMITED_COMMENT_END = ".*\\*/\\s*$";
private static final double EPSILON = 1E-6;

private final Logger logger = LoggerFactory.getLogger("Scala language test");
private final Logger logger = LoggerFactory.getLogger(ScalaLanguageTest.class);
private final String[] testFiles = new String[] {"Parser.scala", COMPLETE_TEST_FILE};
private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "scala").toFile();
private Language language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SwiftFrontendTest {
*/
private static final String DELIMITED_COMMENT_END = ".*\\*/\\s*$";

private final Logger logger = LoggerFactory.getLogger("Swift frontend test");
private final Logger logger = LoggerFactory.getLogger(SwiftFrontendTest.class);
private final String[] testFiles = new String[] {COMPLETE_TEST_FILE};
private final File testFileLocation = Path.of("src", "test", "resources", "de", "jplag", "swift").toFile();
private Language language;
Expand Down
2 changes: 0 additions & 2 deletions languages/text/src/main/java/de/jplag/text/ParserAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.CoreDocument;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.logging.RedwoodConfiguration;

public class ParserAdapter extends AbstractParser {

Expand All @@ -34,7 +33,6 @@ public class ParserAdapter extends AbstractParser {
private int currentLineBreakIndex;

public ParserAdapter() {
RedwoodConfiguration.errorLevel().apply();
Properties properties = new Properties();
properties.put(ANNOTATORS_KEY, ANNOTATORS_VALUE);
this.pipeline = new StanfordCoreNLP(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import de.jplag.text.Language;

class TextLanguageTest {
private final Logger logger = LoggerFactory.getLogger("JPlag-Test");
private final Logger logger = LoggerFactory.getLogger(TextLanguageTest.class);

private static final Path BASE_PATH = Path.of("src", "test", "resources");
private static final String TEST_SUBJECT = "FutureJavaDoc.txt";
Expand Down

0 comments on commit ba15aed

Please sign in to comment.