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);
上一篇 使用Composer安装Magento 2.4
下一篇 Magento使用Redis
目录
文章列表
1 Magento解决https反向代理后admin路径跳转到http问题
Magento解决https反向代理后admin路径跳转到http问题
2
Vue 3.0 初体验(项目搭建)
Vue 3.0 初体验(项目搭建)
3
Linux配置公钥授权方式ssh连接
Linux配置公钥授权方式ssh连接
4
CentOS下安装配置PHP 7
CentOS下安装配置PHP 7
5
Spring Boot集成RabbitMQ详解
Spring Boot集成RabbitMQ详解
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。