Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AB-xdev committed Sep 26, 2024
1 parent 4ba1d84 commit d8ddb02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions src/main/java/software/xdev/saveactions/core/component/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,25 @@ public void processPsiFilesIfNecessary(
}
if(!this.storage.isEnabled(this.activation))
{
LOGGER.info(String.format("Action \"%s\" not enabled on %s", this.activation.getText(), this.project));
LOGGER.info(String.format(
"Action \"%s\" not enabled on %s",
this.activation.getText(),
this.project.getName()));
return;
}

indicator.setIndeterminate(true);
final Set<PsiFile> psiFilesEligible = this.getEligiblePsiFiles(indicator, async);
if(psiFilesEligible.isEmpty())
{
LOGGER.info("No files are eligible");
LOGGER.info("No files are eligible - " + this.project.getName());
return;
}

final List<SaveCommand> processorsEligible = this.getEligibleProcessors(indicator, psiFilesEligible);
if(processorsEligible.isEmpty())
{
LOGGER.info("No processors are eligible");
LOGGER.info("No processors are eligible - " + this.project.getName());
return;
}

Expand All @@ -105,7 +108,7 @@ public void processPsiFilesIfNecessary(

private Set<PsiFile> getEligiblePsiFiles(final @NotNull ProgressIndicator indicator, final boolean async)
{
LOGGER.info(String.format("Processing %s files %s mode %s", this.project, this.psiFiles, this.mode));
LOGGER.info(String.format("Processing %s files %s mode %s", this.project.getName(), this.psiFiles, this.mode));
indicator.checkCanceled();
indicator.setText2("Collecting files to process");

Expand All @@ -124,7 +127,7 @@ private Set<PsiFile> getEligiblePsiFiles(final @NotNull ProgressIndicator indica
final @NotNull ProgressIndicator indicator,
final Set<PsiFile> psiFilesEligible)
{
LOGGER.info(String.format("Start processors (%d)", this.processors.size()));
LOGGER.info(String.format("Start processors (%d) - %s", this.processors.size(), this.project.getName()));
indicator.checkCanceled();
indicator.setText2("Collecting processors");

Expand All @@ -142,7 +145,7 @@ private void flushPsiFiles(
final boolean async,
final Set<PsiFile> psiFilesEligible)
{
LOGGER.info(String.format("Flushing files (%d)", psiFilesEligible.size()));
LOGGER.info(String.format("Flushing files (%d) - %s", psiFilesEligible.size(), this.project.getName()));
indicator.checkCanceled();
indicator.setText2("Flushing files");

Expand Down Expand Up @@ -176,7 +179,11 @@ private void execute(
final AtomicInteger executedCount = new AtomicInteger();
final List<SimpleEntry<Action, Result<ResultCode>>> results = saveCommands.stream()
.map(command -> {
LOGGER.info(String.format("Execute command %s on %d files", command, psiFilesEligible.size()));
LOGGER.info(String.format(
"Execute command %s on %d files - %s",
command,
psiFilesEligible.size(),
this.project.getName()));

indicator.checkCanceled();
indicator.setText2("Executing '" + command.getAction().getText() + "'");
Expand All @@ -189,9 +196,12 @@ private void execute(
return entry;
})
.toList();
LOGGER.info(String.format("Exit engine with results %s", results.stream()
.map(entry -> entry.getKey() + ":" + entry.getValue())
.toList()));
LOGGER.info(String.format(
"Exit engine with results %s - %s",
results.stream()
.map(entry -> entry.getKey() + ":" + entry.getValue())
.toList(),
this.project.getName()));
}

private boolean isPsiFileEligible(final Project project, final PsiFile psiFile)
Expand All @@ -211,7 +221,7 @@ private boolean isProjectValid(final Project project)
final boolean valid = project.isInitialized() && !project.isDisposed();
if(!valid)
{
LOGGER.info("Project invalid. Either not initialized or disposed.");
LOGGER.info(String.format("Project %s invalid. Either not initialized or disposed", project.getName()));
}
return valid;
}
Expand Down Expand Up @@ -260,7 +270,7 @@ private boolean isPsiFileFresh(final PsiFile psiFile)
final boolean isFresh = psiFile.getModificationStamp() != 0;
if(!isFresh)
{
LOGGER.info(String.format("File %s is not fresh.", psiFile));
LOGGER.info(String.format("File %s is not fresh", psiFile));
}
return isFresh;
}
Expand All @@ -270,7 +280,7 @@ private boolean isPsiFileValid(final PsiFile psiFile)
final boolean valid = psiFile.isValid();
if(!valid)
{
LOGGER.info(String.format("File %s is not valid.", psiFile));
LOGGER.info(String.format("File %s is not valid", psiFile));
}
return valid;
}
Expand All @@ -280,7 +290,7 @@ private boolean hasPsiFileText(final PsiFile psiFile)
final boolean valid = psiFile.getTextRange() != null;
if(!valid)
{
LOGGER.info(String.format("File %s has no text.", psiFile));
LOGGER.info(String.format("File %s has no text", psiFile));
}
return valid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class InspectionRunnable implements Runnable
this.project = project;
this.psiFiles = psiFiles;
this.toolWrapper = new LocalInspectionToolWrapper(inspectionTool);
LOGGER.info(String.format("Running inspection for %s", inspectionTool.getShortName()));
LOGGER.info(String.format("Running inspection for %s - %s", inspectionTool.getShortName(), project.getName()));
}

@Override
Expand Down

0 comments on commit d8ddb02

Please sign in to comment.