Answers for "magento 2 log files"

PHP
6

mage log magento 2

<?php
  $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logfile.log');
  $logger = new \Zend\Log\Logger();
  $logger->addWriter($writer);
  $logger->info('Simple Text Log'); // Simple Text Log
  $logger->info('Array Log'.print_r($myArrayVar, true)); // Array Log
?>
Posted by: Guest on December-22-2020
-1

magento 2 custom logging

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
Posted by: Guest on July-01-2020
1

logger magento2

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
Posted by: Guest on June-08-2021
3

log magento 1

Mage::log('message',null,'logfile.log',true);
Mage::log(print_r($arr, 1), null, 'logfile.log',true);
Posted by: Guest on January-25-2021
0

mage log equivalent magento 2

\Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->debug('Your message here');
Posted by: Guest on August-19-2020
0

Magento 2 writing messages to a log file

<preference for=”Psr\Log\LoggerInterface” type=”Magento\Framework\Logger\Monolog” />
<type name=”Magento\Framework\Logger\Monolog”>
<arguments>
<argument name=”name” xsi:type=”string”>main</argument>
<argument name=”handlers” xsi:type=”array”>
<item name=”system” xsi:type=”object”>Magento\Framework\Logger\Handler\System</item>
<item name=”debug” xsi:type=”object”>Magento\Framework\Logger\Handler\Debug</item>
</argument>
</arguments>
</type>



<?php
	namespace Inchoo\Test\Model;

	class Example{
	protected $_logger;

	public function __construct(
		\Psr\Log\LoggerInterface $logger, //log injection
		array $data = []
	) {
		$this->_logger = $logger;
		parent::__construct($data);
	}

	public function someExampleMethod() {
	/*
	some logic of method
	*/
	//accessing to logger instance and calling log method
	$this->_logger->addDebug('some text or variable');
	}

}
Posted by: Guest on July-08-2021

Browse Popular Code Answers by Language