-
Notifications
You must be signed in to change notification settings - Fork 824
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
Add PreformattedEchoHandler
#8930
Conversation
cherry-picked from 4c3f3e6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind describing why this needs to exist in framework? It doesn't seem particularly useful to me. Wouldn't it better that the controller that renders dev output add its own preformatted tags around log output instead?
Also make logger work for stdout
Time constraints. This will be rewritten, there's an issue for this here: #5542 |
Co-Authored-By: bergice <[email protected]>
Yep, I've authored that error handler - it's a hack, and marked as |
{ | ||
if ($logger = Injector::inst()->get(LoggerInterface::class)) { | ||
if (Director::is_cli()) { | ||
$logger->pushHandler(new StreamHandler('php://stdout')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LoggerInterface
doesn't have pushHandler
methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this is one of those cases where we squint a bit, and just assume that people will not apply loggers other than Monolog for now. We're effectively using LoggerInterface as a global singleton here, since @bergice other PR on queuedjobs is configuring that singleton with additional handlers, so both of these are assuming to work off the same instance. It's pretty messy, but the answer is not to use log handlers here at all, but rather Symfony Console.
@@ -23,6 +28,8 @@ class MigrateFileTask extends BuildTask | |||
|
|||
public function run($request) | |||
{ | |||
$this->addLogHandlers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we do that in the constructor rather than the run method?
*/ | ||
protected function addLogHandlers() | ||
{ | ||
if ($logger = Injector::inst()->get(LoggerInterface::class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we have a prototype specialisation, like
Psr\Log\LoggerInterface.monolog:
type: prototype
class: Monolog\Logger
rather than taking the service and mutate its global state in here?
protected function addLogHandlers() | ||
{ | ||
if ($logger = Injector::inst()->get(LoggerInterface::class)) { | ||
if (Director::is_cli()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might worth having a separate logger class implementation rather than encoding this logic in here
lol, too late :) |
cherry-picked from 4c3f3e6