Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A replacement for M1's mage::log() for M2
<?php
// ------------------------------------------------------------------
// Psr Logging Interface *the right way*
protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
$this->logger->debug(\Zend_Debug::dump($message));
// ------------------------------------------------------------------
// direct call to Zend\Log\Writer *the dirty but quick way*
$logfile = BP. '/var/log/my-debug.log';
$writer = new \Zend\Log\Writer\Stream($logfile);
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info(print_r($array, true));
// original code from: https://magento.stackexchange.com/questions/92434/magento-2-replacement-for-magelog-method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment