'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 1:[1]

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);

Solution 2:[2]

Try

php artisan config:cache

If the issue is related to laravel application cache, then the artisan command will help to cache all your config files ( with current changes ) into a single file. In laravel the config values are obtain from the application cache, so you've to run this command whenever you change the config files. To update the application cache with the latest changes.

If the issue is not related to application cache, you can track the real cause using the apache2 error logs.

tail -f /var/log/apache2/error.log

Solution 3:[3]

Might be you have given permission and ownership to storage folder not insider folders like: taking case on redhat, because in case of redhat apache user is apache and in case of debian or most other www-data

folder | Permission | ownership 
storage | 775 | root:apache 
storage/logs | 755 | root:apache
storage/logs | 775 | root:root

It should be minimum

storage/logs | 775 | root:apache
or 
storage/logs | 755 | apache:apache

and please check once with APP_DEBUG=true

Solution 4:[4]

May you have accidentally changed default log path or anything in the configuration array

'single' => [
    'driver' => 'single',
    'path' => storage_path('logs/laravel.log'),
    'level' => 'debug',
],

Solution 5:[5]

Ensure that your log level is set to debug, and remember to clear your config cache after changing that value

.env file 
APP_LOG_LEVEL=debug

run in console
php artisan config:cache

Solution 6:[6]

So two things here:

  1. Double-check if you definitely have the below on your .env file, basically checking to see if it's not a falsey value.:
APP_LOG=daily
  1. Make sure your storage directory is writable to the server user:
chmod -R 755 storage

Solution 7:[7]

change the file permission to 777 and if the errors exist in log file it is for permission . you can check the user run php using :

ps aux | egrep '(apache|httpd)'

and correct the file permission .

if the problem is not for permission then you can use error_get_last() after the code lines you write in the log file and see what is the error.

if you don't have error maybe the address of write log file in config is incorrect

Solution 8:[8]

if previously the logging was ok, and you see wrong encoded stringsg

then its easy to fix. Clear log file and in dropup list in very bottom-right(mine was UTF-16LE) pickup utf-8 encoding . Hit on convert button (in the arisen popup dialog with three buttons) and also further you can use:

echo "" > storage/logs/laravel.log

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Debiprasad
Solution 2 Ajay
Solution 3 Nitin Sharma
Solution 4 dipenparmar12
Solution 5 Jon Winstanley
Solution 6 melonlogic
Solution 7 parisam
Solution 8