Jump to content

LoggerInterface, console, and PrestaShopLogger


Recommended Posts

Hi all,

 

Before using Prestashop 1.7, for my Prestashop commands, I used $logger = new ConsoleLogger($output); before call $logger->warn(...);.

With Prestahsop 1.7, I use the dependency injection, and in the constructor of the class, I call LoggerInterface :

use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;

class NextpharmStockUpdateCommand extends Command
{
    private LoggerInterface $logger;

    public function __construct(LoggerInterface $logger)
    {
        parent::__construct('my:module:command');

        $this->logger = $logger;
    }
}

Basically, that seems work, but the logger used is PrestaShopLogger, which write in database (ps_log) and by default checks if there is already the message in ps_log (SELECT COUNT(*) FROM ps_log WHERE message='...'). In my case (update stock of all [~15000] products), the execution was ~5 minutes and is now >4h.

Is someone know, for commands, use ConsoleLogger for LoggerInterface instead of PrestaShopLogger?

Thanks!

Edited by rpommier (see edit history)
Link to comment
Share on other sites

My modules/mymodule/config/services.yaml began with:

services:
    _defaults:
        autowire: true

    MyModule\Command\MyCommand:
        class: MyModule\Command\MyCommand
        tags: [ 'console.command' ]

Now, by adding the bind element, that seems work as I want:

services:
    _defaults:
        autowire: true
        bind:
            Psr\Log\LoggerInterface: '@monolog.logger.console'

    MyModule\Command\MyCommand:
        class: MyModule\Command\MyCommand
        tags: [ 'console.command' ]

Source: https://symfony.com/doc/3.4/service_container.html#binding-arguments-by-name-or-type

Edited by rpommier
Add symfony doc source (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...