Skip to content

Commit

Permalink
Add autowiring alias for LoggerInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Mar 22, 2017
1 parent ebce76a commit 28808a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions DependencyInjection/MonologExtension.php
Expand Up @@ -52,12 +52,11 @@ public function load(array $configs, ContainerBuilder $container)
if (isset($config['handlers'])) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('monolog.xml');
$container->setAlias('logger', 'monolog.logger');

$container->setParameter('monolog.use_microseconds', $config['use_microseconds']);

// always autowire the main logger, require Symfony >= 2.8
if (method_exists('Symfony\Component\DependencyInjection\Definition', 'addAutowiringType')) {
// always autowire the main logger, require Symfony >= 2.8, < 3.3
if (!method_exists('Symfony\Component\DependencyInjection\ContainerBuilder', 'fileExists') && method_exists('Symfony\Component\DependencyInjection\Definition', 'addAutowiringType')) {
$container->getDefinition('monolog.logger')->addAutowiringType('Psr\Log\LoggerInterface');
}

Expand Down
2 changes: 2 additions & 0 deletions Resources/config/monolog.xml
Expand Up @@ -14,6 +14,8 @@

<service id="logger" alias="monolog.logger" />

<service id="Psr\Log\LoggerInterface" alias="logger" public="false" />

<service id="monolog.logger_prototype" class="Symfony\Bridge\Monolog\Logger" abstract="true">
<argument /><!-- Channel -->
</service>
Expand Down

0 comments on commit 28808a4

Please sign in to comment.