improve logging #18

Merged
kilian.schuettler1 merged 1 commits from improve-logging into main 2024-10-25 21:19:13 +02:00
5 changed files with 12 additions and 11 deletions

View File

@ -94,23 +94,24 @@ public class AsyncOcrService {
private static void handleCompleted(BatchContext batchContext) {
log.info("Completed : {}", batchContext.batch);
batchContext.supervisor.leaveConcurrency(batchContext.batch);
log.info("Completed batch {} with pages {}", batchContext.batch.getIndex(), batchContext.batch);
}
private void handleError(Throwable ex, BatchContext batchContext) {
batchContext.supervisor.leaveConcurrency(batchContext.batch);
batchContext.supervisor.logPageError(batchContext.batch, ex);
}
private void handleSuccessful(AnalyzeResult finalResult, BatchContext batchContext) {
batchContext.supervisor.leaveConcurrency(batchContext.batch);
try {
batchContext.supervisor.logPageSuccess(batchContext.batch());
if (settings.isDebug()) {
mapper.writeValue(batchContext.batch().getImagePipelineDir().resolve("azure_result_%d.json".formatted(batchContext.batch().getIndex())).toFile(), finalResult);
mapper.writeValue(batchContext.batch().getImagePipelineDir().resolve("azure_result_%d.json" .formatted(batchContext.batch().getIndex())).toFile(), finalResult);
}
batchContext.layerFactory.processAnalyzeResult(batchContext.batch(), finalResult);
} catch (Exception e) {

View File

@ -74,7 +74,7 @@ public class OcrExecutionSupervisor {
public void logUploadStart(PageBatch pageRange, long bytes) {
log.info("Start uploading pages {} with {}", pageRange, humanizeBytes(bytes));
log.info("Batch {}: Start uploading pages {} with {}", pageRange.getIndex(), pageRange, humanizeBytes(bytes));
statistics.getBatchStats(pageRange).start();
statistics.increaseTotalBytes(pageRange, bytes);
}
@ -83,11 +83,11 @@ public class OcrExecutionSupervisor {
public void logInProgress(PageBatch pageRange) {
if (!statistics.getBatchStats(pageRange).isUploadFinished()) {
log.info("Pages {} is in progress", pageRange);
log.info("Batch {}: Pages {} is in progress", pageRange.getIndex(), pageRange);
statistics.getBatchStats(pageRange).finishUpload();
ocrMessageSender.sendUpdate(fileId, processedPages(), getTotalPageCount());
} else {
log.debug("Pages {} still in progress", pageRange);
log.debug("Batch {}: Pages {} still in progress", pageRange.getIndex(), pageRange);
}
}
@ -114,14 +114,14 @@ public class OcrExecutionSupervisor {
this.errorPages.add(batch);
batch.forEach(pageIndex -> this.countDownPagesToProcess.countDown());
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount());
log.error("{}/{}: Error occurred on pages {}", processedPages(), getTotalPageCount(), batch, e);
log.error("{}/{}: Error occurred in batch {} with pages {}", processedPages(), getTotalPageCount(), batch.getIndex(), batch, e);
}
public void logPageSuccess(PageBatch batch) {
statistics.getBatchStats(batch).finishApiWait();
log.info("{}/{}: Finished OCR on pages {}", processedPages(), getTotalPageCount(), batch);
log.info("{}/{}: Finished OCR in batch {} with pages {}", processedPages(), getTotalPageCount(), batch.getIndex(), batch);
}

View File

@ -91,7 +91,7 @@ public class GhostScriptOutputHandler extends Thread {
if (!pagesToProcess.isEmpty()) {
errorHandler.accept(String.format("Ghostscript finished for batch %d, but pages %s remain unprocessed.", batchIdx, formatPagesToProcess()));
} else {
log.info("{}: Batch rendered successfully!", batchIdx);
log.info("Batch: {} rendered successfully!", batchIdx);
}
}

View File

@ -35,7 +35,7 @@ public class GhostScriptService {
supervisor.requireNoErrors();
log.info("Batch {}: starting GhostScript rendering with {} pages", batch, batch.size());
log.info("Batch {}: starting GhostScript rendering with page(s) {}", batch.getIndex(), batch);
executeProcess(batch.getIndex(), buildCmdArgs(batch, renderedImageDir, batch.getBatchDoc()), successHandler, errorHandler);
}

View File

@ -57,7 +57,6 @@ public class OcrMessageReceiver {
try {
MDC.put("fileId", fileId);
log.info("--------------------------------------------------------------------------");
log.info("Starting OCR");
ocrMessageSender.sendOCRStarted(fileId);
@ -78,6 +77,7 @@ public class OcrMessageReceiver {
in.getMessageProperties().getHeaders().put(MessagingConfiguration.X_ERROR_INFO_TIMESTAMP_HEADER, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
throw new RuntimeException(e);
} finally {
log.info("Done");
MDC.remove("fileId");
FileSystemUtils.deleteRecursively(tmpDir);
}