PHP code example of gcrico / swift-mailer-psr-logger-plugin

1. Go to this page and download the library: Download gcrico/swift-mailer-psr-logger-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gcrico / swift-mailer-psr-logger-plugin example snippets


use gcrico\SwiftMailerPsrLoggerPlugin\SwiftMailerPsrLoggerPlugin;

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

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

    '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,

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

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

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

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;
});
bash
php composer.phar