Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Remove `excluded_404s` option, use `excluded_http_codes` instead
* Remove `console_formater_options` option, use `console_formatter_options` instead
* Remove `elasticsearch` type, use `elastica` or `elastic_search` instead
* Remove `mongo` type, use `mongodb` instead
* Remove `sentry` and `raven` types, use a `service` type with [`sentry/sentry-symfony`](https://docs.sentryio/platforms/php/guides/symfony/logs/) instead
* Remove `DebugHandlerPass`
* Remove support for the `DebugHandler`
11 changes: 0 additions & 11 deletions config/schema/monolog-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<xsd:element name="member" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="channels" type="channels" minOccurs="0" maxOccurs="1" />
<xsd:element name="publisher" type="publisher" minOccurs="0" maxOccurs="1" />
<xsd:element name="mongo" type="mongo" minOccurs="0" maxOccurs="1" />
<xsd:element name="mongodb" type="mongodb" minOccurs="0" maxOccurs="1" />
<xsd:element name="elasticsearch" type="elasticsearch" minOccurs="0" maxOccurs="1" />
<xsd:element name="config" type="xsd:anyType" minOccurs="0" maxOccurs="1" />
Expand Down Expand Up @@ -148,16 +147,6 @@
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="mongo">
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="host" type="xsd:string" />
<xsd:attribute name="port" type="xsd:integer" />
<xsd:attribute name="user" type="xsd:string" />
<xsd:attribute name="pass" type="xsd:string" />
<xsd:attribute name="database" type="xsd:string" />
<xsd:attribute name="collection" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="mongodb">
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="uri" type="xsd:string" />
Expand Down
53 changes: 0 additions & 53 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@
* - [filename_format]: string, defaults to '{filename}-{date}'
* - [date_format]: string, defaults to 'Y-m-d'
*
* - mongo:
* - mongo:
* - id: optional if host is given
* - host: database host name, optional if id is given
* - [port]: defaults to 27017
* - [user]: database user name
* - pass: mandatory only if user is present
* - [database]: defaults to monolog
* - [collection]: defaults to logs
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
*
* - mongodb:
* - mongodb:
* - id: optional if uri is given
Expand Down Expand Up @@ -584,7 +572,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->end();

$this->addGelfSection($handlerNode);
$this->addMongoSection($handlerNode);
Copy link
Member

@HypeMC HypeMC Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments on the top should be removed as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also from the XSD.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching what I had missed. It 's fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed, the comments part is still there.

$this->addMongoDBSection($handlerNode);
$this->addElasticsearchSection($handlerNode);
$this->addRedisSection($handlerNode);
Expand Down Expand Up @@ -742,46 +729,6 @@ private function addGelfSection(ArrayNodeDefinition $handlerNode): void
;
}

private function addMongoSection(ArrayNodeDefinition $handlerNode): void
{
$handlerNode
->children()
->arrayNode('mongo')
->canBeUnset()
->beforeNormalization()
->ifString()
->then(function ($v) { return ['id' => $v]; })
->end()
->children()
->scalarNode('id')->end()
->scalarNode('host')->end()
->scalarNode('port')->defaultValue(27017)->end()
->scalarNode('user')->end()
->scalarNode('pass')->end()
->scalarNode('database')->defaultValue('monolog')->end()
->scalarNode('collection')->defaultValue('logs')->end()
->end()
->validate()
->ifTrue(function ($v) {
return !isset($v['id']) && !isset($v['host']);
})
->thenInvalid('The "mongo" handler configuration requires either a service "id" or a connection "host".')
->end()
->validate()
->ifTrue(function ($v) {
return isset($v['user']) && !isset($v['pass']);
})
->thenInvalid('If you set user, you must provide a password.')
->end()
->end()
->end()
->validate()
->ifTrue(function ($v) { return 'mongo' === $v['type'] && !isset($v['mongo']); })
->thenInvalid('The "mongo" configuration has to be specified to use a "mongo" handler type.')
->end()
;
}

private function addMongoDBSection(ArrayNodeDefinition $handlerNode)
{
$handlerNode
Expand Down
39 changes: 1 addition & 38 deletions src/DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,39 +231,6 @@ private function buildHandler(ContainerBuilder $container, string $name, array $
]);
break;

case 'mongo':
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.');

if (!class_exists(\MongoDB\Client::class)) {
throw new \RuntimeException('The "mongo" handler requires the mongodb/mongodb package to be installed.');
}

if (isset($handler['mongo']['id'])) {
$client = new Reference($handler['mongo']['id']);
} else {
$server = 'mongodb://';

if (isset($handler['mongo']['user'])) {
$server .= $handler['mongo']['user'].':'.$handler['mongo']['pass'].'@';
}

$server .= $handler['mongo']['host'].':'.$handler['mongo']['port'];

$client = new Definition(\MongoDB\Client::class, [
$server,
['appname' => 'monolog-bundle'],
]);
}

