Created
April 30, 2020 18:17
-
-
Save ADmad/d906fd769dcc45fc6e4b92da20a1908f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Error/BaseErrorHandler.php b/src/Error/BaseErrorHandler.php | |
index 8cb03f96b9..2208bccf8d 100644 | |
--- a/src/Error/BaseErrorHandler.php | |
+++ b/src/Error/BaseErrorHandler.php | |
@@ -54,7 +54,7 @@ abstract class BaseErrorHandler | |
/** | |
* Exception logger instance. | |
* | |
- * @var \Cake\Error\ErrorLogger|null | |
+ * @var \Cake\Error\ErrorLoggerInterface|null | |
*/ | |
protected $logger; | |
@@ -309,21 +309,17 @@ abstract class BaseErrorHandler | |
$data['file'], | |
$data['line'] | |
); | |
+ $context = []; | |
if (!empty($this->_config['trace'])) { | |
/** @var string $trace */ | |
- $trace = Debugger::trace([ | |
+ $context['trace'] = Debugger::trace([ | |
'start' => 1, | |
'format' => 'log', | |
]); | |
- | |
- $request = Router::getRequest(); | |
- if ($request) { | |
- $message .= $this->getLogger()->getRequestContext($request); | |
- } | |
- $message .= "\nTrace:\n" . $trace . "\n"; | |
+ $context['request'] = Router::getRequest(); | |
} | |
- return $this->getLogger()->logMessage($level, $message); | |
+ return $this->getLogger()->logMessage($level, $message, $context); | |
} | |
/** | |
diff --git a/src/Error/ErrorLogger.php b/src/Error/ErrorLogger.php | |
index 97cedbad16..425c312682 100644 | |
--- a/src/Error/ErrorLogger.php | |
+++ b/src/Error/ErrorLogger.php | |
@@ -57,8 +57,15 @@ class ErrorLogger implements ErrorLoggerInterface | |
/** | |
* @inheritDoc | |
*/ | |
- public function logMessage($level, string $message): bool | |
+ public function logMessage($level, string $message, array $context = []): bool | |
{ | |
+ if (!empty($context['request'])) { | |
+ $message .= $this->getRequestContext($context['request']); | |
+ } | |
+ if (!empty($context['trace'])) { | |
+ $message .= "\nTrace:\n" . $context['trace'] . "\n"; | |
+ } | |
+ | |
return Log::write($level, $message); | |
} | |
diff --git a/src/Error/ErrorLoggerInterface.php b/src/Error/ErrorLoggerInterface.php | |
index acfe2a1b55..b8ee57c239 100644 | |
--- a/src/Error/ErrorLoggerInterface.php | |
+++ b/src/Error/ErrorLoggerInterface.php | |
@@ -44,7 +44,8 @@ interface ErrorLoggerInterface | |
* | |
* @param string|int $level The logging level | |
* @param string $message The message to be logged. | |
+ * @param array $context Context. | |
* @return bool | |
*/ | |
- public function logMessage($level, string $message): bool; | |
+ public function logMessage($level, string $message, array $context = []): bool; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment