Could not load class debug


#1

Hi, I have created a command, that calls another class that is used also in the web app (working fine), but when it is used from the command, throws this error:

Exception: Could not load class debug
#0 /var/app/current/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php(95): Cake\Log\LogEngineRegistry->_throwMissingClassError('debug', NULL)
#1 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(198): Cake\Core\ObjectRegistry->load('debug', Array)
#2 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(180): Cake\Log\Log::_loadConfig()
#3 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(351): Cake\Log\Log::_init()
#4 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(501): Cake\Log\Log::write('debug', 'Executing query...', Array)
#5 /var/app/current/src/SearchUtils.php(88): Cake\Log\Log::debug('Executing query...', Array)
#6 /var/app/current/src/Model/Table/GcloudComputeInstancesTable.php(118): App\SearchUtils::searchCommand(Object(Cake\ORM\Query), Object(App\Model\Entity\User), NULL)
#7 /var/app/current/src/Command/GenerateSendReportEmailCommand.php(155): App\Model\Table\GcloudComputeInstancesTable->searchCommand(Object(App\Model\Entity\User), NULL)
#8 /var/app/current/vendor/cakephp/cakephp/src/Console/Command.php(183): App\Command\GenerateSendReportEmailCommand->execute(Object(Cake\Console\Arguments), Object(Cake\Console\ConsoleIo))
#9 /var/app/current/vendor/cakephp/cakephp/src/Console/CommandRunner.php(167): Cake\Console\Command->run(Array, Object(Cake\Console\ConsoleIo))
#10 /var/app/current/bin/cake.php(12): Cake\Console\CommandRunner->run(Array)
#11 {main}

This is my Log configuration in app.php:

$debug = filter_var(env('CAKEPHP_DEBUG', false), FILTER_VALIDATE_BOOLEAN);

$log = [
    'error' => [
        'className' => 'Cake\Log\Engine\FileLog',
        'path' => LOGS,
        'file' => 'error',
        'url' => env('LOG_ERROR_URL', null),
        'scopes' => false,
        'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
    ],
    'sqllog' => [
        'className' => 'Cake\Log\Engine\FileLog',
        'path' => LOGS,
        'file' => 'sqllog',
        'scopes' => ['sqllog'],
    ],
];

if ($debug) {
    $log['debug'] = [
        'className' => 'Cake\Log\Engine\FileLog',
        'path' => LOGS,
        'file' => 'debug',
        'url' => env('LOG_DEBUG_URL', null),
        'scopes' => false,
        'levels' => [],
    ];
}

// ....

return [
    // ...
    'Log' => $log,
    // ...
];

Any idea? Thanks!


#2

I have isolated a little the problem. This “only” happens when in AWS instances (Beanstalk, Amazon Linux AMI 2018.03) , with this simple command:

# cat src/Command/HelloCommand.php
<?php
namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use Cake\Log\Log;


class HelloCommand extends Command
{
    public function execute(Arguments $args, ConsoleIo $io)
    {
        Log::debug("Hello");
    }
}

Throwing this error:

# bin/cake hello
Exception: Could not load class debug in [/var/app/current/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php, line 57]
PHP Fatal error:  Uncaught RuntimeException: Could not load class debug in /var/app/current/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php:57
Stack trace:
#0 /var/app/current/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php(95): Cake\Log\LogEngineRegistry->_throwMissingClassError('debug', NULL)
#1 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(198): Cake\Core\ObjectRegistry->load('debug', Array)
#2 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(180): Cake\Log\Log::_loadConfig()
#3 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(351): Cake\Log\Log::_init()
#4 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(453): Cake\Log\Log::write('error', '[RuntimeExcepti...', Array)
#5 /var/app/current/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(325): Cake\Log\Log::error('[RuntimeExcepti...')
#6 /var/app/current/vendor/cakephp/cakephp/src/Console/ConsoleErrorHandler.php(69): Cake\Error\BaseErrorHandler->_logException(Object(RuntimeException))
#7 /var/app/current/vendor/cakephp/cakephp/src/E in /var/app/current/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php on line 57
PHP Fatal error:  Uncaught RuntimeException: Could not load class debug in /var/app/current/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php:57
Stack trace:
#0 /var/app/current/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php(95): Cake\Log\LogEngineRegistry->_throwMissingClassError('debug', NULL)
#1 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(198): Cake\Core\ObjectRegistry->load('debug', Array)
#2 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(180): Cake\Log\Log::_loadConfig()
#3 /var/app/current/vendor/cakephp/cakephp/src/Log/Log.php(351): Cake\Log\Log::_init()
#4 /var/app/current/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(297): Cake\Log\Log::write(3, 'Fatal Error (1)...')
#5 /var/app/current/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(229): Cake\Error\BaseErrorHandler->_logError(3, Array)
#6 /var/app/current/vendor/cakephp/cakephp/src/Error/BaseErrorHandler.php(109): Cake\Error\BaseErrorHandler->handleFatalError(1, 'Uncaught Runtim...', '/var/app/curren...', 57)
#7 [internal fu in /var/app/current/vendor/cakephp/cakephp/src/Log/LogEngineRegistry.php on line 57

