Skip to content

Commit

Permalink
Add support for use_microseconds configuration at the logger level
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Apr 12, 2016
1 parent 67919e0 commit d156f62
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public function getConfigTreeBuilder()
->fixXmlConfig('channel')
->fixXmlConfig('handler')
->children()
->scalarNode('use_microseconds')->defaultTrue()->end()
->arrayNode('channels')
->canBeUnset()
->prototype('scalar')->end()
Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);


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')) {
$container->getDefinition('monolog.logger')->addAutowiringType('Psr\Log\LoggerInterface');
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/monolog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
<services>
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
<argument index="0">app</argument>
<call method="useMicrosecondTimestamps">
<argument>%monolog.use_microseconds%</argument>
</call>
</service>

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

0 comments on commit d156f62

Please sign in to comment.