In a project I have three environment files for testing
.env.testing
for unit/feature tests, .env.dusk.local
for local Dusk tests, and .env.dusk.testing
for CI/CD Dusk tests. I’m trying to set the log channel for all of these to null
, because I don’t need tests to log anything at all.
When I replace the logging variables in these files with:
LOG_CHANNEL=null
…and try to run the Dusk tests, I get the following in my logs:
[2023-10-26 18:38:28] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at D:\Path\To\Site\mysite\vendor\laravel\framework\src\Illuminate\Log\LogManager.php:210)
[stacktrace]
...
I know this should be possible based on the documentation, and I’ve confirmed that I have the following set up in logging.php
:
'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],
I’ve also run php artisan optimize:clear
to rule out the configuration cache. For what it’s worth, I did use Laravel Shift to upgrade to Laravel 9 recently, in case this is a dependency or version-specific issue.
2
Answers
Laravel doesn’t consider every
.env
variable as string, there are special keywords that will be converted to other types. In your case,null
seems to be converted effectively to anull
value inside Laravel.Try to change your channel name to something else (like
nullable
for example):Or you can also try to wrap
null
inside double quotes in your.env
file:LOG_CHANNEL="null"
Reference: https://laravel.com/docs/10.x/configuration#environment-variable-types
Another solution, also this seems to be not well documented, is to use
null
driver like this:You can try this and see. (It wasn’t tested)
In
config/logging.php
and run
Make sure in
.env