原木位于何处?

我正在调试一个 JSON 端点,需要查看内部服务器错误。但是,我的 app/storage/logs目录是空的,似乎没有其他目录专门用于项目中的日志。我试过在谷歌上搜索这个话题,但是没有用。

如果日志尚未启用,我如何启用日志并查看日志?

161464 次浏览
  • Ensure debug mode is on - either add APP_DEBUG=true to .env file or set an environment variable

  • Log files are in storage/logs folder. laravel.log is the default filename. If there is a permission issue with the log folder, Laravel just halts. So if your endpoint generally works - permissions are not an issue.

  • In case your calls don't even reach Laravel or aren't caused by code issues - check web server's log files (check your Apache/nginx config files to see the paths).

  • If you use PHP-FPM, check its log files as well (you can see the path to log file in PHP-FPM pool config).

You should be checking the root directory and not the app directory.

Look in $ROOT/storage/laravel.log not app/storage/laravel.log, where root is the top directory of the project.

In Laravel 6, by default the logs are in:

storage/logs/laravel.log

Ensure that APP_DEBUG=true is set to on on you .env

If you want to easily check your storage log you can install:

https://github.com/rap2hpoutre/laravel-log-viewer

You can access the location programmatically by storage_path() . '/logs':

$logFiles = array_filter(
scandir(storage_path() . '/logs'),
fn($fn) => !str_starts_with($fn,'.') // filter everything that begins with dot
);

The location of the log file can be found inside channels array config/logging.php (See below)

enter image description here

In case if some one is looking to write to the single channel, using Laravel's Log Facade, here's how to do.

Log::channel('single')->info('Your message');