Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rubendn's avatar

Log 404 Errors to a separate log

It seems like Laravel doesn't log 404 exceptions by default.

I would like to log 404 errors to it's own log file. With everything I've found in the Docs and searches online, I have not been able to achieve any 404 errors logged, much less to their own log.

It is on Laravel 10.x

0 likes
6 replies
CatherineCoulombe's avatar

Hy there i can see your post and i must say

Create a Custom Log Channel: In your config/logging.php configuration file, define a new log channel for 404 errors. Use the Custom Log Channel: In your application's exception handler (app/Exceptions/Handler.php), update the report method to log 404 exceptions to the newly created log channel: Configure Logging Level: https://www.adpworkforce-now.com/ Make sure the logging level for the custom channel is set to 'error' or any appropriate level for 404 errors.

Clear Configuration Cache: After making changes to your configuration files, clear the configuration cache using the command:

Thanks and regards CatherineCoulombe

rubendn's avatar

I kinda got the same response from the AI tool in the forum but it looks like it was based on a previous version of Laravel.

rubendn's avatar

This is what I have tried but it doesn't look like it's being triggered...

In the logging.php config file added another channel:

        '404' => [
            'driver' => 'daily',
            'path' => storage_path('logs/404.log'),
            'level' => 'error',
        ],

In the Handler.php file

        $this->reportable(function (NotFoundHttpException $e) {
                Log::channel('404')->error($e);
        });
rubendn's avatar

This is how I'm handling it for now...

I've added the following to the top of my custom 404 blade file...

@php
    Log::channel('404')->error(app('request')->fullUrl());
@endphp
Snapey's avatar

There is a reason 404s are not logged.

If you get this setup you will realise what a complete nightmare the internet is. Your logs will be absolutely full of requests for pages that have absolutely nothing to do with your site. Things like wordpress admin pages etc etc.

Any 404s that are genuinely for your app will be like less than 1% of requests and almost impossible to find in the noise.

If you want to gauge this, just have a look at your web server logs.

I've yet to find any legitimate reason to care about 404s

puklipo's avatar

404 errors are disabled in the framework.

https://laravel.com/docs/11.x/errors#ignoring-exceptions-by-type

Laravel11

// bootstrap/app.php

use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->stopIgnoring(HttpException::class);

        $exceptions->report(function (NotFoundHttpException $e) {
            Log::build([
                'driver' => 'daily',
                'path' => storage_path('logs/404.log'),
                'days' => 7,
            ])->info($e->getMessage());
        })->stop();
    })

To others

Don't log 404 errors.

1 like

Please or to participate in this conversation.