chg: [workflow:logging] Added logging to file in addition to DB logging

This is used to mitigate a bug that prevent log entries to be saved in the log table if they are inserted in a `beforeSave` context. The bug append because cakephp rolls back any pending entry in the transaction.
pull/8530/head
Sami Mokaddem 2022-07-06 15:31:16 +02:00
parent 9f9c421140
commit 14f1ffab8b
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 18 additions and 1 deletions

View File

@ -413,7 +413,9 @@ class Workflow extends AppModel
return false;
}
$this->Log = ClassRegistry::init('Log');
$this->Log->createLogEntry('SYSTEM', 'execute_workflow', 'Workflow', $workflow['Workflow']['id'], __('Started executing workflow for trigger `%s` (%s)', $trigger_id, $workflow['Workflow']['id']));
$message = __('Started executing workflow for trigger `%s` (%s)', $trigger_id, $workflow['Workflow']['id']);
$this->Log->createLogEntry('SYSTEM', 'execute_workflow', 'Workflow', $workflow['Workflow']['id'], $message);
$this->__logToFile($workflow, $message);
$workflow = $this->__incrementWorkflowExecutionCount($workflow);
$walkResult = [];
$blockingPathExecutionSuccess = $this->walkGraph($workflow, $startNode, Workflow::BLOCKING_PATH, $data, $blockingErrors, $walkResult);
@ -740,6 +742,21 @@ class Workflow extends AppModel
{
$this->Log = ClassRegistry::init('Log');
$this->Log->createLogEntry('SYSTEM', 'execute_workflow', 'Workflow', $workflow['Workflow']['id'], $message);
$this->__logToFile($workflow, $message);
}
/**
* __logToFile Log to file
*
* @param array $workflow
* @param string $message
* @return void
*/
private function __logToFile($workflow, $message)
{
$logEntry = sprintf('[%s] Workflow(%s:%s). %s' . PHP_EOL, date('Y-m-d H:i:s'), $workflow['Workflow']['trigger_id'], $workflow['Workflow']['id'], $message);
// file_put_contents(APP . 'tmp/logs/workflow-execution.log', $logEntry, FILE_APPEND | LOCK_EX);
FileAccessTool::writeToFile(APP . 'tmp/logs/workflow-execution.log', $logEntry, false, true);
}
private function __logLoadingError($filename, $error)