gcrico/swift-mailer-psr-logger-plugin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gcrico/swift-mailer-psr-logger-plugin

最新稳定版本:v1.2.0

Composer 安装命令:

composer require gcrico/swift-mailer-psr-logger-plugin

包简介

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

README 文档

README

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

There are several psr/log implementations out there.

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

Installation

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

Example Usage

This will log all the mailer activity:

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:

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

$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.

$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 silexphp/Silex#959):

$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:

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

统计信息

  • 总下载量: 46.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-13