Skip to content

Commit

Permalink
made the logger optional in AdminExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 authored and rande committed Mar 27, 2013
1 parent eefc531 commit f15aabd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Resources/config/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<!-- Translation extractor -->
<service id="sonata.admin.translator.extractor.jms_translator_bundle" class="Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor" >
<tag name="jms_translation.extractor" alias="sonata_admin"/>
<argument type="service" id="logger" />
<argument type="service" id="sonata.admin.pool" />
<argument type="service" id="logger" on-invalid="ignore" />
</service>

<!-- controller as services -->
Expand Down
12 changes: 8 additions & 4 deletions Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class AdminExtractor implements ExtractorInterface, TranslatorInterface, Securit
private $domain;

/**
* @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
* @param \Sonata\AdminBundle\Admin\Pool $adminPool
* @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger, Pool $adminPool)
public function __construct(Pool $adminPool, LoggerInterface $logger = null)
{
$this->logger = $logger;
$this->adminPool = $adminPool;
Expand Down Expand Up @@ -91,14 +91,18 @@ public function extract()
)
);

$this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
if ($this->logger) {
$this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
}

foreach ($methods as $method => $calls) {
foreach ($calls as $args) {
try {
call_user_func_array(array($admin, $method), $args);
} catch (\Exception $e) {
$this->logger->err(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
if ($this->logger) {
$this->logger->err(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
}

throw $e;
}
Expand Down

0 comments on commit f15aabd

Please sign in to comment.