magento2 debug排查方式汇总 :增加 Log 记录
	
		 
        
        
        上一篇:2018年magento自建站10大潮流趋势,你的页面更新了吗? 
        下一篇:magento2的checkout totals添加产品属性 
        
        
      使用该方法将在 [root]/var/log/support_report.log 文件中添加记录。
\Magento\Framework\App\ObjectManager::getInstance()
    ->get( '\Psr\Log\LoggerInterface' )->addCritical( print_r( 'xxx', true ) );
数据对象的数据输出
所有继承 DataObject 的类都可使用其 debug 方法将所有属性(属性若为 DataObject 对象则递归处理)转换成字符数组输出。比如 block、model、resource model 等。
print_r( $obj->debug() );
控制器路由查错
可到以下方法中加入代码片段进行 debug:
- 
		MagentoFrameworkAppRouterBase::matchAction 
- 
		MagentoFrameworkConfigReaderFilesystem::_readFiles 
查询所有加载了的 layout
在 MagentoFrameworkViewModelLayoutMerge::_loadFileLayoutUpdatesXml 中找到:
foreach ($updateFiles as $file) {
在其后添加如下代码:
echo $file->getFileIdentifier()."\n";
清空缓存后刷新页面。
获取所有打开的模块名
把 MagentoFrameworkModuleModuleList 的 getNames 方法改成
public function getNames()
{
    $this->loadConfigData();
    if (!$this->configData) {
        return [];
    }
    $result = array_keys(array_filter($this->configData));
    print_r( $result ); exit; // 添加这行
    return $result;
}
          