2017 © Pedro Peláez
 

library swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

image

gcrico/swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

  • Monday, January 15, 2018
  • by gcrico
  • Repository
  • 1 Watchers
  • 6 Stars
  • 6,826 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 25 % Grown

The README.md

swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger., (*1)

There are several psr/log implementations out there., (*2)

Warning! The logger must NOT send emails with a mailer that it is logging, or you will run in a dead loop!, (*3)

Installation

php composer.phar require gcrico/swift-mailer-psr-logger-plugin @stable

Example Usage

This will log all the mailer activity:, (*4)

use gcrico\SwiftMailerPsrLoggerPlugin\SwiftMailerPsrLoggerPlugin;

$transport = /*...*/;
$mailer = Swift_Mailer::newInstance($transport);

$logger = new YourFavoritePsr3Logger();
$mailer_logger = new SwiftMailerPsrLoggerPlugin($logger);
$mailer->registerPlugin($mailer_logger);

The default log levels are:, (*5)

    'sendPerformed.SUCCESS'     => LogLevel::INFO,
    'sendPerformed.TENTATIVE'   => LogLevel::WARNING,
    'sendPerformed.NOT_SUCCESS' => LogLevel::ERROR,
    'sendPerformed.PENDING'     => LogLevel::DEBUG,
    'sendPerformed.SPOOLED'     => LogLevel::DEBUG,
    'exceptionThrown'           => LogLevel::ERROR,
    'beforeSendPerformed'       => LogLevel::DEBUG,
    'commandSent'               => LogLevel::DEBUG,
    'responseReceived'          => LogLevel::DEBUG,
    'beforeTransportStarted'    => LogLevel::DEBUG,
    'transportStarted'          => LogLevel::DEBUG,
    'beforeTransportStopped'    => LogLevel::DEBUG,
    'transportStopped'          => LogLevel::DEBUG,

You can change the default log levels:, (*6)

$mailer_log_levels =  array(
    'sendPerformed.SUCCESS'     => LogLevel::DEBUG,
    'sendPerformed.NOT_SUCCESS' => LogLevel::WARNING,
    'exceptionThrown'           => LogLevel::WARNING,
);
$mailer_logger = new SwiftMailerPsrLoggerPlugin($logger, $mailer_log_levels);

You can disable logging of some events, using a falsy value for the level., (*7)

$mailer_log_levels =  array(
    'commandSent'               => 0,
    'sendPerformed.NOT_SUCCESS' => false,
    'exceptionThrown'           => null,
    'beforeTransportStopped'    => '',
);
$mailer_logger = new SwiftMailerPsrLoggerPlugin($logger, $mailer_log_levels);

Example Usage with Silex

This workaround is needed for Silex <= 1.2.0 (see https://github.com/silexphp/Silex/issues/959):, (*8)

$app['swiftmailer.spooltransport'] = $app->share(function ($app) {
    return new \Swift_Transport_SpoolTransport($app['swiftmailer.transport.eventdispatcher'], $app['swiftmailer.spool']);
});

Let's extends the mailer service:, (*9)

use gcrico\SwiftMailerPsrLoggerPlugin\SwiftMailerPsrLoggerPlugin;

$app->extend('mailer', function ($mailer) use ($app) {
    $app_logger = $app['logger'];
    $mailer_logger = new SwiftMailerPsrLoggerPlugin($app_logger);
    $mailer->registerPlugin($mailer_logger);
    return $mailer;
});

The Versions

15/01 2018

dev-master

9999999-dev https://github.com/gcrico/swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

  Sources   Download

MIT

The Requires

 

by Guillaume Crico

psr log logging swiftmailer mailer swift

15/01 2018

v1.1.1

1.1.1.0 https://github.com/gcrico/swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

  Sources   Download

MIT

The Requires

 

by Guillaume Crico

psr log logging swiftmailer mailer swift

05/09 2017

v1.1.0

1.1.0.0 https://github.com/gcrico/swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

  Sources   Download

MIT

The Requires

 

by Guillaume Crico

psr log logging swiftmailer mailer swift

13/06 2014

v1.0.0

1.0.0.0 https://github.com/gcrico/swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

  Sources   Download

MIT

The Requires

 

by Guillaume Crico

psr log logging swiftmailer mailer swift

13/06 2014

dev-devel-sala

dev-devel-sala https://github.com/gcrico/swift-mailer-psr-logger-plugin

Logs swift mailer activity with a (PSR-3) logger.

  Sources   Download

MIT

The Requires

 

by Guillaume Crico

psr log logging swiftmailer mailer swift