randomcast's avatar

Unable to disable deprecations logging

I cannot seem to disable deprecations loggings/attempts of loggings, running Laravel 9.11.

My logging.php config file is not altered, containing:

    'deprecations' => [
        'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
        'trace' => false,
    ],

and my env file has

LOG_DEPRECATIONS_CHANNEL=null

However, i still keep getting deprecations logging attempts, where the logger logs deprecations in regular app log because it can't seem to find deprecations logging config {"exception":"[object] (InvalidArgumentException(code: 0): Log [deprecations] is not defined..

I can create a deprecations logging channel like this in logging.php

        ...
        'deprecations' => [
		    'driver' => 'single',
		    'path' => storage_path('logs/php-deprecation-warnings.log'),
	    ],

but i want to disable them completely.

Why is Laravel ignoring LOG_DEPRECATIONS_CHANNEL=null?

1 like
2 replies
MortenS's avatar

I was also stumped by this, but it's actually explained in the docs:

Or, you may define a log channel named deprecations. If a log channel with this name exists, it will always be used to log deprecations

So if you want to be able to toggle deprecation logging on/off via .env, you have to rename the deprecations channel to something else.

imrandevbd's avatar

When Laravel sees this, it tells the framework: "Hey, look for a dedicated log channel named deprecations inside the channels array, and route it based on the env variable." But because you don't actually have a channel named deprecations defined inside your channels array, the driver look-up crashes and defaults to falling back into your standard app log. Setting it to null doesn't stop the framework from trying to find the missing channel configuration block.

To fix this and completely silence deprecations without things blowing up, you just need to explicitly define the deprecations channel as a null driver inside your channels array.

Open config/logging.php and update your channels list

Please or to participate in this conversation.