Search code examples
codeignitercodeigniter-4

Class CodeIgniter\Log\Logger" not found


I am in the progress of migrating my code from Codeigniter 4.3.4 to 4.5.1. When running through the web (auto testing doesn't produce this error), I get the error that Class "CodeIgniter\Log\Logger" not found.

Here is my backtrace:

<b>Fatal error</b>:  Uncaught Error: Class &quot;CodeIgniter\Log\Logger&quot; not found in /var/www/html/project/system_4.5.1/Config/Services.php:403
Stack trace:
#0 /var/www/html/project/system_4.5.1/Config/BaseService.php(311): CodeIgniter\Config\Services::logger()
#1 /var/www/html/project/system_4.5.1/Config/BaseService.php(250): CodeIgniter\Config\BaseService::__callStatic()
#2 /var/www/html/project/system_4.5.1/Config/Services.php(400): CodeIgniter\Config\BaseService::getSharedInstance()
#3 /var/www/html/project/system_4.5.1/Config/BaseService.php(311): CodeIgniter\Config\Services::logger()
#4 /var/www/html/project/system_4.5.1/Config/BaseService.php(201): CodeIgniter\Config\BaseService::__callStatic()
#5 /var/www/html/project/system_4.5.1/Common.php(998): CodeIgniter\Config\BaseService::get()
#6 /var/www/html/project/system_4.5.1/Common.php(785): service()
#7 /var/www/html/project/system_4.5.1/Debug/Exceptions.php(135): log_message()
#8 /var/www/html/project/system_4.5.1/Debug/Exceptions.php(252): CodeIgniter\Debug\Exceptions-&gt;exceptionHandler()
#9 [internal function]: CodeIgniter\Debug\Exceptions-&gt;shutdownHandler()
#10 {main}
  thrown in <b>/var/www/html/project/system_4.5.1/Config/Services.php</b> on line <b>403</b><br />

I've been through the various config files to check on any differences and they seem fine but why would Codeigniter not be able to find the logger class? It is clearly there??

Interestingly amending the 4.5.1 Config\Services Logger() function like this shows that the Logger function hasn't been loaded ...??

public static function logger(bool $getShared = true)
{
    print'<pre>';print_r(get_included_files());print'</pre>';
    print'<pre>';print_r($log);print'</pre>';exit;

    if ($getShared) {
    return static::getSharedInstance('logger');
    }

    return new Logger(config(LoggerConfig::class));
}

Solution

  • I discovered that when System\Log\Logger didn't extend LoggerInterface it produced a different error. This extend the PSR Logger which on my system was on version 1 but noticed from the 4.5.1 composer.json file needed updating (I had run a Composer update before).

    I updated my composer.json file to

    "require": {
        "php": "^8.1",
        "ext-intl": "*",
        "ext-mbstring": "*",
        "laminas/laminas-escaper": "^2.13",
        "psr/log": "^3.0"
    },
    

    Ran a composer update and this fixed it. Hope that helps someone!