cbloss793
cbloss793

Reputation: 1649

Laravel 5.6 Upgrade caused Logging to break

Heey!

So I've recently been given the task to take a Laravel 5.2 up to 5.6. It seemed to be fine...until I tried to do a \Log::info(). Every time I run that, I get a big error, but at the end, it still prints to the log. I saw the 5.6 documentation on creating the config/logger.php. I took a fresh copy of it from github. The only thing I did after that was set an env variable for the LOG_CHANNEL to be single. Here's the error I get:

[2018-03-02 08:28:59] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at I:\xampp\htdocs\mtm\vendor\laravel\framework\src\Illuminate\Log\LogManager.php:181) [ ....

I did a file comparison between Laravel 5.2 and 5.6. I'm not seeing anything that jumps out that would break the Logging functionality.

Has anyone run into this with a Laravel upgrade?

Upvotes: 47

Views: 46394

Answers (11)

ssi-anik
ssi-anik

Reputation: 3714

In case someone reaches here just like I did.

After upgrading the legacy application from Lumen 6 to Lumen 10 and PHP 7.4 to PHP 8.3, I faced the same issue.

On Lumen 10 (since Lumen 8.x), it started logging deprecations as deprecations instead of exceptions

For logging deprecations, it tries to log it to a different channel based on the configuration. However the config file is too old, and the log channel does not exist in the configuration. That's why it creates an emergency logger that was luckily pointed to my single driver's path.

I hope this explains the issue and the next person who reaches here will get a hint.

Upvotes: 0

Kaleemullah
Kaleemullah

Reputation: 544

Problem Statement

[2023-03-10 09:41:21] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at /home/5835934853094/domains/--------.com/public_html/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:207)

Solution 100% Work

  1. This Problem is due to Cache and php version.
  2. You need remove cache from
  3. storage/Framework/views/
  4. storage/Framework/session/
  5. storage/Framework/cache/
  6. You need upgrade to php version 8.1 if you are using laravel 9.19 or above

Upvotes: 0

MohamedBenhida
MohamedBenhida

Reputation: 616

Add this file to your config folder https://github.com/laravel/laravel/blob/5.6/config/logging.php

and add this to your .env file LOG_CHANNEL=stack

Don't forget to run php artisan config:clear command afterwards.

Upvotes: 53

chu palema
chu palema

Reputation: 1

all right, i got it take a look at the official library, copy log config configuration code :

link :https://github.com/laravel/laravel/blob/5.6/config/logging.php

create in your project's config directory logging.php file copy the code in

clear the cache :php artisan config:clear

that's it. keep stomping ...

Upvotes: 0

Ngugi Kiarie
Ngugi Kiarie

Reputation: 1448

I had the same issue, turns out I had accidentally moved the config folder. If you find yourself in the same situation, (probably as embarrassed as I am) move it back to the root folder of your project.

Regards

Upvotes: 0

Manjiri Parab
Manjiri Parab

Reputation: 131

In my case, APP_LOG= was blank in .env file so I saved it as APP_LOG=single and it worked.

Upvotes: 1

Libra Ramis
Libra Ramis

Reputation: 393

I was facing the same issue due to upgrade of my laravel version from 5.3 to 5.7. But after search of few mints i found the solution. You just need to follow the following steps.

  1. create logging.php file inside the config folder.
  2. Copy code from this Official Link of Laravel.
  3. Past this code into your logging.php file.
  4. run this command -- php artisan config:clear

All done. Happy Coding :)

Upvotes: 23

Son Nguyen
Son Nguyen

Reputation: 401

I got the same problem and tried to do everything as you did but not work.

Finally, I've found that it was because of cached config, just clear it and everything will be fine:

php artisan config:clear

Upvotes: 11

Parisa
Parisa

Reputation: 801

use upgrade guide , and add logging.php to your config files.

Upvotes: 5

nensamuel
nensamuel

Reputation: 596

After two days of some research, I found a solution on Github.

If you are using Laravel 5.5.4 to Laravel 5.6.*, then you can just install and configure the exceptions package by Graham Campbell.

Link: https://github.com/GrahamCampbell/Laravel-Exceptions

This worked perfectly for me on Mac OSX (PHP 7.1.7), Laravel 5.6.22

My initial error:

2018-05-25 14:35:07] laravel.EMERGENCY: Unable to create configured logger. 

Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at /Users/pro/Sites/metiwave/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:181)

Upvotes: 4

Marco Cazzaro
Marco Cazzaro

Reputation: 701

I recently had the same error in my development machine (and not in the production one, oddly). In my development machine I have both php 7.1 and php 7.2 installed. Checking with phpinfo(), I discovered that 7.1 was the default version, so I decided to switch to 7.2.

sudo a2dismod php7.1
sudo a2enmod php7.2
sudo systemctl restart apache2

That didn't solve the problem (but maybe was part of it).

After several hours spent on trying everything suggested around the web, I found my solution by:

  1. Checking all the permissions in the storage folder.
  2. In my project folder, clearing all the cache(s) and config(s).
  3. Dumping all composer autoload files.

In detail:

cd your_project_full_path
sudo chmod -R 0775 storage
sudo chown -R www-data:www-data storage
php artisan config:clear
php artisan view:clear
php artisan route:clear
composer dump-autoload

After this, I had no problem any more. Maybe try 0755 as permission for the storage folder. Hope this helps!

Upvotes: 7

Related Questions