cancel
Showing results for 
Search instead for 
Did you mean: 

main.ERROR: Area code is already set on system.log

main.ERROR: Area code is already set on system.log

Hello,

 

Bellow error message is getting print on system.log about 5 times per second. How can I resolve this issue?

 

Magento version is 2.3.6-p1

 

[2022-03-29 11:26:09] main.ERROR: Area code is already set
#0 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\State->setAreaCode('global')
#1 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\State\Interceptor->___callParent('setAreaCode', Array)
#2 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\State\Interceptor->Magento\Framework\Interception\{closure}('global')
#3 /var/www/magento/generated/code/Magento/Framework/App/State/Interceptor.php(26): Magento\Framework\App\State\Interceptor->___callPlugins('setAreaCode', Array, Array)
#4 /var/www/magento/vendor/magento/module-message-queue/Console/StartConsumerCommand.php(91): Magento\Framework\App\State\Interceptor->setAreaCode('global')
#5 /var/www/magento/vendor/symfony/console/Command/Command.php(255): Magento\MessageQueue\Console\StartConsumerCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(58): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(138): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->___callParent('run', Array)
#8 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->Magento\Framework\Interception\{closure}(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/magento/generated/code/Magento/MessageQueue/Console/StartConsumerCommand/Interceptor.php(26): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->___callPlugins('run', Array, Array)
#10 /var/www/magento/generated/code/Magento/MessageQueue/Console/StartConsumerCommand/Proxy.php(143): Magento\MessageQueue\Console\StartConsumerCommand\Interceptor->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/magento/vendor/symfony/console/Application.php(1009): Magento\MessageQueue\Console\StartConsumerCommand\Proxy->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/magento/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Magento\MessageQueue\Console\StartConsumerCommand\Proxy), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/magento/vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/magento/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/magento/bin/magento(23): Symfony\Component\Console\Application->run()
#16 {main} [] []

1 REPLY 1

Re: main.ERROR: Area code is already set on system.log

Hello @marketingi  First check whether the area code is set or not then set area code so you will not get this error. 

$state = $this->_objectManager->create(\Magento\Framework\App\State::class);
try {
        $state->getAreaCode();
      } catch (\Magento\Framework\Exception\LocalizedException $e) {
            if ($e->getMessage() == 'Area code is not set') {
                $state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
            }
        }