Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wreckless's avatar

"Class LogManager not found in LogServiceProvider" After upgrade to PHP8.1

I just upgraded my servers from PHP7.4 to PHP8.1. Everything works great in my local (Homestead) environment, but after deploying to prod I noticed that some of the messages I expected to show up in logs weren't there. More digging revealed that the following error is being thrown:

2021/12/04 19:48:02 [error] 18025#18025: *1806449 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Class "Illuminate\Log\LogManager" not found in /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php:17
Stack trace:
#0 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Container/Container.php(873): Illuminate\Log\LogServiceProvider->Illuminate\Log\{closure}()
#1 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Container/Container.php(758): Illuminate\Container\Container->build()
#2 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(851): Illuminate\Container\Container->resolve()
#3 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\Foundation\Application->resolve()
#4 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(836): Illuminate\Container\Container->make()
#5 /home/forge/app.theaven...PHP message: PHP Fatal error:  Uncaught Error: Class "Illuminate\Log\LogManager" not found in /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php:17
Stack trace:
#0 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Container/Container.php(873): Illuminate\Log\LogServiceProvider->Illuminate\Log\{closure}()
#1 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Container/Container.php(758): Illuminate\Container\Container->build()
#2 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(851): Illuminate\Container\Container->resolve()
#3 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\Foundation\Application->resolve()
#4 /home/forge/{site}/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(836): Illuminate

This is happening on ALL of my servers. Four are running one Laravel app and another, single server is running a different Laravel app. All servers were created by Forge. Three of the servers are deployed via Envoyer, so they would be getting a new/fresh install of vendor sources each deployment.

Some, probably most, logging does work. And while there may be differences in code regarding how the logger is being called, it still seems like an environment issue since this all works fine running on PHP8.1 on my local system.

Any ideas? Thanks in advance!!

0 likes
10 replies
wreckless's avatar

@Sinnbeck Yes, I've verified on a couple of the servers that the file actually exists. The LogManager that is "not found" is even in the same directory as the LogServiceProvider.php file.

wreckless's avatar

This gets curiouser and curiouser. As mentioned, MOST logging is actually working, but I was able to find a specific case where it failed each time and started experimenting. Essentially the error is being thrown when attempting to resolve the logger from the app service container. Here's what I'm working with (Its inside of a UserEventListener):

    public function onLoggedOut($event)
    {
        logger('User Logged Out: '.$event->user->full_name);
    }

    public function onLoggedIn($event)
    {
//logger('1');
        $ip_address = request()->getClientIp();
//logger('2 ');
        // Update the logging in users time & IP
        $event->user->fill([
            'last_login_at' => now()->toDateTimeString(),
            'last_login_ip' => $ip_address,
        ]);
//logger('3');
        // Update the timezone via IP address
        $geoip = geoip($ip_address);
logger('4');
        if ($event->user->timezone !== $geoip['timezone']) {
            // Update the users timezone
            $event->user->fill([
                'timezone' => $geoip['timezone'],
            ]);
        }
logger('5');
        $event->user->save();
logger('6');
        logger('User Logged In: '.$event->user->full_name);
    }

Here's what I've found:

  1. For some reason, the call to logger() within the onLoggedOut method ALWAYS fails with the original error provided.
  2. The original call to logger within onLoggedIn() function works.
  3. HOWEVER, I added other logger calls within that same method (logger(1) - logger(6)) and only some of them work. The logger 1, logger 2, and logger 3 lines fail with the original error. But, logger 4, logger 5, logger 6 and the final/original logger lines all work. WHY would resolving the logger work on some of the lines within a function but not others?? And, more generally, how is the logger being resolved without error in some cases, but not in others??
wreckless's avatar

I should mention that logger() is just a helper method to resolve the log service, like: return app('log')->debug($message, $context);

I can swap out logger() for a call to \Log::debug() or any other context (ex \Log::info()) and get the exact same results.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Seems to be php 8.1 related somehow

wreckless's avatar

@Sinnbeck A HUGE thank you for digging up that thread. I just swapped all of my servers/sites to PHP8.0. The errors are magically gone and logging is working in all cases now. Always fun monkeying around with production servers in the middle of the day. :|

It doesn't seem to be strictly caused by PHP8.1 since I didn't have these issues on my local environment running 8.1. Maybe something with config swapping, or a setting that Forge defaults to? Either way, things are now working. Cheers, mate.

Sinnbeck's avatar

@wreckless happy to help. I am quite unsure what the cause is as well. Never seen a bug like that before. Might try recreating it with sail

Please or to participate in this conversation.