$definition->setArguments([
$client,
$handler['mongo']['database'],
$handler['mongo']['collection'],
$handler['level'],
$handler['bubble'],
]);
break;

case 'mongodb':
if (!class_exists(\MongoDB\Client::class)) {
throw new \RuntimeException('The "mongodb" handler requires the mongodb/mongodb package to be installed.');
Expand Down Expand Up @@ -302,10 +269,6 @@ private function buildHandler(ContainerBuilder $container, string $name, array $
}
break;

case 'elasticsearch':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.');
// no break

case 'elastica':
case 'elastic_search':
if (isset($handler['elasticsearch']['id'])) {
Expand Down Expand Up @@ -859,7 +822,7 @@ private function getHandlerClassByType(string $handlerType): string
'whatfailuregroup' => \Monolog\Handler\WhatFailureGroupHandler::class,
'fingers_crossed' => \Monolog\Handler\FingersCrossedHandler::class,
'filter' => \Monolog\Handler\FilterHandler::class,
'mongo','mongodb' => \Monolog\Handler\MongoDBHandler::class,
'mongodb' => \Monolog\Handler\MongoDBHandler::class,
'telegram' => \Monolog\Handler\TelegramBotHandler::class,
'server_log' => \Symfony\Bridge\Monolog\Handler\ServerLogHandler::class,
'redis', 'predis' => \Monolog\Handler\RedisHandler::class,
Expand Down
80 changes: 0 additions & 80 deletions tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use Monolog\Handler\RollbarHandler;
use Monolog\Processor\UidProcessor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority;
Expand Down Expand Up @@ -556,84 +554,6 @@ public function testElasticsearchAndElasticaHandlers()
$this->assertSame(['hosts' => ['es:9200'], 'transport' => 'Http'], $elasticaClient->getArgument(0));
}

#[Group('legacy')]
#[IgnoreDeprecations]
public function testMongo()
{
if (!class_exists('MongoDB\Client')) {
$this->markTestSkipped('mongodb/mongodb is not installed.');
}

// $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.');

$container = new ContainerBuilder();
$container->setDefinition('mongodb.client', new Definition('MongoDB\Client'));

$config = [[
'handlers' => [
'mongo_with_id' => [
'type' => 'mongo',
'mongo' => ['id' => 'mongodb.client'],
],
'mongo_with_string_id' => [
'type' => 'mongo',
'mongo' => 'mongodb.client',
],
'mongo_with_host' => [
'type' => 'mongo',
'mongo' => [
'host' => 'localhost',
'port' => '27018',
'user' => 'username',
'pass' => 'password',
'database' => 'db',
'collection' => 'coll',
],
],
'mongo_with_host_and_default_args' => [
'type' => 'mongo',
'mongo' => [
'host' => 'localhost',
],
],
],
]];

$extension = new MonologExtension();
$extension->load($config, $container);

$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_id'));
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_string_id'));
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_host'));
$this->assertTrue($container->hasDefinition('monolog.handler.mongo_with_host_and_default_args'));

// MongoDB handler should receive the mongodb.client as first argument
$handler = $container->getDefinition('monolog.handler.mongo_with_id');
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
$this->assertDICConstructorArguments($handler, [new Reference('mongodb.client'), 'monolog', 'logs', 'DEBUG', true]);

// MongoDB handler should receive the mongodb.client as first argument
$handler = $container->getDefinition('monolog.handler.mongo_with_string_id');
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
$this->assertDICConstructorArguments($handler, [new Reference('mongodb.client'), 'monolog', 'logs', 'DEBUG', true]);

// MongoDB handler with host and arguments
$handler = $container->getDefinition('monolog.handler.mongo_with_host');
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
$client = $handler->getArgument(0);
$this->assertDICDefinitionClass($client, 'MongoDB\Client');
$this->assertDICConstructorArguments($client, ['mongodb://username:password@localhost:27018', ['appname' => 'monolog-bundle']]);
$this->assertDICConstructorArguments($handler, [$client, 'db', 'coll', 'DEBUG', true]);

// MongoDB handler with host and default arguments
$handler = $container->getDefinition('monolog.handler.mongo_with_host_and_default_args');
$this->assertDICDefinitionClass($handler, MongoDBHandler::class);
$client = $handler->getArgument(0);
$this->assertDICDefinitionClass($client, 'MongoDB\Client');
$this->assertDICConstructorArguments($client, ['mongodb://localhost:27017', ['appname' => 'monolog-bundle']]);
$this->assertDICConstructorArguments($handler, [$client, 'monolog', 'logs', 'DEBUG', true]);
}

public function testMongoDB()
{
if (!class_exists('MongoDB\Client')) {
Expand Down