Any tips, ideas? Can anyone check if this happens to you also?


#3

try to remove 'url' => env('LOG_DEBUG_URL', null),


#4

Nope, same error… :frowning:


#5

hm its not debug class per se but Cake\Log\Engine\FileLog it cant find, i havent tried new command yet but try adding

require '../../vendor/autoload.php';

on top of that HelloCommand.php


#6

Hi @Graziel, thank you very much for your help, but it doesn’t work, same error… I have modified the top to fix paths:

<?php
namespace App\Command;

require dirname(__DIR__) . '/../vendor/autoload.php';

It is very strange, because it works in my computer (Ubuntu 18.04), even in Windows 10 (Git Bash), but not in AWS (AMI Linux)… Here is some more information if it helps to someone to help me :slight_smile:

# cat /etc/os-release 
NAME="Amazon Linux AMI"
VERSION="2018.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2018.03"
PRETTY_NAME="Amazon Linux AMI 2018.03"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

# rpm -qa | grep php | sort
php72-7.2.11-1.6.amzn1.x86_64
php72-bcmath-7.2.11-1.6.amzn1.x86_64
php72-cli-7.2.11-1.6.amzn1.x86_64
php72-common-7.2.11-1.6.amzn1.x86_64
php72-devel-7.2.11-1.6.amzn1.x86_64
php72-gd-7.2.11-1.6.amzn1.x86_64
php72-intl-7.2.11-1.6.amzn1.x86_64
php72-json-7.2.11-1.6.amzn1.x86_64
php72-mbstring-7.2.11-1.6.amzn1.x86_64
php72-mysqlnd-7.2.11-1.6.amzn1.x86_64
php72-odbc-7.2.11-1.6.amzn1.x86_64
php72-opcache-7.2.11-1.6.amzn1.x86_64
php72-pdo-7.2.11-1.6.amzn1.x86_64
php72-pecl-apcu-5.1.8-2.7.amzn1.x86_64
php72-pecl-igbinary-1.2.2-0.1.20151217git2b7c703.8.amzn1.x86_64
php72-pecl-imagick-3.4.3-1.7.amzn1.x86_64
php72-pecl-mcrypt-1.0.1-3.5.amzn1.x86_64
php72-pecl-memcache-3.0.9-0.4.20160311git4991c2f.11.amzn1.x86_64
php72-pecl-memcached-3.0.0-0.1.20160217git6ace07d.5.amzn1.x86_64
php72-pecl-oauth-2.0.2-1.5.amzn1.x86_64
php72-pecl-ssh2-1.0-5.19.amzn1.x86_64
php72-pecl-uuid-1.0.4-7.3.amzn1.x86_64
php72-pgsql-7.2.11-1.6.amzn1.x86_64
php72-process-7.2.11-1.6.amzn1.x86_64
php72-soap-7.2.11-1.6.amzn1.x86_64
php72-xml-7.2.11-1.6.amzn1.x86_64
php72-xmlrpc-7.2.11-1.6.amzn1.x86_64
php7-pear-1.10.1-1.24.amzn1.noarch