diff --git a/.changes/unreleased/Fixed-20250416-210315.yaml b/.changes/unreleased/Fixed-20250416-210315.yaml new file mode 100644 index 000000000..845ab7c1f --- /dev/null +++ b/.changes/unreleased/Fixed-20250416-210315.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Add consistent log prefix and key to logs when stale workflows are automatically canceled +time: 2025-04-16T21:03:15.491889784+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php index d8f0863fc..d392df1ca 100644 --- a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php +++ b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowHandler.php @@ -25,6 +25,8 @@ use Symfony\Component\Workflow\Transition; #[AsMessageHandler] final readonly class CancelStaleWorkflowHandler { + private const LOG_PREFIX = '[CancelStaleWorkflowHandler] '; + public function __construct( private EntityWorkflowRepository $workflowRepository, private Registry $registry, @@ -40,13 +42,13 @@ final readonly class CancelStaleWorkflowHandler $workflow = $this->workflowRepository->find($message->getWorkflowId()); if (null === $workflow) { - $this->logger->alert('Workflow was not found!', [$workflowId]); + $this->logger->alert(self::LOG_PREFIX.'Workflow was not found!', ['entityWorkflowId' => $workflowId]); return; } if (false === $workflow->isStaledAt($olderThanDate)) { - $this->logger->alert('Workflow has transitioned in the meantime.', [$workflowId]); + $this->logger->alert(self::LOG_PREFIX.'Workflow has transitioned in the meantime.', ['entityWorkflowId' => $workflowId]); throw new UnrecoverableMessageHandlingException('the workflow is not staled any more'); } @@ -67,14 +69,14 @@ final readonly class CancelStaleWorkflowHandler 'transitionAt' => $this->clock->now(), 'transition' => $transition->getName(), ]); - $this->logger->info('EntityWorkflow has been cancelled automatically.', [$workflowId]); + $this->logger->info(self::LOG_PREFIX.'EntityWorkflow has been cancelled automatically.', ['entityWorkflowId' => $workflowId]); $transitionApplied = true; break; } } if (!$transitionApplied) { - $this->logger->error('No valid transition found for EntityWorkflow.', [$workflowId]); + $this->logger->error(self::LOG_PREFIX.'No valid transition found for EntityWorkflow.', ['entityWorkflowId' => $workflowId]); throw new UnrecoverableMessageHandlingException(sprintf('No valid transition found for EntityWorkflow %d.', $workflowId)); }