I'm trying to log some info in the existing Magento 2 module just to check if the code is running or not.
Following files have been modified to log info.
Magento\Checkout\Block\Cart\Item\Renderer.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Checkout\Block\Cart\Item;
.
.
.
.
use Psr\Log\LoggerInterface;
.
.
.
protected $_logger;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
.
.
LoggerInterface $logger,
array $data = []
) {
.
.
.
$this->logger = $logger;
parent::__construct($context, $data);
.
.
.
}
.
.
.
public function getProductOptions()
{
/* @var $helper \Magento\Catalog\Helper\Product\Configuration */
$helper = $this->_productConfig;
$this->_logger->debug('Product Options');
return $helper->getCustomOptions($this->getItem());
}
I'm getting following error.
Exception #0 (Exception): Recoverable Error: Argument 10 passed to
Magento\Checkout\Block\Cart\Item\Renderer::__construct() must
implement interface Psr\Log\LoggerInterface, array given, called in
/Applications/MAMP/htdocs/magentoce21/vendor/magento/module-bundle/Block/Checkout/Cart/Item/Renderer.php
on line 65 and defined in
/Applications/MAMP/htdocs/magentoce21/vendor/magento/module-checkout/Block/Cart/Item/Renderer.php
on line 120
Best Answer
You should refresh generation files. Try to remove the
var/generation
directory content, like:from the magento root directory.
Additional info: you can use logger from the parent class, without declaring new logger, becouse it already exists in the
_logger
parameter.Update: It is possible that error is coming from the some other block which extends your block, but still uses a standard set of arguments in the
__construct
method when it try to call the parent__construct
method.I think this block located here: