bilfeldt / laravel-request-logger

Log Laravel application request and response with a unique ID for easy debugging
MIT License
97 stars 10 forks source link

ignoredPaths still get logged #29

Closed eelco2k closed 9 months ago

eelco2k commented 9 months ago

The ignored paths still get logged in db. For example /filament/update and /_debugbar/open.

this is my config array for ignored_paths:

'ignore_paths' => [
        '_debugbar*',
        'debugbar*',
        'telescope',
        'telescope-api*',
        'horizon*',
        'nova-api*',
        'livewire*',
    ],

I'm having multiple log drivers so maybe that makes it still log to db....

I used the Middleware method and added it to Kernel.php.

in the Listeners/LogRequest.php there is a if check but the logging is done after the if.

if ($this->shouldLog($event->request, $event->response)) {
            $event->request->enableLog();
}

foreach (array_unique($event->request->attributes->get('log', [])) as $driver) {
                RequestLoggerFacade::driver($driver)->log(
                    $event->request,
                    $event->response,
                    $duration,
                    $memory
                );
            }

when i move the foreach within the if statement no more logs for ignored items.

like so:

if ($this->shouldLog($event->request, $event->response)) {
            $event->request->enableLog();

            foreach (array_unique($event->request->attributes->get('log', [])) as $driver) {
                RequestLoggerFacade::driver($driver)->log(
                    $event->request,
                    $event->response,
                    $duration,
                    $memory
                );
            }
}
eelco2k commented 9 months ago

I see that when using the Middleware it executes the Request Macro 'enableLog', so via that way enableLog is already enabled. so it doesn't matter if ($this->shouldLog($event->request, $event->response) == true / false), it will always be enabled an therefor also log all events in the foreach

bilfeldt commented 9 months ago

I see that when using the Middleware it executes the Request Macro 'enableLog', so via that way enableLog is already enabled. so it doesn't matter if ($this->shouldLog($event->request, $event->response) == true / false), it will always be enabled an therefor also log all events in the foreach

Correct. This is expected behaviour.

eelco2k commented 9 months ago

So when enabled via middleware all configs will be ignored… not only ignored paths but also allowed methods etc…

bilfeldt commented 9 months ago

So when enabled via middleware all configs will be ignored… not only ignored paths but also allowed methods etc…

Correct. Use either middleware or config approach.