Skip to content

Commit 271d38a

Browse files
committed
Remove "mongo" handler type
1 parent 27d779a commit 271d38a

File tree

5 files changed

+2
-182
lines changed

5 files changed

+2
-182
lines changed

CHANGELOG-4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Remove `excluded_404s` option, use `excluded_http_codes` instead
1111
* Remove `console_formater_options` option, use `console_formatter_options` instead
1212
* Remove `elasticsearch` type, use `elastica` or `elastic_search` instead
13+
* Remove `mongo` type, use `mongodb` instead
1314
* Remove `sentry` and `raven` types, use a `service` type with [`sentry/sentry-symfony`](https://docs.sentryio/platforms/php/guides/symfony/logs/) instead
1415
* Remove `DebugHandlerPass`
1516
* Remove support for the `DebugHandler`

config/schema/monolog-1.0.xsd

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<xsd:element name="member" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
2121
<xsd:element name="channels" type="channels" minOccurs="0" maxOccurs="1" />
2222
<xsd:element name="publisher" type="publisher" minOccurs="0" maxOccurs="1" />
23-
<xsd:element name="mongo" type="mongo" minOccurs="0" maxOccurs="1" />
2423
<xsd:element name="mongodb" type="mongodb" minOccurs="0" maxOccurs="1" />
2524
<xsd:element name="elasticsearch" type="elasticsearch" minOccurs="0" maxOccurs="1" />
2625
<xsd:element name="config" type="xsd:anyType" minOccurs="0" maxOccurs="1" />
@@ -148,16 +147,6 @@
148147
</xsd:restriction>
149148
</xsd:simpleType>
150149

151-
<xsd:complexType name="mongo">
152-
<xsd:attribute name="id" type="xsd:string" />
153-
<xsd:attribute name="host" type="xsd:string" />
154-
<xsd:attribute name="port" type="xsd:integer" />
155-
<xsd:attribute name="user" type="xsd:string" />
156-
<xsd:attribute name="pass" type="xsd:string" />
157-
<xsd:attribute name="database" type="xsd:string" />
158-
<xsd:attribute name="collection" type="xsd:string" />
159-
</xsd:complexType>
160-
161150
<xsd:complexType name="mongodb">
162151
<xsd:attribute name="id" type="xsd:string" />
163152
<xsd:attribute name="uri" type="xsd:string" />

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@
7979
* - [filename_format]: string, defaults to '{filename}-{date}'
8080
* - [date_format]: string, defaults to 'Y-m-d'
8181
*
82-
* - mongo:
83-
* - mongo:
84-
* - id: optional if host is given
85-
* - host: database host name, optional if id is given
86-
* - [port]: defaults to 27017
87-
* - [user]: database user name
88-
* - pass: mandatory only if user is present
89-
* - [database]: defaults to monolog
90-
* - [collection]: defaults to logs
91-
* - [level]: level name or int value, defaults to DEBUG
92-
* - [bubble]: bool, defaults to true
93-
*
9482
* - mongodb:
9583
* - mongodb:
9684
* - id: optional if uri is given
@@ -584,7 +572,6 @@ public function getConfigTreeBuilder(): TreeBuilder
584572
->end();
585573

586574
$this->addGelfSection($handlerNode);
587-
$this->addMongoSection($handlerNode);
588575
$this->addMongoDBSection($handlerNode);
589576
$this->addElasticsearchSection($handlerNode);
590577
$this->addRedisSection($handlerNode);
@@ -742,46 +729,6 @@ private function addGelfSection(ArrayNodeDefinition $handlerNode): void
742729
;
743730
}
744731

