amesplash/campaignmonitor-log

Campaign Monitor PSR-3 Log Decorator

1.0.0 2019-04-06 12:18 UTC

This package is auto-updated.

Last update: 2024-10-21 20:55:01 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License

PSR-3 Log decorator for Campaign Monitor.

Installation

$ composer require amesplash/campaignmonitor-log

If not already available the above command will also install campaignmonitor/createsend-php.

Usage

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
        );
    }
}

Log Levels

This library maps the Camapign Monitor log levels defined in vendor/campaignmonitor/class/log.php as follows:

If your log level is CS_REST_LOG_NONE it will be pointless to instantiate the LogDecorator.