protected function logError($error, array $additionalData = [])
{
$backTrace = $error->getTrace();
$className = isset($backTrace[0]['class']) ? $backTrace[0]['class'] : '?';
$methodName = isset($backTrace[0]['function']) ? $backTrace[0]['function'] : '?';
$message = $this->getErrorLogMessage($error);
if ($error->getPrevious() !== null) {
$additionalData['previousException'] = $this->getErrorLogMessage($error->getPrevious());
}
$explodedClassName = explode('\\', $className);
// FIXME: This is not really the package key:
$packageKey = isset($explodedClassName[1]) ? $explodedClassName[1] : null;
if (!file_exists(FLOW_PATH_DATA . 'Logs/Exceptions')) {
mkdir(FLOW_PATH_DATA . 'Logs/Exceptions');
}
if (file_exists(FLOW_PATH_DATA . 'Logs/Exceptions') && is_dir(FLOW_PATH_DATA . 'Logs/Exceptions') && is_writable(FLOW_PATH_DATA . 'Logs/Exceptions')) {
$referenceCode = $error instanceof Exception ? $error->getReferenceCode() : date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6);
$errorDumpPathAndFilename = FLOW_PATH_DATA . 'Logs/Exceptions/' . $referenceCode . '.txt';
file_put_contents($errorDumpPathAndFilename, $this->renderErrorInfo($error));
$message .= ' - See also: ' . basename($errorDumpPathAndFilename);
} else {
$this->log(sprintf('Could not write exception backtrace into %s because the directory could not be created or is not writable.', FLOW_PATH_DATA . 'Logs/Exceptions/'), LOG_WARNING, [], 'Flow', __CLASS__, __FUNCTION__);
}
$this->log($message, LOG_CRIT, $additionalData, $packageKey, $className, $methodName);
}