Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 342e03a

Browse files
committed
Improve exception logging
1 parent 44818aa commit 342e03a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

QuietFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class QuietFactory implements FactoryInterface
2020
private $innerFactory;
2121

2222
/**
23-
* @var LoggerInterface
23+
* @var LoggerInterface|null
2424
*/
2525
private $logger;
2626

@@ -33,7 +33,7 @@ class QuietFactory implements FactoryInterface
3333
*/
3434
private $allowEmptyItems;
3535

36-
public function __construct(FactoryInterface $innerFactory, LoggerInterface $logger, $allowEmptyItems = false)
36+
public function __construct(FactoryInterface $innerFactory, LoggerInterface $logger = null, $allowEmptyItems = false)
3737
{
3838
$this->innerFactory = $innerFactory;
3939
$this->logger = $logger;
@@ -48,7 +48,12 @@ public function createItem($name, array $options = array())
4848
try {
4949
return $this->innerFactory->createItem($name, $options);
5050
} catch (RouteNotFoundException $e) {
51-
$this->logger->error(sprintf('%s : %s', $name, $e->getMessage()));
51+
if (null !== $this->logger) {
52+
$this->logger->error(
53+
sprintf('An exception was thrown while creating a menu item called "%s"', $name),
54+
array('exception' => $e)
55+
);
56+
}
5257

5358
if (!$this->allowEmptyItems) {
5459
return null;

Resources/config/menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<service id="cmf_menu.factory.quiet" class="Symfony\Cmf\Bundle\MenuBundle\QuietFactory" public="false">
1212
<argument type="service" id="cmf_menu.factory.quiet.inner" />
13-
<argument type="service" id="logger"/>
13+
<argument type="service" id="logger" on-invalid="ignore" />
1414
<argument>%cmf_menu.allow_empty_items%</argument>
1515
</service>
1616

0 commit comments

Comments
 (0)