symfony / symfony-docs

The Symfony documentation
https://symfony.com/doc
Other
2.17k stars 5.12k forks source link

Built-in monolog processors not documented correctly #18217

Closed ash-m closed 1 year ago

ash-m commented 1 year ago

How to Add extra Data to Log Messages via a Processor claims:

Symfony's MonologBridge provides processors that can be registered inside your application.

Given the instructions for how to implement a custom processor in services.yaml immediately preceding that text (which I would consider "registering"), I would expect the built-ins to be registered something like:

services:
  Symfony\Bridge\Monolog\Processor\WebProcessor:
    tags:
      - { name: monolog.processor, channel: main }

But this will result in an error:

You have requested a non-existent service "monolog.logger.main". (500 Internal Server Error)

The correct way to use it is (apparently) just specifying the class without tags, though I don't really understand why that is the case or how built-in processors like that should be configured (eg: which channel?)

The same goes for monolog built-ins which the article links to:

:link: Check out the built-in Monolog processors to learn more about how to create these processors.

Though that may just be indicating that Symfony has used some of the monolog built-ins for it's bridge and you can use them for reference rather than how to actually implement individual monolog built-ins. Still some clarification on that would help.

94noni commented 1 year ago

The correct way to use it is (apparently) just specifying the class without tags

as far as I remember, the tag monolog.processor is required (so that it is properly registered), but the channel not, and not defining channel will attach this processor to all monolog channels

You have requested a non-existent service "monolog.logger.main". (500 Internal Server Error)

do you have a monolog channel named main in your config?

ostrolucky commented 1 year ago

Correct. You are in "Registering Processors per Channel" section, so this works only if you have logger with same channel. Nothing wrong with docs there IMO. Error message could be improved, but that improvement would go to https://github.com/symfony/monolog-bundle

stof commented 1 year ago

Well, if you haven't created a main channel, this error is expected if you try to register your processor for the main channel only.

Note that the default channel of monolog-bundle is named app

stof commented 1 year ago

and if you omit the channel in the tag, it gets registered for all channels.

javiereguiluz commented 1 year ago

Thank you all for your review. We're trying to improve this in #18901.