Skip to content

Commit

Permalink
Merge pull request #43 from smartbooster/41_batch_log
Browse files Browse the repository at this point in the history
#41 add sentry to BatchLogger
  • Loading branch information
mathieu-ducrot authored Nov 3, 2022
2 parents 3cbebc0 + 0750fe5 commit 33c4132
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"symfony/yaml": "^4.4 || ^5.4 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"nelmio/security-bundle": "^2.8",
"yokai/security-token-bundle": "^3.3"
"yokai/security-token-bundle": "^3.3",
"sentry/sentry-symfony": "^4.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.7",
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ services:
public: true
arguments:
- '@Doctrine\ORM\EntityManagerInterface'
- '@Sentry\ClientInterface'

Smart\SonataBundle\Logger\BatchLogger:
public: false
Expand Down
9 changes: 8 additions & 1 deletion src/Logger/BatchLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
namespace Smart\SonataBundle\Logger;

use Doctrine\ORM\EntityManagerInterface;
use Sentry\ClientInterface;
use Smart\SonataBundle\Entity\Log\BatchLog;

class BatchLogger
{
private EntityManagerInterface $entityManager;
private ClientInterface $sentry;

public function __construct(EntityManagerInterface $entityManager)
public function __construct(EntityManagerInterface $entityManager, ClientInterface $sentry)
{
$this->entityManager = $entityManager;
$this->sentry = $sentry;
}

public function log(array $parameters): void
{
if (isset($parameters['exception'])) {
$this->sentry->captureException($parameters['exception']);
}

$batchLog = new BatchLog();
if (!isset($parameters['context'])) {
throw new \Exception("'context' must be present in batch log");
Expand Down
1 change: 1 addition & 0 deletions tests/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function registerBundles()
new \Yokai\SecurityTokenBundle\YokaiSecurityTokenBundle(),
new \Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new \Knp\Bundle\MenuBundle\KnpMenuBundle(),
new \Sentry\SentryBundle\SentryBundle(),
];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/DependencyInjection/DependencyInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Sentry\ClientInterface;
use Smart\SonataBundle\SmartSonataBundle;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\FileLocator;
Expand All @@ -25,6 +26,7 @@ protected function setUp(): void
$bundle = new SmartSonataBundle();
$this->container = new ContainerBuilder();
$this->container->setDefinition('Doctrine\ORM\EntityManagerInterface', new Definition(EntityManagerInterface::class));
$this->container->setDefinition('Sentry\ClientInterface', new Definition(ClientInterface::class));
$this->container->registerExtension($bundle->getContainerExtension());
$bundle->build($this->container);
}
Expand Down

0 comments on commit 33c4132

Please sign in to comment.