Skip to content

Commit

Permalink
Merge pull request #3 from FVSoftwareDeveloper/master
Browse files Browse the repository at this point in the history
upgrade to support Symfony 5
  • Loading branch information
angelbencosme committed Oct 13, 2022
2 parents 4785460 + 227e57d commit 6239616
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions EventListener/KernelExceptionListener.php
Expand Up @@ -4,7 +4,7 @@
namespace NTI\LogBundle\EventListener;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

Expand All @@ -24,10 +24,10 @@ function __construct($container) {
/**
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(ExceptionEvent $event)
{
// You get the exception object from the received event
$exception = $event->getException();
$exception = $event;
$this->container->get('nti.logger')->logException($exception);
}
}
}
7 changes: 4 additions & 3 deletions Services/Logger.php
Expand Up @@ -10,6 +10,7 @@
use NTI\LogBundle\Exception\SlackException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use NTI\LogBundle\Entity\Log;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;

class Logger {

Expand Down Expand Up @@ -60,8 +61,8 @@ public function logError($message, $action = Log::ACTION_INFO, $entity = null) {
$this->log($message, $action, $entity, Log::LEVEL_ERROR);
}

public function logException(\Exception $ex) {
$this->log($ex->getMessage(), Log::ACTION_EXCEPTION, null, Log::LEVEL_ERROR, $ex);
public function logException(ExceptionEvent $ex) {
$this->log($ex->getThrowable(), Log::ACTION_EXCEPTION, null, Log::LEVEL_ERROR, $ex->getResponse());
}

public function logSlack($message, $level = Log::LEVEL_NOTICE, $entity = null) {
Expand Down Expand Up @@ -185,4 +186,4 @@ private function log($message, $action = Log::ACTION_INFO, $entity = null, $leve
$this->logSlack($message, $level, $entity);
}
}
}
}

0 comments on commit 6239616

Please sign in to comment.