745-
private function addMongoSection(ArrayNodeDefinition $handlerNode): void
746-
{
747-
$handlerNode
748-
->children()
749-
->arrayNode('mongo')
750-
->canBeUnset()
751-
->beforeNormalization()
752-
->ifString()
753-
->then(function ($v) { return ['id' => $v]; })
754-
->end()
755-
->children()
756-
->scalarNode('id')->end()
757-
->scalarNode('host')->end()
758-
->scalarNode('port')->defaultValue(27017)->end()
759-
->scalarNode('user')->end()
760-
->scalarNode('pass')->end()
761-
->scalarNode('database')->defaultValue('monolog')->end()
762-
->scalarNode('collection')->defaultValue('logs')->end()
763-
->end()
764-
->validate()
765-
->ifTrue(function ($v) {
766-
return !isset($v['id']) && !isset($v['host']);
767-
})
768-
->thenInvalid('The "mongo" handler configuration requires either a service "id" or a connection "host".')
769-
->end()
770-
->validate()
771-
->ifTrue(function ($v) {
772-
return isset($v['user']) && !isset($v['pass']);
773-
})
774-
->thenInvalid('If you set user, you must provide a password.')
775-
->end()
776-
->end()
777-
->end()
778-
->validate()
779-
->ifTrue(function ($v) { return 'mongo' === $v['type'] && !isset($v['mongo']); })
780-
->thenInvalid('The "mongo" configuration has to be specified to use a "mongo" handler type.')
781-
->end()
782-
;
783-
}
784-
785732
private function addMongoDBSection(ArrayNodeDefinition $handlerNode)
786733
{
787734
$handlerNode

src/DependencyInjection/MonologExtension.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -231,39 +231,6 @@ private function buildHandler(ContainerBuilder $container, string $name, array $
231231
]);
232232
break;
233233

