Analyzing class Disqontrol\Logger\JobLogger
A logger that can add job debug information to the log messages
We use the second argument, $context, to send jobs to the logger. If the caller includes a job object in the $context, we presume it wants to add details about the job, so we add a debug level message with the job details.
To add job details to any log message, just add this to the second argument, $context:
$context[JobLogger::JOB_INDEX] = $job;
I have considered three solutions: - Adding a Monolog processor and a handler - Inheriting the Monolog logger and overriding parent methods - Encapsulating the logger and calling it as a dependency
I have ruled out the first solution, because we want to emit two messages from one call and neither a handler or a processor are the right place. I have tried the second solution, inheritance, but the constructor was complex and unit testing was not easy without mocking the tested class. In the end I have decided to use composition and encapsulate the original logger.