Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Log\DebugLoggerConfigurator;
Expand Down Expand Up @@ -61,8 +61,8 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

if (isset($config['handlers'])) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('monolog.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('monolog.php');

if (!class_exists(DebugLoggerConfigurator::class)) {
$container->getDefinition('monolog.logger_prototype')->setClass(LegacyLogger::class);
Expand Down
66 changes: 66 additions & 0 deletions Resources/config/monolog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Monolog\Formatter\ChromePHPFormatter;
use Monolog\Formatter\GelfMessageFormatter;
use Monolog\Formatter\HtmlFormatter;
use Monolog\Formatter\JsonFormatter;
use Monolog\Formatter\LineFormatter;
use Monolog\Formatter\LogglyFormatter;
use Monolog\Formatter\LogstashFormatter;
use Monolog\Formatter\NormalizerFormatter;
use Monolog\Formatter\ScalarFormatter;
use Monolog\Formatter\WildfireFormatter;
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;

return static function (ContainerConfigurator $container) {
$container->services()

->alias('logger', 'monolog.logger')
->alias(LoggerInterface::class, 'logger')

->set('monolog.logger')
->parent('monolog.logger_prototype')
->args(['index_0' => 'app'])
->call('useMicrosecondTimestamps', [param('monolog.use_microseconds')])

->set('monolog.logger_prototype', Logger::class)
->args([abstract_arg('channel')])
->abstract()

->set('monolog.activation_strategy.not_found', NotFoundActivationStrategy::class)->abstract()
->set('monolog.handler.fingers_crossed.error_level_activation_strategy', ErrorLevelActivationStrategy::class)->abstract()

// Formatters
->set('monolog.formatter.chrome_php', ChromePHPFormatter::class)
->set('monolog.formatter.gelf_message', GelfMessageFormatter::class)
->set('monolog.formatter.html', HtmlFormatter::class)
->set('monolog.formatter.json', JsonFormatter::class)
->set('monolog.formatter.line', LineFormatter::class)
->set('monolog.formatter.loggly', LogglyFormatter::class)
->set('monolog.formatter.normalizer', NormalizerFormatter::class)
->set('monolog.formatter.scalar', ScalarFormatter::class)
->set('monolog.formatter.wildfire', WildfireFormatter::class)

->set('monolog.formatter.logstash', LogstashFormatter::class)
->args(['app'])

->set('monolog.http_client', HttpClientInterface::class)
->factory([HttpClient::class, 'create'])
;
};
44 changes: 0 additions & 44 deletions Resources/config/monolog.xml

This file was deleted.

10 changes: 5 additions & 5 deletions Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class AddProcessorsPassTest extends TestCase
Expand All @@ -42,8 +42,8 @@ public function testHandlerProcessors()
public function testFailureOnHandlerWithoutPushProcessor()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.php');

$service = new Definition(NullHandler::class);
$service->addTag('monolog.processor', ['handler' => 'test3']);
Expand All @@ -68,8 +68,8 @@ public function testFailureOnHandlerWithoutPushProcessor()
protected function getContainer()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.php');

$definition = $container->getDefinition('monolog.logger_prototype');
$container->setParameter('monolog.handler.console.class', ConsoleHandler::class);
Expand Down
14 changes: 7 additions & 7 deletions Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class LoggerChannelPassTest extends TestCase
Expand Down Expand Up @@ -147,8 +147,8 @@ public function testChannelsConfigurationOptionSupportsAppChannel()
private function getContainer()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.php');
$definition = $container->getDefinition('monolog.logger_prototype');
$container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', [100, false]));
$definition->addMethodCall('pushHandler', [new Reference('monolog.handler.test')]);
Expand Down Expand Up @@ -189,8 +189,8 @@ private function getContainer()
private function getContainerWithSetter()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.php');
$definition = $container->getDefinition('monolog.logger_prototype');
$container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', [100, false]));
$definition->addMethodCall('pushHandler', [new Reference('monolog.handler.test')]);
Expand Down Expand Up @@ -222,8 +222,8 @@ private function getFunctionalContainer()
$container->setParameter('monolog.handlers_to_channels', []);
$container->setParameter('monolog.use_microseconds', true);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config'));
$loader->load('monolog.php');

$container->addCompilerPass(new LoggerChannelPass());

Expand Down
Loading