首页 > 解决方案 > Log file is not being written in Laravel 5.5

问题描述

I have logging enabled by default on Laravel 5.5.

The settings are:

In config/app.php file:

'log' => env('APP_LOG', 'single'),

'log_level' => env('APP_LOG_LEVEL', 'debug'),

In .env file:

APP_LOG_LEVEL=debug

If any error happens on the application, I can see the exception page. But I don't see it in the log file anymore. It was working fine a couple of months ago. Even when I try to log manually, it does not log it.

Log::debug('Notification');

I have code to create files using Storage and it's working fine. So, I don't think it's some permission issue. What could be the reason behind this?

标签: phplaravelloggingmonolog

解决方案


我发现了这个问题。我正在使用 Bugsnag(用于生产)并且我已经在项目中设置了它。

当我集成它时,我使用了它在仪表板上的说明,我认为这并不完整,因为他们在他们的文档中有它。因此,我在我的应用程序服务提供者 app/Providers/AppServiceProvider.php 的注册方法中添加了以下代码。

$this->app->alias('bugsnag.logger', \Illuminate\Contracts\Logging\Log::class);
$this->app->alias('bugsnag.logger', \Psr\Log\LoggerInterface::class);

在我的本地环境中,我没有BUGSNAG_API_KEY在我的.env文件中设置。因此,它既没有将异常发送到 Bugsnag,也没有登录到本地 laravel.log 文件。

当我将 Bugsnag 集成到另一个在 Laravel 6 上运行的项目时,我怀疑这个问题并检查了文档。在那里我找到了保持记录到我的原始记录器以及 Bugsnag 所需的代码。

$this->app->alias('bugsnag.multi', \Illuminate\Contracts\Logging\Log::class);
$this->app->alias('bugsnag.multi', \Psr\Log\LoggerInterface::class);

推荐阅读