Magento 2日志打印
protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
You use debug, exception, system for PSR Logger for example:
$this->logger->info($message);
$this->logger->debug($message);
HINT:
Don't forget to run
php bin/magento setup:di:compile
Refer: magento-2-replacement-for-magelog-method
<?php
# Logging mechanisms in Magento 2 as Mage::Log is not globally
# inherited anymore like in M1, and new vendor options exist.
# Original sauce: https://magento.stackexchange.com/a/92442/69
# Mage::Log in M2
# You can also write to the logs using the Zend library:
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');
Edited
# You can also print PHP objects and arrays:
$logger->info(print_r($yourArray, true));
# OR Mono/PSR Logger which is new in M2
protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
# You use debug, exception, system for psr logger for example
$this->logger->info($message);
$this->logger->debug($message);
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/25/magento-2-logging/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Magento 2日志打印
protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)
{
$this->logger = $logger;
}
You use debug, exception, syst……
文章目录
关闭
共有 0 条评论