-
Notifications
You must be signed in to change notification settings - Fork 74
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 job error logging #309
base: 4
Are you sure you want to change the base?
Add job error logging #309
Conversation
Use a job error logger which logs all of the issues inside job messages. If job execution fails and triggers errors, all relevant information will be present in the job messages which makes the debugging process for developer that much easier. - Add Logger class - Add unit test for Logger class - Update README document
README.md
Outdated
$logger = new Logger(); | ||
$logger->setJob($job); | ||
$helper = Helper::create(); | ||
$helper->setLogger($logger); |
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.
I think this example should be changed to reflect a more common situation where the logging is attached within the job execution. i.e. within the process()
function of the job
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.
You mean something like this?
$logger = new Logger();
$logger->setJob($job);
$helper = Helper::create();
$helper->setLogger($logger)
->run();
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.
Something like this:
// within your job class
public function process(): void
{
$logger = new Logger();
$logger->setJob($this);
Helper::create()
->setLogger($logger)
->run();
}
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.
Given that Helper
isn't defined, I still think this is quite confusing. Regardless, I'm not sure why there's a need to mix in the concept of a "helper class" with the creation of a logger, seems like unnecessary noise? It's pretty clear how a logger can be used (incl. passing it to other hypothetical dependencies) once it's created.
How does this relate to the logging that's already in place there? I think this might have gotten introduced after you forked off this repo? We did this in context of the "file migration task" work for 4.4.0. https://github.com/symbiote/silverstripe-queuedjobs/blob/4/src/Services/QueuedJobService.php#L875 Also, I'm improving this implementation with this PR: #310 |
@chillu I think the difference is that the logger in place is for the queue runner and the logger which this PR is adding is for job execution only. This covers the case where job execution is covered by a helper and is more complex. We used this in the SS3 to SS4 migration. |
Looks good, thanks @shoosah :) |
I don't believe a logger which handles messages directly is in keeping with the From what I can tell, this will also cause duplicate And finally, I don't believe it should be up to the individual job to decide how its messages are logged, that belongs in the parent execution context ( So please have a read through |
Thanks for feedback, will have a look at your PR :) |
Feedback for your points:
|
interface UsesLogger
{
public function setLogger(LoggerInterface $logger);
public function getLogger() : LoggerInterface;
}
class MyJob extends Job implements UsesLogger
{
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function process()
{
$this->logger->setLevel(<new-level>);
$this->logger->debug('...');
$this->logger->setLevel(<old-level>);
}
}
class QueuedJobService
{
public function runJob()
{
// ...
if ($job instanceof UsesLogger) {
$job->setLogger($logger);
}
}
How is this not duplicating
Would this still hold once my PR gets merged? It fixes an inconsistency where it calls
Thanks for spelling that out, easy to lose the forest for the trees in these discussions. It feels like my suggestion above achieves this, you could log everything debug level in your particular job, and then only look at the messages tagged with that level in the log channels (so either the database record, stdout, Raygun, etc) |
Thanks @chillu , will pick this is up next hackday but it looks like we're on the same page 👍 |
@shoosah @mfendeksilverstripe This pull request hasn't had any activity for a while. Are you going to be doing further work on it, or would you prefer to close it now? |
@Cheddam I believe that this PR is still useful as the error logging for jobs can be really resource heavy for larger sites. I'll add this to my TODO list as this is definitely something I would like to pick up eventually. |
Use a job error logger which logs all of the issues inside job messages. If job execution fails and triggers errors, all relevant information will be present in the job messages which makes the debugging process for developer that much easier.
Notes
Split from Feature batch as
Feature 8 - Job error logging