khuetd / m2-custom-log
改进magento 2日志的定制格式
0.0.6
2020-04-05 07:47 UTC
Requires
- php: >=7.0
- magento/framework: 100.*|101.*|102.*
- monolog/monolog: ^1.0
README
``ktd/custom-log``
主要功能
改进magento 2日志的定制格式
安装
* = 在生产环境中请使用 --keep-generated
选项
类型 1: 压缩文件
- 将压缩文件解压到
app/code/Ktd
- 通过运行
php bin/magento module:enable Ktd_LogHandler
启用模块 - 通过运行
php bin/magento setup:upgrade
应用数据库更新* - 通过运行
php bin/magento cache:flush
清除缓存
类型 2: Composer
- 将模块添加到composer仓库中,例如
- 私有仓库
repo.magento.com
- 公共仓库
packagist.org
- 公共github仓库作为vcs
- 私有仓库
- 通过运行
composer config repositories.repo.magento.com composer https://repo.magento.com/
将composer仓库添加到配置中 - 通过运行
composer require ktd/custom-log
安装模块 - 通过运行
php bin/magento module:enable Ktd_LogHandler
启用模块 - 通过运行
php bin/magento setup:upgrade
应用数据库更新* - 通过运行
php bin/magento cache:flush
清除缓存
配置
使用
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Ktd\LogHandler\Helper\Data $log */
$log = $objectManager->get('\Ktd\LogHandler\Helper\Data');
$log->setFuncDebug('saleorder'); //set filename
$logType = 'ORDER';
$logApiType = 'SO-ORDER';
$req = ['sample' => 1];
$res = ['success' => 1];
$apiname = 'http://URL_API';
$req = json_encode($req);
$res = json_encode($res);
$log->debuglog($logType, array(
$logApiType,
"API : $apiname",
"REQ : $req",
"RES : $res"
));
日志结果
Log path: MAGENTO_ROOT_FOLDER/var/log/api/saleorder_debug_2020-04-05.log
2020-04-05 13:08:25|DEBUG|8aprmocv1b38g4n3d809m8pr79|ORDER|SO-ORDER|API : http://URL_API|REQ : {"sample":1}|RES : {"success":1}