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

Improve log readability and parse error reporting #1133

Merged
merged 3 commits into from
Jun 12, 2023
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
2 changes: 0 additions & 2 deletions cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ private void log(int level, String message, Throwable throwable, Date timeOfErro
// Append date-time
builder.append(dateFormat.format(timeOfError == null ? new Date() : timeOfError)).append(' ');

// Append current thread name
builder.append('[').append(Thread.currentThread().getName()).append("] ");
// Append current Level
builder.append('[').append(renderLevel(level)).append(']').append(' ');

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/de/jplag/JPlag.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.jplag;

import java.io.File;
import java.util.List;
import java.util.ResourceBundle;

import org.slf4j.Logger;
Expand Down Expand Up @@ -72,6 +74,19 @@ public static JPlagResult run(JPlagOptions options) throws ExitException {
if (logger.isInfoEnabled())
logger.info("Total time for comparing submissions: {}", TimeUtil.formatDuration(result.getDuration()));
result.setClusteringResult(ClusteringFactory.getClusterings(result.getAllComparisons(), options.clusteringOptions()));

logSkippedSubmissions(submissionSet, options);

return result;
}

private static void logSkippedSubmissions(SubmissionSet submissionSet, JPlagOptions options) {
List<Submission> skippedSubmissions = submissionSet.getInvalidSubmissions();
if (!skippedSubmissions.isEmpty()) {
logger.warn("{} submissions were skipped (see errors above): {}", skippedSubmissions.size(), skippedSubmissions);
if (options.debugParser()) {
logger.warn("Erroneous submissions were copied to {}", new File(JPlagOptions.ERROR_FOLDER).getAbsolutePath());
}
}
}
}
8 changes: 2 additions & 6 deletions core/src/main/java/de/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
import org.slf4j.LoggerFactory;

import de.jplag.normalization.TokenStringNormalizer;
import de.jplag.options.JPlagOptions;

/**
* Represents a single submission. A submission can contain multiple files.
*/
public class Submission implements Comparable<Submission> {
private static final Logger logger = LoggerFactory.getLogger(Submission.class);

/**
* Directory name for storing submission files with parse errors if so requested.
*/
private static final String ERROR_FOLDER = "errors";

/**
* Identification of the submission (often a directory or file name).
*/
Expand Down Expand Up @@ -226,7 +222,7 @@ private void copySubmission() {
}

private static File createErrorDirectory(String... subdirectoryNames) {
File subdirectory = Path.of(ERROR_FOLDER, subdirectoryNames).toFile();
File subdirectory = Path.of(JPlagOptions.ERROR_FOLDER, subdirectoryNames).toFile();
if (!subdirectory.exists()) {
subdirectory.mkdirs();
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/de/jplag/TimeUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.jplag;

import java.time.Duration;

public final class TimeUtil {

private TimeUtil() {
Expand All @@ -12,10 +14,8 @@ private TimeUtil() {
* @return Readable representation of the time interval.
*/
public static String formatDuration(long durationInMilliseconds) {
int timeInSeconds = (int) (durationInMilliseconds / 1000);
String hours = (timeInSeconds / 3600 > 0) ? (timeInSeconds / 3600) + " h " : "";
String minutes = (timeInSeconds / 60 > 0) ? ((timeInSeconds / 60) % 60) + " min " : "";
String seconds = (timeInSeconds % 60) + " sec";
return hours + minutes + seconds;
Duration duration = Duration.ofMillis(durationInMilliseconds);
return String.format("%dh %02dmin %02ds %03dms", duration.toHours(), duration.toMinutesPart(), duration.toSecondsPart(),
tsaglam marked this conversation as resolved.
Show resolved Hide resolved
duration.toMillisPart());
}
}
1 change: 1 addition & 0 deletions core/src/main/java/de/jplag/options/JPlagOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public record JPlagOptions(Language language, Integer minimumTokenMatch, Set<Fil
public static final int SHOW_ALL_COMPARISONS = 0;
public static final SimilarityMetric DEFAULT_SIMILARITY_METRIC = SimilarityMetric.AVG;
public static final Charset CHARSET = StandardCharsets.UTF_8;
public static final String ERROR_FOLDER = "errors";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* to the disk.
*/
public class ReportObjectFactory {
private static final String DIRECTORY_ERROR = "Could not create directory {} for report viewer generation";

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

private static final ToDiskWriter fileWriter = new ToDiskWriter();
Expand Down Expand Up @@ -76,7 +78,7 @@ public void createAndSaveReport(JPlagResult result, String path) {
logger.info("Zipping report files...");
zipAndDelete(path);
} catch (IOException e) {
logger.error("Could not create directory " + path + " for report viewer generation", e);
logger.error(DIRECTORY_ERROR, e, path);
}

}
Expand Down Expand Up @@ -130,7 +132,7 @@ private File createSubmissionDirectory(String path, File submissionsPath, Submis
try {
return createDirectory(submissionsPath.getPath(), submissionToIdFunction.apply(submission), file, submissionRoot);
} catch (IOException e) {
logger.error("Could not create directory " + path + " for report viewer generation", e);
logger.error(DIRECTORY_ERROR, e, path);
return null;
}
}
Expand All @@ -139,7 +141,7 @@ private File createSubmissionDirectory(String path, File submissionsPath, Submis
try {
return createDirectory(submissionsPath.getPath(), submissionToIdFunction.apply(submission));
} catch (IOException e) {
logger.error("Could not create directory " + path + " for report viewer generation", e);
logger.error(DIRECTORY_ERROR, e, path);
return null;
}
}
Expand All @@ -148,7 +150,7 @@ private File createSubmissionsDirectory(String path) {
try {
return createDirectory(path, SUBMISSIONS_FOLDER);
} catch (IOException e) {
logger.error("Could not create directory " + path + " for report viewer generation", e);
logger.error(DIRECTORY_ERROR, e, path);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public abstract class AbstractComparisonStrategy implements ComparisonStrategy {

private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Logger logger = LoggerFactory.getLogger(ComparisonStrategy.class);

private final GreedyStringTiling greedyStringTiling;

Expand All @@ -24,7 +24,6 @@ public abstract class AbstractComparisonStrategy implements ComparisonStrategy {
protected AbstractComparisonStrategy(JPlagOptions options, GreedyStringTiling greedyStringTiling) {
this.greedyStringTiling = greedyStringTiling;
this.options = options;
logger.info("Start comparing...");
}

/**
Expand Down