PSR-3 Log decorator for Campaign Monitor.
$ composer require amesplash/campaignmonitor-log
If not already available the above command will also install campaignmonitor/createsend-php
.
Construct a new LogDecorator instance with any PSR-3 compatible logger. You can pass through your default context as the second argument.
Construct your Campaign Monitor instances passing your desired log level and the LogDecorator instance.
<?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
);
}
}
This library maps the Camapign Monitor log levels defined in vendor/campaignmonitor/class/log.php
as follows:
Campaign Monitor Log Level | PSR Log Level |
---|---|
CS_REST_LOG_VERBOSE (1000) | LogLevel::DEBUG |
CS_REST_LOG_WARNING (500) | LogLevel::WARNING |
CS_REST_LOG_ERROR (250) | LogLevel::ERROR |
If your log level is CS_REST_LOG_NONE
it will be pointless to instantiate the LogDecorator.