I need to add trackability information for all logs.
E.g. logged in user and route parameters (entity ID)
Right now I have this code:
use Monolog\Processor\ProcessorInterface;
class RequestProcessor impelements ProcessorInterface {
public function __construct(
private RequestStack $requestStack,
) {
}
public function __invoke(LogRecord $record): LogRecord {
$request = $this->requestStrack->getCurrentRequest();
$record = $record->with(
context: [
'route' => $request->attributes->get('_route'),
],
);
return $record;
}
}
Problem is that some logs (e.g. deprecations) are logged before `Kernel::request` event. That means there is no "current request" in strack.
Same with logged in user information.
---
Tried adding Bulk Handler, but it seem no processor were executed after flush, as processors are applied before passing log to handler
monolog:
handlers:
info_buffer:
type: buffer
handler: info_only
info_only:
type: filter
handler: info_log
channels: ['!database', '!elasticsearch_client', '!security']
accepted_levels:
- info
info_log:
type: stream
level: debug
bubble: false
channels: ['!database']
path: "%kernel.logs_dir%/info.jsonl.log"
formatter: app.log.formatter.json