magezone/magento2-logviewer

一个具有Tracy调试、自定义日志记录器和日志查看UI的Magento 2模块

安装: 6

依赖项: 0

建议者: 0

安全: 0

类型:magento2-module

0.1.0 2018-05-29 11:36 UTC

This package is not auto-updated.

Last update: 2024-09-20 03:30:38 UTC


README

日志文件中的数据可以保存为表格格式。在Magento管理界面中,您可以分配格式化程序到表格列

  1. 转到 系统 > 工具 > 日志查看器
  2. 在页面顶部点击 管理列格式化程序
  3. 点击 添加新的列格式化程序

格式化描述

  • 索引:创建新的日志条目时,数据对应的数组索引。
  • 名称:此索引上的日志列的标题。
  • 日志文件:应用于此列格式化程序的日志文件路径,相对于var/log。
  • 格式化类:用于格式化此列的类。

格式化类

  • StringData:数据被转换为字符串。
  • ExceptionData:数据必须实现\Throwable接口。保存Tracy的异常蓝屏。
  • StructuredData:对象或数组。它以可浏览的格式保存。

使用自定义日志记录器

您需要将LogViewer Logger添加到依赖注入中,例如

public function __construct(
	...
	\Magezone\LogViewer\Logger\Logger $logger
	...
)
...

记录的数据必须是一个数组。每个数组值对应于日志查看中的一个列。如果未指定所选日志文件和列索引的列格式化程序,则使用StringData格式化程序。日志文件的数组值数量必须保持不变。日志级别与默认的Monolog日志记录器相同。

异常记录示例

...
catch (\Throwable $e) {
	// in Magento admin, there is ExceptionData column formatter for file test.log and index 2
	$this->logger->warning('test.log', ['test log data', 'second column', $e]); 
}
...

结构化数据示例

...
// in Magento admin, there is StructuredData column formatter for file test2.log and index 1
$data = ['person' => ['name' => 'Mikhael', 'age' => 24]];
$this->logger->debug('test2.log', ['some column', $data, 'other column']);
...