phplaravelloggingmonolog

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?


Solution

  • I found the issue. I am using Bugsnag (for production) and I had set it up in the project.

    When I integrated it, I used the instruction it had on its dashboard, which I believe was not complete as they have it on their documentation. So, I had added the following code in the register method of my application service provider app/Providers/AppServiceProvider.php.

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

    In my local environment, I had not set the BUGSNAG_API_KEY in my .env file. So, it was neither sending the exceptions to Bugsnag nor logging into the local laravel.log file.

    When I was integrating Bugsnag to another project which runs on Laravel 6, I suspected this issue and checked the documentation. There I found the code which is needed to keep logging to my original logger as well as Bugsnag.

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