Skip to content

Commit

Permalink
fix missing set extra[url] when check log throw RuntimeException
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 25, 2018
1 parent 49fb49d commit ac091d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
33 changes: 19 additions & 14 deletions src/Handler/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Logging
*/
private $request;

/**
* @var string
*/
private $serverUrl;

/**
* @var array
*/
Expand Down Expand Up @@ -175,7 +180,20 @@ private function collectErrorExceptionData(Throwable $t) : array

private function collectErrorExceptionExtraData(array $collectedExceptionData) : array
{
if ($this->request instanceof ConsoleRequest) {
$this->serverUrl = \php_uname('n');
$requestUri = ':' . \basename((string) \getcwd())
. ' ' . \get_current_user()
. '$ php ' . $this->request->getScriptName() . ' ' . $this->request->toString();
} else {
Assertion::isInstanceOf($this->request, HttpRequest::class);
$getServerURLandRequestURI = getServerURLandRequestURI($this->request);
$this->serverUrl = $getServerURLandRequestURI['serverUrl'];
$requestUri = $getServerURLandRequestURI['requestUri'];
}

return [
'url' => $this->serverUrl . $requestUri,
'file' => $collectedExceptionData['errorFile'],
'line' => $collectedExceptionData['errorLine'],
'error_type' => $collectedExceptionData['errorType'],
Expand Down Expand Up @@ -217,19 +235,6 @@ public function handleErrorException(Throwable $t) : void
$collectedExceptionData = $this->collectErrorExceptionData($t);
$extra = $this->collectErrorExceptionExtraData($collectedExceptionData);

if ($this->request instanceof ConsoleRequest) {
$serverUrl = \php_uname('n');
$requestUri = ':' . \basename((string) \getcwd())
. ' ' . \get_current_user()
. '$ php ' . $this->request->getScriptName() . ' ' . $this->request->toString();
} else {
Assertion::isInstanceOf($this->request, HttpRequest::class);
$getServerURLandRequestURI = getServerURLandRequestURI($this->request);
$serverUrl = $getServerURLandRequestURI['serverUrl'];
$requestUri = $getServerURLandRequestURI['requestUri'];
}
$extra['url'] = $serverUrl . $requestUri;

try {
if (
$this->isExists(
Expand All @@ -249,6 +254,6 @@ public function handleErrorException(Throwable $t) : void
$extra = $this->collectErrorExceptionExtraData($collectedExceptionData);
}

$this->sendMail($collectedExceptionData['priority'], $collectedExceptionData['errorMessage'], $extra, '['.$serverUrl.'] '.$collectedExceptionData['errorType'].' has thrown');
$this->sendMail($collectedExceptionData['priority'], $collectedExceptionData['errorMessage'], $extra, '['.$this->serverUrl.'] '.$collectedExceptionData['errorType'].' has thrown');
}
}
6 changes: 3 additions & 3 deletions src/Handler/LoggingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function __invoke(ContainerInterface $container) : Logging
{
if (! Console::isConsole()) {
if ($container->has('Request')) {
$request = $container->get('Request');
$request = $container->get('Request');
} else {
$request = null;
$request = null;
}
} else {
$request = new ConsoleRequest();
$request = new ConsoleRequest();
}

$config = $container->get('config');
Expand Down

0 comments on commit ac091d7

Please sign in to comment.