44

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?

cbloss793
  • 1,555
  • 4
  • 19
  • 30
  • 1
    Is `'Log' => Illuminate\Support\Facades\Log::class,` in your `aliases` in `config/app.php`? – ceejayoz Mar 02 '18 at 16:47
  • @ceejayoz yes it is! I did confirm that. :) Good question. – cbloss793 Mar 02 '18 at 16:52
  • Huh, very odd, then. What if you do a `Log::info` call in Tinker? Same error? – ceejayoz Mar 02 '18 at 16:53
  • Yea. The Tinker outputs null and the laravel.EMERGENCY shows up in the error log. – cbloss793 Mar 02 '18 at 17:00
  • 1
    I hope your error is already resolved. We had the same issue, and after debugging we found that APP_LOG_LEVEL needs to be all in lowercase. Unfortunately we add APP_LOG_LEVEL=ERROR, which was causing the issue – jtanmay Oct 16 '18 at 12:28
  • @jtanmay I just started out with a fresh install of Laravel 5.6. That fixed my issue. That's good to know in the future though!! I'll keep that in mind. – cbloss793 Oct 16 '18 at 20:45

10 Answers10

47

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.

N69S
  • 16,110
  • 3
  • 22
  • 36
MohamedBenhida
  • 556
  • 5
  • 4
  • 1
    I have already added the logger.php as I mentioned. It was in the upgrade. I've tried the stack instead of single in the .env but both bring back the same error. Thanks for chiming in though! – cbloss793 Mar 02 '18 at 18:59
  • @cbloss793 it's `logging.php` not `logger.php`. it solved my issue. – Amit Shah Aug 17 '19 at 08:44
  • @AmitShah that might have been it. I ended up just starting out with a fresh version and moved the pieces over. Thanks though!! – cbloss793 Aug 19 '19 at 14:48
  • 4
    That link is broken – kadrian Mar 14 '21 at 18:54
  • 1
    updated link: https://github.com/laravel/laravel/blob/5.6/config/logging.php for me, I had to add the null driver since I had the logging.php file already ``` 'null' => [ 'driver' => 'monolog', 'handler' => NullHandler::class, ], 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], ``` – Zombiesplat Jul 16 '21 at 04:34
23

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

Libra Ramis
  • 403
  • 3
  • 6
  • I did the same. I think I was missing more than that. A fresh install and move the files over worked the best. Thanks though! And welcome to Stack!! :) – cbloss793 May 02 '19 at 14:37
11

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
Son Nguyen
  • 391
  • 4
  • 11
7

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!

Marco Cazzaro
  • 661
  • 8
  • 13
  • Ohh! I appreciate you going into full detail! I am using PHP 7.1.7 which should have been fine according to the Laravel docs. Sadly, I'm on a Windows machine so the permissions is not an issue. I did do all the artisan clears you suggested and a composer dump. Still doesn't work. I wonder if I need to upgrade to PHP 7.2. – cbloss793 Mar 05 '18 at 17:38
  • PS. I gave you a vote up for a completely thorough answer. I know that will help someone. Just didn't work in my case. – cbloss793 Mar 05 '18 at 17:40
  • Thank you for you vote :) Anyway, if you are still struggling with it, another test you could do is to try creating a new app: if you still have that problem, maybe it's a matter of environment, otherwise should be an issue related to your current upgrade itself (from 5.2 to 5.6 the jump is huge!). – Marco Cazzaro Mar 05 '18 at 18:27
  • That's what I'm thinking. This is the first 5.6 app that I've got. I'm on other 5.5 and they are fine. This is the first massive update app I've done. I almost just created a new app and moved pieces over, but I didn't start this app and there was a lot of customized stuff. I may still do that. Thanks for your tips! – cbloss793 Mar 05 '18 at 18:53
  • 1
    I spent three hours on this, you had the right answer! Worked like a charm! – Alex Rindone Oct 06 '18 at 03:01
5

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

parisssss
  • 803
  • 16
  • 36
4

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)

nensamuel
  • 566
  • 8
  • 10
  • 1
    Good find! I'll have to try this on my old project and let you know if it worked for me. I ended up just using a fresh install of Laravel 5.6 and moving the pieces over. It made things so much cleaner. I am curious if it works though! +1 for researching! – cbloss793 May 25 '18 at 21:06
  • @cbloss793 I am certain it will work for you because you will get to see the error on the application and fix it easily. Thanks for the thumbs up – nensamuel May 27 '18 at 12:41
1

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

Victor Lee
  • 2,467
  • 3
  • 19
  • 37
Manjiri Parab
  • 141
  • 1
  • 16
0

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

Ngugi Kiarie
  • 1,353
  • 11
  • 9
0

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 ...

0

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
Kaleemullah
  • 446
  • 3
  • 8