0

I want to show login Magento 2 of my custom module.

I have created an index controller but it's not working for me

class Index extends \Magento\Framework\App\Action\Action 
{
protected $resultJsonFactory;
protected $_helper;
protected $logger;

public function __construct(Context $context, 
\Softprodigy\Opc\Helper\Data $helper,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,\Psr\Log\LoggerInterface $logger)
{
    $this->resultJsonFactory  = $resultJsonFactory;
    $this->_helper = $helper;
    $this->_logger = $logger;
    parent::__construct($context);
}

  public function execute()
  {
    //die('dfsd');
    //$topTel = $this->_helper->getConfig('dynamicpdf/general/topTel');
    //$_thishepler = $this->_helper('namespace\moduename\Helper\Data'); 
    $isEnabled = $helper->getStoreConfig('namespace_module/general/enabled');

   $this->_logger->addDebug("test".$isEnabled); // log location: var/log/system.log
    $this->_logger->addInfo("test2".$isEnabled); // log location: var/log/exception.log
    $this->_logger->addNotice("test3".$isEnabled); // log location: var/log/exception.log
    $this->_logger->addError("test4".$isEnabled); // log location: var/log/exception.log
    $this->_logger->critical("test5".$isEnabled);
    print_r($isEnabled); die;
0

You can use below code to log

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
0

Try this

class Index extends \Magento\Framework\App\Action\Action 
{
    protected $resultJsonFactory;
    protected $_helper;
    protected $logger;

    public function __construct(Context $context, \Softprodigy\Opc\Helper\Data $helper,\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,\Psr\Log\LoggerInterface $logger)
    {
        $this->resultJsonFactory  = $resultJsonFactory;
        $this->_helper = $helper;
        $this->_logger = $logger;
        parent::__construct($context);
    }

    public function execute()
    {

        $isEnabled = $helper->getStoreConfig('namespace_module/general/enabled');

        $this->_logger->debug("test".$isEnabled); // log location: var/log/system.log
        $this->_logger->info("test2".$isEnabled); // log location: var/log/exception.log
        $this->_logger->notice("test3".$isEnabled); // log location: var/log/exception.log
        $this->_logger->error("test4".$isEnabled); // log location: var/log/exception.log
        $this->_logger->critical("test5".$isEnabled);
        print_r($isEnabled); die;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.