Skip to content

Conversation

@wimme002
Copy link

@wimme002 wimme002 commented Oct 7, 2019

The MongoDBFormatter has sensible values in the constructor so I guess it can be added as a service in this bundle

The MongoDBFormatter has sensible values in the constructor so I guess it can be added as a service in this bundle
@GromNaN GromNaN changed the base branch from 4.x to 3.x September 24, 2025 08:28
<service id="monolog.formatter.json" class="Monolog\Formatter\JsonFormatter" public="false" />
<service id="monolog.formatter.line" class="Monolog\Formatter\LineFormatter" public="false" />
<service id="monolog.formatter.loggly" class="Monolog\Formatter\LogglyFormatter" public="false" />
<service id="monolog.formatter.mongo_db" class="Monolog\Formatter\MongoDBFormatter" public="false" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<service id="monolog.formatter.mongo_db" class="Monolog\Formatter\MongoDBFormatter" public="false" />
<service id="monolog.formatter.mongodb" class="Monolog\Formatter\MongoDBFormatter" public="false" />

@jmikola
Copy link
Contributor

jmikola commented Oct 20, 2025

@GromNaN: Am I correct in assuming that defining a service here still requires it to be enabled via the formatter option for a handler definition? Per the custom formatter docs.

I expect this eventually would warrant changes to https://github.com/symfony/symfony-docs/blob/7.3/logging/formatter.rst as well to list this in the documentation.

@GromNaN
Copy link
Member

GromNaN commented Oct 20, 2025

Looking at Seldaek/monolog@c04d39d, the MongoDBFormatter is the one by default since Monolog 2.

We can create a new mongodb type handler that uses the service MongoDBFormatter by default as handler and passes the constructor options ($maxNestingLevel and $exceptionTraceAsString). Similar to this:

if (empty($handler['formatter'])) {
$formatter = new Definition("Monolog\Formatter\FlowdockFormatter", [
$handler['source'],
$handler['from_email'],
]);
$formatterId = 'monolog.flowdock.formatter.'.sha1($handler['source'].'|'.$handler['from_email']);
$formatter->setPublic(false);
$container->setDefinition($formatterId, $formatter);
$definition->addMethodCall('setFormatter', [new Reference($formatterId)]);
}

@jmikola
Copy link
Contributor

jmikola commented Oct 23, 2025

@GromNaN: I've incorporated the assignment of a default MongoDBFormatter in #550

This only applies to handlers created with the new mongodb syntax, and the default ctor args of MongoDBFormatter are used. If customer args are required, users can rely on the common formatter config syntax and specify a service ID.

@GromNaN
Copy link
Member

GromNaN commented Oct 23, 2025

Superseded by #550. Thank you @wimme002

@GromNaN GromNaN closed this Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants