Laravel 5.5升级至5.6后Logger仍无法正常运行的技术求助
Hey there, let's work through this logging problem you're facing after upgrading to Laravel 5.6. The initial "Log [] is not defined" error is a common gotcha with the new logging system introduced in 5.6, and even after adding the config/logging.php file, there are a few key checks to make:
1. Update Your .env File
Laravel 5.6 replaced the old APP_LOG environment variable with LOG_CHANNEL. If you're still using the old variable, the logger won't know which channel to use.
- Open your
.envfile - Replace any line like
APP_LOG=singlewithLOG_CHANNEL=single(or match the channel you want to use, e.g.,stack) - Make sure the channel name matches one defined in your
config/logging.phpfile
2. Verify config/logging.php Configuration
Double-check that your logging.php has valid channel definitions and a correct default channel:
- Ensure the
defaultkey points to an existing channel:'default' => env('LOG_CHANNEL', 'stack'), - Confirm the channel you're using is properly defined in the
channelsarray. For example, the defaultsinglechannel should look like this:'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), 'level' => 'debug', ], - If using the
stackchannel, make sure it lists valid child channels:'stack' => [ 'driver' => 'stack', 'channels' => ['single'], 'ignore_exceptions' => false, ],
3. Clear Configuration Cache
Old cached configuration can cause conflicts after an upgrade. Run these commands to clear cached config and application cache:
php artisan config:clear php artisan cache:clear
4. Check Log Directory Permissions
Ensure the storage/logs directory has proper write permissions for the web server or CLI user. You can set the correct permissions with:
chmod -R 755 storage/ chown -R www-data:www-data storage/ # Adjust user/group to match your server setup
5. Confirm Composer Dependencies Are Up-to-Date
Make sure your composer.json specifies Laravel 5.6 and you've run composer update to pull in the correct framework version:
composer update laravel/framework
After going through these steps, test your logger again (e.g., use Log::info('Test log message'); in a route or controller). If you're still having issues, share any new error messages or details about your logging.php setup, and we can dig deeper.
内容的提问来源于stack exchange,提问作者Handige Harrie

