Add check that function error_log exists

[MAILPOET-5026]
This commit is contained in:
Jan Lysý
2023-02-24 17:21:09 +01:00
committed by Veljko V
parent 71aef99607
commit 212e01dd4c
3 changed files with 7 additions and 3 deletions

View File

@ -281,7 +281,9 @@ class API {
private function logError(Throwable $e): void {
// logging to the php log
if (function_exists('error_log')) {
error_log((string)$e); // phpcs:ignore Squiz.PHP.DiscouragedFunctions
}
// logging to the MailPoet table
$this->loggerFactory->getLogger(LoggerFactory::TOPIC_API)->warning($e->getMessage(), [
'requestMethod' => $this->requestMethod,

View File

@ -83,7 +83,7 @@ class API {
? new ErrorResponse($e->getStatusCode(), $e->getMessage(), $e->getErrorCode(), $e->getErrors())
: new ErrorResponse(500, __('An unknown error occurred.', 'mailpoet'), 'mailpoet_automation_unknown_error');
if ($response->get_status() >= 500) {
if ($response->get_status() >= 500 && function_exists('error_log')) {
error_log((string)$e); // phpcs:ignore Squiz.PHP.DiscouragedFunctions
}
return $response;

View File

@ -165,8 +165,10 @@ class TranslationUpdater {
if (class_exists(Debugger::class)) {
Debugger::log($message, ILogger::ERROR);
}
if (function_exists('error_log')) {
error_log($message); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged
}
}
/**
* @return array|\WP_Error