-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to know if the logger has handlers which handle a level #53
Comments
there is an issue here: an handler decides to handle a specific message. All built-in handlers use only the level for this but you could imagine other behaviors for a custom handler: handling the message only for a specific channel, or only when some key exist in the context, or even randomly if you see a reason to do so. |
Yes but my interest here is to know if there is at least one handler which is able to handle my message according to the level. I will give an example: <?php
if ($logger->hasHandlers(Logger::DEBUG) {
$logger->addDebug('my_message');
} With that, before adding a debug message, I'm able to detect if there is indeed an handler which will be able to handle my message. |
well, you can add the debug message. Monolog already checks internally if the message is handled by an handler (and supporting any check done in the handler) and returns early otherwise. |
Sorry but I will try to explain me better. What I want to do is to instanciate an object which will debug the execution time of some queries if there is an handler which is able to handle the level I use. So, I would like my code looks like: <?php
$debugStack = new DebugStack();
if ($logger->hasHandlers(Logger::INFO)) {
$debugStack->start();
}
// Execute queries
if ($logger->hasHandlers(Logger::INFO)) {
$debugStack->stop();
$logger->addInfo($debugStack->toString());
} I hope you understand my interest to detect if the logger can handle my message :) |
I guess a better implementation would be to use something similar to the existing
It's not so efficient though to create a dummy log record and loop through handlers. |
That's exactly what I want :) Are you agree to add this feature to the core? |
Done |
Thanks ! |
Hi,
I'm currently integrating Monolog in a project which needs to know if the logger has handlers for a specific level. In this case, my app will create some specific objects in order to debug more precisely what's happened.
Currently, I must override the logger for being able to acces handlers.
If you're OK with this feature, I will create a PR.
The text was updated successfully, but these errors were encountered: