Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Created November 17, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molotovbliss/fe388afd98ecb733fd07988dc60f1047 to your computer and use it in GitHub Desktop.
Save molotovbliss/fe388afd98ecb733fd07988dc60f1047 to your computer and use it in GitHub Desktop.
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