amesplash / campaignmonitor-log
Campaign Monitor PSR-3 日志装饰器
1.0.0
2019-04-06 12:18 UTC
Requires
- php: ^7.2,<7.4
- campaignmonitor/createsend-php: ^6.0
- psr/log: ^1.1
Requires (Dev)
- eloquent/phony-phpunit: ^5.0
- phpstan/phpstan: ^0.11.5
- squizlabs/php_codesniffer: ^3.4
Provides
This package is auto-updated.
Last update: 2024-09-21 20:39:02 UTC
README
用于 Campaign Monitor 的PSR-3 日志装饰器。
安装
$ composer require amesplash/campaignmonitor-log
如果上述命令尚未安装,它也将安装 campaignmonitor/createsend-php
。
用法
使用任何 PSR-3 兼容的日志记录器构建一个新的 LogDecorator 实例。您可以将默认上下文作为第二个参数传递。
构建 Campaign Monitor 实例时,传递所需的日志级别和 LogDecorator 实例。
<?php declare(strict_types=1); namespace App; use CS_REST_Campaigns; use Psr\Log\LoggerInterface; use Psr\Container\ContainerInterface; use Amesplash\CampaignMonitorLog\LogDecorator; final class MyCampaignMonitorCampaignFactory { public function __invoke(ContainerInterface $container) : CS_REST_Campaigns { $params = $container->get('params'); $psr3Logger = $container->get('monolog or any other PSR 3 Logger'); $defaultContext = [ 'Campaign' => 'Functional Dev', ]; $logDecorator = new LogDecorator($psr3Logger, $defaultContext); return new CS_REST_Campaigns( $params->get('campaignmonitor.campaign_id'), ['api_key' => $params->get('campaignmonitor.api_key')], 'https', CS_REST_LOG_VERBOSE, 'api.createsend.com', $logDecorator ); } }
日志级别
此库将 Camapign Monitor 在 vendor/campaignmonitor/class/log.php
中定义的日志级别映射如下
如果您的日志级别是 CS_REST_LOG_NONE
,则实例化 LogDecorator 将毫无意义。