Skip to main content

youYou can do the same thing you did in magento oneMagento 1.x in the method \Magento\Framework\Event\Manager::dispatch().

but it's a difference. You don't have access to the logger.
You will have to inject an instance of the logger in the constructor.

$protectedprotected $logger; 

public function __construct(
    InvokerInterface $invoker, 
    ConfigInterface $eventConfig,
    \Psr\Log\LoggerInterface $logger
)
{
    $this->_invoker = $invoker;
    $this->_eventConfig = $eventConfig;
    $this->logger = $logger;
}

Then you can call in the dispatch method this:

$this->logger->info($message);

Instead of info you can use all the methods from \Psr\Log\LoggerInterface

you can do the same thing you did in magento one in the method \Magento\Framework\Event\Manager::dispatch().

but it's a difference. You don't have access to the logger.
You will have to inject an instance of the logger in the constructor.

$protected $logger;
public function __construct(
    InvokerInterface $invoker, 
    ConfigInterface $eventConfig,
    \Psr\Log\LoggerInterface $logger
)
{
    $this->_invoker = $invoker;
    $this->_eventConfig = $eventConfig;
    $this->logger = $logger;
}

Then you can call in the dispatch method this:

$this->logger->info($message);

Instead of info you can use all the methods from \Psr\Log\LoggerInterface

You can do the same thing you did in Magento 1.x in the method \Magento\Framework\Event\Manager::dispatch().

but it's a difference. You don't have access to the logger.
You will have to inject an instance of the logger in the constructor.

protected $logger; 

public function __construct(
    InvokerInterface $invoker, 
    ConfigInterface $eventConfig,
    \Psr\Log\LoggerInterface $logger
)
{
    $this->_invoker = $invoker;
    $this->_eventConfig = $eventConfig;
    $this->logger = $logger;
}

Then you can call in the dispatch method this:

$this->logger->info($message);

Instead of info you can use all the methods from \Psr\Log\LoggerInterface

Source Link
Marius
  • 198.5k
  • 55
  • 424
  • 833

you can do the same thing you did in magento one in the method \Magento\Framework\Event\Manager::dispatch().

but it's a difference. You don't have access to the logger.
You will have to inject an instance of the logger in the constructor.

$protected $logger;
public function __construct(
    InvokerInterface $invoker, 
    ConfigInterface $eventConfig,
    \Psr\Log\LoggerInterface $logger
)
{
    $this->_invoker = $invoker;
    $this->_eventConfig = $eventConfig;
    $this->logger = $logger;
}

Then you can call in the dispatch method this:

$this->logger->info($message);

Instead of info you can use all the methods from \Psr\Log\LoggerInterface