Skip to content
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 $this->getLogger() to BuildTask #9183

Closed
sminnee opened this issue Aug 19, 2019 · 4 comments
Closed

Add $this->getLogger() to BuildTask #9183

sminnee opened this issue Aug 19, 2019 · 4 comments

Comments

@sminnee
Copy link
Member

sminnee commented Aug 19, 2019

There's been a whole large discussion about refactoring BuildTask, but one incremental fix that would make things better is to provide a getLogger() method on the abstract base class of BuildTask. In the v4.5 implementation I would recommend that this simply prints to STDOUT and/or STDERR. We could provide setLogger() too, so that BuildTask runners might override this in the future.

BuildTasks could then be written to rely on a logger object rather than echos, from 4.5 on.

@dnsl48
Copy link
Contributor

dnsl48 commented Aug 19, 2019

We could provide setLogger() too, so that BuildTask runners might override this in the future.

Dependency injection definitely sounds like a good idea in this case.

@sminnee
Copy link
Member Author

sminnee commented Aug 20, 2019

I'd probably approach it as TaskRunner::runTask() supplied the logger to the build task in question (as it is the part of the system that should decide how things are logged), but perhaps it could be fetching a TaskLogger or LoggerInterface.TaskRunner from the service registry.

In an ideal interface, $logger would be an argument to TaskRunner::run() but that's a breaking change. My specific coal in this recommendation was suggesting an incremental improvement that we could squeeze into a minor release that would be a meaningful step toward an ideal UI. In particular, capturing output via a LoggerInterface does this.

@dnsl48
Copy link
Contributor

dnsl48 commented Aug 20, 2019

but perhaps it could be fetching a TaskLogger or LoggerInterface.TaskRunner from the service registry.

Well, sorry, I meant dependency injection through setLogger, and not service discovery through Injector->get.

chillu added a commit to open-sausages/silverstripe-queuedjobs that referenced this issue Jun 9, 2020
It's counterintuitive to run the queue on CLI (e.g. when testing things),
get zero error output, and then discover why the job was broken by looking at a tiny text field in the admin/jobs CMS UI.

There's an interesting edge case where the logger *does* output to CLI only when
a broken job is discovered, because that uses the logger for messages *before*
adding the job-specific handlers. And in case a Monolog logger implementation doesn't have any handlers,
it'll add a php://stderr by default. Very confusing :D

Note that modifying the singleton during execution by adding job-specific handlers isn't ideal (didn't change that status quo).
But there's no clear interface for any services being executed through a task
receiving a logger *from* the task. So we have to assume they'll use the injector singleton.
Technically it means any messages after the job-specific execution (e.g. during shutdown)
would also be logged into the QueuedJobDescriptor database record,
but you could argue that's desired behaviour.

This should really be fixed by adding BuildTask->getLogger() and making it available to all tasks,
but this is the first step to fix this specific task behaviour.
See silverstripe/silverstripe-framework#9183
chillu added a commit to open-sausages/silverstripe-queuedjobs that referenced this issue Jun 12, 2020
It's counterintuitive to run the queue on CLI (e.g. when testing things),
get zero error output, and then discover why the job was broken by looking at a tiny text field in the admin/jobs CMS UI.

There's an interesting edge case where the logger *does* output to CLI only when
a broken job is discovered, because that uses the logger for messages *before*
adding the job-specific handlers. And in case a Monolog logger implementation doesn't have any handlers,
it'll add a php://stderr by default. Very confusing :D

Note that modifying the singleton during execution by adding job-specific handlers isn't ideal (didn't change that status quo).
But there's no clear interface for any services being executed through a task
receiving a logger *from* the task. So we have to assume they'll use the injector singleton.
Technically it means any messages after the job-specific execution (e.g. during shutdown)
would also be logged into the QueuedJobDescriptor database record,
but you could argue that's desired behaviour.

This should really be fixed by adding BuildTask->getLogger() and making it available to all tasks,
but this is the first step to fix this specific task behaviour.
See silverstripe/silverstripe-framework#9183
chillu added a commit to open-sausages/silverstripe-queuedjobs that referenced this issue Aug 27, 2020
It's counterintuitive to run the queue on CLI (e.g. when testing things),
get zero error output, and then discover why the job was broken by looking at a tiny text field in the admin/jobs CMS UI.

There's an interesting edge case where the logger *does* output to CLI only when
a broken job is discovered, because that uses the logger for messages *before*
adding the job-specific handlers. And in case a Monolog logger implementation doesn't have any handlers,
it'll add a php://stderr by default. Very confusing :D

Note that modifying the singleton during execution by adding job-specific handlers isn't ideal (didn't change that status quo).
But there's no clear interface for any services being executed through a task
receiving a logger *from* the task. So we have to assume they'll use the injector singleton.
Technically it means any messages after the job-specific execution (e.g. during shutdown)
would also be logged into the QueuedJobDescriptor database record,
but you could argue that's desired behaviour.

This should really be fixed by adding BuildTask->getLogger() and making it available to all tasks,
but this is the first step to fix this specific task behaviour.
See silverstripe/silverstripe-framework#9183
chillu added a commit to open-sausages/silverstripe-queuedjobs that referenced this issue Sep 18, 2020
It's counterintuitive to run the queue on CLI (e.g. when testing things),
get zero error output, and then discover why the job was broken by looking at a tiny text field in the admin/jobs CMS UI.

There's an interesting edge case where the logger *does* output to CLI only when
a broken job is discovered, because that uses the logger for messages *before*
adding the job-specific handlers. And in case a Monolog logger implementation doesn't have any handlers,
it'll add a php://stderr by default. Very confusing :D

Note that modifying the singleton during execution by adding job-specific handlers isn't ideal (didn't change that status quo).
But there's no clear interface for any services being executed through a task
receiving a logger *from* the task. So we have to assume they'll use the injector singleton.
Technically it means any messages after the job-specific execution (e.g. during shutdown)
would also be logged into the QueuedJobDescriptor database record,
but you could argue that's desired behaviour.

This should really be fixed by adding BuildTask->getLogger() and making it available to all tasks,
but this is the first step to fix this specific task behaviour.
See silverstripe/silverstripe-framework#9183
@GuySartorelli
Copy link
Member

Closing - with the refactor of sake and BuildTask in #11341 there will be a standardised output class. It doesn't have logging functionality, but that could easily be added either at a project level or in a future enhancement in framework.

@GuySartorelli GuySartorelli closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants