mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-26 16:15:49 +03:00
[GH-ISSUE #1961] Handler of type "service" doesn't respect configured level #846
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#846
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @micter59 on GitHub (Apr 1, 2025).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1961
Hello,
I posted an issue here, but with no response. I try my chance here.
My goal is to store logs with level "error" in a DB, just to facilitate their readings from inside my app. I've written a simple custom handler :
The service is declared in the "services.yaml" file, with the needed entitymanager as argument :
And I've added this handler in the configuration of the monolog bundle :
Log entries are effectively written to the database, but the "level: error" in the monolog.yaml is not respected. All log levels are written (info, debug are written for example). I could filter this in my handler, but this would be more practical to be able to change this as needed in the yaml file. Is this a bug, or do I missed something in my configuration or in the documentation ?
PHP 8.2
Symfony 7.2.3
Monolog 3.10.0
Thank you.
Michaël
@stof commented on GitHub (Apr 1, 2025):
When using the type
service, you are responsible for configuring the service definition of your service (as MonologBundle has no idea how your class looks like). So the extra config settings are no-op (channelsis not a no-op as this is about configure where the handler is injected, not about configuring the handler itself).You need to pass the level in the
parent::__construct()call in your class (as you omit the argument, the default level will be used, and it is noterrorbutdebug)@micter59 commented on GitHub (Apr 1, 2025):
Thanks for your quick answer. I think I understand what you mean.
I now have to find how to pass log level to my class. This will be in the "services.yaml", I am right ?
Do you have any doc elsewhere to describe how to do please ?
@micter59 commented on GitHub (Apr 1, 2025):
Just to be sure, here's the modified constructor of my class :
But log level is not respected. That's why I'm looking in the services.yaml.
@micter59 commented on GitHub (Apr 3, 2025):
Hello. Even, with the constructor modified as I mentioned it before, the log level is not correctly passed to my class.
I've found nothing about add something in the services.yaml.
Googling a bit more about that, i've only found this issue which seems pretty similar to what I face : https://github.com/symfony/monolog-bundle/issues/322.
@stof commented on GitHub (Apr 3, 2025):
if you make it configurable in your own constructor, you need to configure it when configuring your service (which is not specific to monolog-bundle at all)
@micter59 commented on GitHub (Apr 3, 2025):
I'm not sure to understand you well, when you say "So the extra config settings are no-op". Sorry, english is not my first language. Is the information "level" coming from the monolog.yaml file, passed to my class at any moment ? If yes, I know how to check this in my class. I could overwritte the "handle" method herited from the AbstractHandler. But for now, I can't get the information coming from the yaml file, so I hard coded it. I hope what I write is understandable...
@stof commented on GitHub (Apr 3, 2025):
When using
type: service, any configuration of the handler has to be done when configuring the service (for which you give the id in the monolog-bundle configuration). It cannot be done through the monolog-bundle semantic configuration as monolog-bundle is not the one defining the service definition for the handler in that case.@micter59 commented on GitHub (Apr 3, 2025):
OK. So I understand I have to put it directly in the "arguments" section of the "services.yaml", and won't be able to get it from "monolog.yaml". Thank you for your patience with me.