-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Flush loggers on kernel.reset #279
Conversation
Shouldn't we use the |
Actually I tried |
Never mind, I see the issue now. Its not ideal, but it still solves the problem adequately and |
I would use Seldaek/monolog#997 instead of using |
Yeap, that solution looks better. Hope it gets merged soon, and I'll change this PR to use that one :) |
I hope too :) |
reset is now part of Monolog 1.24.0 and above.. Would be good to update this PR. You can test for ResettableInterface being present. |
Perfect, will update it in the next few days. |
@Seldaek @lyrixx @nicolas-grekas I have updated this PR to use the There is a deprecation notice in the PHP 7.1 tests, but I don't think its related with this PR, could you guys have a look? |
Sorry for the delay. This looks better already but I am afraid attaching kernel.reset to all handlers means that some of them will end up being reset multiple times. For example a GroupHandler or BufferHandler when it gets reset it resets the handlers it contains. This is so you can simply call Logger::reset and then it trickles down to all handlers from there even tho the Logger doesn't know about all of them. I think it would be preferrable to set the tag on the Logger instances to avoid these multi-resets. |
Hmm is it a good idea to explicitly set the tag on specific loggers? Won't this be something we'll have to keep track of whenever a new logger is added? If reset is designed to trickle down to all handlers, maybe it would be better to just trigger reset on the |
Yes.. this is kinda complicated by the fact that some handlers can be only in some loggers, and not in all. But I guess resetting only the main logger would probably make sense, otherwise we end up with duplicate resets again. Channel-specific handlers might be needing a manual reset from the user in that case.. that's a trade-off we may have to live with unless someone feels like figuring out which handlers are not in the default logger chain and then tagging those for reset too.. I'm not sure what's worse between maybe double resets and maybe no reset at all. |
I think just resetting the It will certainly improve the situation compared to what it is currently, so maybe we should proceed with that? |
Yes that sounds good to me :) |
We could leverage the autoconfiguration, isn't ? |
I think the DI extension already knows which handlers are nested ones. So it could manage the tagging of non-nested ones. |
OK, so we'll leverage the the DI extension to find all the top-level handlers (like |
Is there something left to be done here? Can we help in some way? We're really interested in this PR |
I think it looks good to me now. Would be happy to get a second opinion from someone else, but for me it looks mergeable. |
@dnna the only thing i'd probably suggest is a squash of all the commits. |
@acasademont there is an option to do this automatically during the merge, no? If not I'm happy to squash them |
It took time, but here we go, this is in now. Thank you very much @dnna. |
This PR was squashed before being merged into the 3.x-dev branch (closes #279). Discussion ---------- Flush loggers on kernel.reset Fixes php-pm/php-pm-httpkernel#134 and php-pm/php-pm-httpkernel#62 When using [PHP-PM](https://github.com/php-pm/php-pm) the worker does not die at the end of the request, so the shutdown functions registered by monolog are never triggered (so for example `BufferHandler` never flushes). This PR partially fixes the problem by flushing the loggers containing a `flush` function at the end of each request. I did not use the `close` function (mentioned in Seldaek/monolog#1053) because some loggers use sockets or other connections that would be closed in this case and not be reusable in the next request. I'm not sure if this is the best solution to this problem, happy to discuss alternatives if there is a better way. Commits ------- 366f692 Flush loggers on kernel.reset
awesome thanks! hope we can have a new release of the bundle soon :D |
I made some triage recently. I will wait a bit to get some feedback and we will release it ASAP. |
Fixes php-pm/php-pm-httpkernel#134 and php-pm/php-pm-httpkernel#62
When using PHP-PM the worker does not die at the end of the request, so the shutdown functions registered by monolog are never triggered (so for example
BufferHandler
never flushes). This PR partially fixes the problem by flushing the loggers containing aflush
function at the end of each request.I did not use the
close
function (mentioned in Seldaek/monolog#1053) because some loggers use sockets or other connections that would be closed in this case and not be reusable in the next request.I'm not sure if this is the best solution to this problem, happy to discuss alternatives if there is a better way.