234-
case 'mongo':
235-
trigger_deprecation('symfony/monolog-bundle', '3.11', 'The "mongo" handler type is deprecated in MonologBundle since version 3.11.0, use the "mongodb" type instead.');
236-
237-
if (!class_exists(\MongoDB\Client::class)) {
238-
throw new \RuntimeException('The "mongo" handler requires the mongodb/mongodb package to be installed.');
239-
}
240-
241-
if (isset($handler['mongo']['id'])) {
242-
$client = new Reference($handler['mongo']['id']);
243-
} else {
244-
$server = 'mongodb://';
245-
246-
if (isset($handler['mongo']['user'])) {
247-
$server .= $handler['mongo']['user'].':'.$handler['mongo']['pass'].'@';
248-
}
249-
250-
$server .= $handler['mongo']['host'].':'.$handler['mongo']['port'];
251-
252-
$client = new Definition(\MongoDB\Client::class, [
253-
$server,
254-
['appname' => 'monolog-bundle'],
255-
]);
256-
}
257-
258-
$definition->setArguments([
259-
$client,
260-
$handler['mongo']['database'],
261-
$handler['mongo']['collection'],
262-
$handler['level'],
263-
$handler['bubble'],
264-
]);
265-
break;
266-
267234
case 'mongodb':
268235
if (!class_exists(\MongoDB\Client::class)) {
269236
throw new \RuntimeException('The "mongodb" handler requires the mongodb/mongodb package to be installed.');
@@ -302,10 +269,6 @@ private function buildHandler(ContainerBuilder $container, string $name, array $
302269
}
303270
break;
304271

305-
case 'elasticsearch':
306-
trigger_deprecation('symfony/monolog-bundle', '3.8', 'The "elasticsearch" handler type is deprecated in MonologBundle since version 3.8.0, use the "elastica" type instead, or switch to the official Elastic client using the "elastic_search" type.');
307-
// no break
308-
309272
case 'elastica':
310273
case 'elastic_search':
311274
if (isset($handler['elasticsearch']['id'])) {
@@ -859,7 +822,7 @@ private function getHandlerClassByType(string $handlerType): string
859822
'whatfailuregroup' => \Monolog\Handler\WhatFailureGroupHandler::class,
860823
'fingers_crossed' => \Monolog\Handler\FingersCrossedHandler::class,
861824
'filter' => \Monolog\Handler\FilterHandler::class,
862-
'mongo','mongodb' => \Monolog\Handler\MongoDBHandler::class,
825+
'mongodb' => \Monolog\Handler\MongoDBHandler::class,
863826
'telegram' => \Monolog\Handler\TelegramBotHandler::class,
864827
'server_log' => \Symfony\Bridge\Monolog\Handler\ServerLogHandler::class,
865828
'redis', 'predis' => \Monolog\Handler\RedisHandler::class,

tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
use Monolog\Handler\RollbarHandler;
1919
use Monolog\Processor\UidProcessor;
2020
use PHPUnit\Framework\Attributes\DataProvider;
21-
use PHPUnit\Framework\Attributes\Group;
22-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2321
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
2422
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
2523
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority;
@@ -556,84 +554,6 @@ public function testElasticsearchAndElasticaHandlers()
556554
$this->assertSame(['hosts' => ['es:9200'], 'transport' => 'Http'], $elasticaClient->getArgument(0));
557555
}
558556

559-
#[Group('legacy')]
560-
#[IgnoreDeprecations]
561-
public function testMongo()
562-
{
563-
if (!class_exists('MongoDB\Client')) {
564-
$this->markTestSkipped('mongodb/mongodb is not installed.');
565-
}
566-
567-
// $this->expectDeprecation('Since symfony/monolog-bundle 3.11: The "mongo" handler type is deprecated in MonologBundle since version 3.11.0, use the "mongodb" type instead.');
568-
569-
$container = new ContainerBuilder();
570-
$container->setDefinition('mongodb.client', new Definition('MongoDB\Client'));
571-
572-
$config = [[
573-
'handlers' => [
574-
'mongo_with_id' => [
575-
'type' => 'mongo',
576-
'mongo' => ['id' => 'mongodb.client'],
577-
],
578-
'mongo_with_string_id' => [
579-
'type' => 'mongo',
580-
'mongo' => 'mongodb.client',
581-
],
582-
'mongo_with_host' => [
583-
'type' => 'mongo',
584-
'mongo' => [
585-
'host' => 'localhost',
586-
'port' => '27018',
587-
'user' => 'username',
588-
'pass' => 'password',
589-
'database' => 'db',
590-
'collection' => 'coll',
591-
],
592-
],
593-
'mongo_with_host_and_default_args' => [
594-
'type' => 'mongo',
595-
'mongo' => [
596-
'host' => 'localhost',
597-
],
598-
],
599-
],
600-
]];
601-
602-
$extension = new MonologExtension();
603-
$extension->load($config, $container);
604-
605-
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_id'));
606-
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_string_id'));
607-
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_host'));
608-
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_host_and_default_args'));
609-
610-
// MongoDB handler should receive the mongodb.client as first argument
611-
$handler = $container->getDefinition('monolog.handler.mongo_with_id');
612-
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
613-
$this->assertDICConstructorArguments($handler, [new Reference('mongodb.client'), 'monolog', 'logs', 'DEBUG', true]);
614-
615-
// MongoDB handler should receive the mongodb.client as first argument
616-
$handler = $container->getDefinition('monolog.handler.mongo_with_string_id');
617-
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
618-
$this->assertDICConstructorArguments($handler, [new Reference('mongodb.client'), 'monolog', 'logs', 'DEBUG', true]);
619-
620-
// MongoDB handler with host and arguments
621-
$handler = $container->getDefinition('monolog.handler.mongo_with_host');
622-
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
623-
$client = $handler->getArgument(0);
624-
$this->assertDICDefinitionClass($client, 'MongoDB\Client');
625-
$this->assertDICConstructorArguments($client, ['mongodb://username:password@localhost:27018', ['appname' => 'monolog-bundle']]);
626-
$this->assertDICConstructorArguments($handler, [$client, 'db', 'coll', 'DEBUG', true]);
627-
628-
// MongoDB handler with host and default arguments
629-
$handler = $container->getDefinition('monolog.handler.mongo_with_host_and_default_args');
630-
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
631-
$client = $handler->getArgument(0);
632-
$this->assertDICDefinitionClass($client, 'MongoDB\Client');
633-
$this->assertDICConstructorArguments($client, ['mongodb://localhost:27017', ['appname' => 'monolog-bundle']]);
634-
$this->assertDICConstructorArguments($handler, [$client, 'monolog', 'logs', 'DEBUG', true]);
635-
}
636-
637557
public function testMongoDB()
638558
{
639559
if (!class_exists('MongoDB\Client')) {

0 commit comments

Comments
 (0)