symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.75k stars 9.46k forks source link

[Monolog Bridge] WebProcessor not called for 404 errors #27635

Closed mathroc closed 3 years ago

mathroc commented 6 years ago

Symfony version(s) affected: ^3.4|^4.0

Description

The Symfony\Bridge\Monolog\Processor\WebProcessor is supposed to add information to log messages about the request (ip, host, etc.) but it does not work for 404 errors because only the subrequest created by the exception listener triggers the kernel.request event

Possible Workaround

I use this instead of directly Symfony\Bridge\Monolog\Processor\WebProcessor

use Symfony\Bridge\Monolog\Processor\WebProcessor;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class MonologWebProcessor
{
    public function onKernelRequest(GetResponseEvent $event)
    {
        parent::onKernelRequest($event);

        if (empty($this->serverData)) {
            $this->serverData = $event->getRequest()->server->all();
            $this->serverData['REMOTE_ADDR'] = $event->getRequest()->getClientIp();
        }
    }
}

I'm not sure how this should be fixed properly. is it normal to only have the subrequest trigger this event ?

Simperfit commented 5 years ago

@mathroc do you want / have time to work on a fix ?

mathroc commented 5 years ago

@Simperfit I don't know how this should be fixed properly

carsonbot commented 3 years ago

Hey, thanks for your report! There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

carsonbot commented 3 years ago

Could I get a reply or should I close this?

xabbuh commented 3 years ago

@mathroc Do you still experience this issue on the latest patch releases? If so, could you please create a small example application that we could check out to reproduce it?