[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Plugins/ -> LoggerPlugin.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2004-2009 Chris Corbyn
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * Does real time logging of Transport level information.
  13   *
  14   * @author     Chris Corbyn
  15   */
  16  class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_Events_ResponseListener, Swift_Events_TransportChangeListener, Swift_Events_TransportExceptionListener, Swift_Plugins_Logger
  17  {
  18      /** The logger which is delegated to */
  19      private $logger;
  20  
  21      /**
  22       * Create a new LoggerPlugin using $logger.
  23       */
  24      public function __construct(Swift_Plugins_Logger $logger)
  25      {
  26          $this->logger = $logger;
  27      }
  28  
  29      /**
  30       * Add a log entry.
  31       *
  32       * @param string $entry
  33       */
  34      public function add($entry)
  35      {
  36          $this->logger->add($entry);
  37      }
  38  
  39      /**
  40       * Clear the log contents.
  41       */
  42      public function clear()
  43      {
  44          $this->logger->clear();
  45      }
  46  
  47      /**
  48       * Get this log as a string.
  49       *
  50       * @return string
  51       */
  52      public function dump()
  53      {
  54          return $this->logger->dump();
  55      }
  56  
  57      /**
  58       * Invoked immediately following a command being sent.
  59       */
  60      public function commandSent(Swift_Events_CommandEvent $evt)
  61      {
  62          $command = $evt->getCommand();
  63          $this->logger->add(sprintf('>> %s', $command));
  64      }
  65  
  66      /**
  67       * Invoked immediately following a response coming back.
  68       */
  69      public function responseReceived(Swift_Events_ResponseEvent $evt)
  70      {
  71          $response = $evt->getResponse();
  72          $this->logger->add(sprintf('<< %s', $response));
  73      }
  74  
  75      /**
  76       * Invoked just before a Transport is started.
  77       */
  78      public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt)
  79      {
  80          $transportName = get_class($evt->getSource());
  81          $this->logger->add(sprintf('++ Starting %s', $transportName));
  82      }
  83  
  84      /**
  85       * Invoked immediately after the Transport is started.
  86       */
  87      public function transportStarted(Swift_Events_TransportChangeEvent $evt)
  88      {
  89          $transportName = get_class($evt->getSource());
  90          $this->logger->add(sprintf('++ %s started', $transportName));
  91      }
  92  
  93      /**
  94       * Invoked just before a Transport is stopped.
  95       */
  96      public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt)
  97      {
  98          $transportName = get_class($evt->getSource());
  99          $this->logger->add(sprintf('++ Stopping %s', $transportName));
 100      }
 101  
 102      /**
 103       * Invoked immediately after the Transport is stopped.
 104       */
 105      public function transportStopped(Swift_Events_TransportChangeEvent $evt)
 106      {
 107          $transportName = get_class($evt->getSource());
 108          $this->logger->add(sprintf('++ %s stopped', $transportName));
 109      }
 110  
 111      /**
 112       * Invoked as a TransportException is thrown in the Transport system.
 113       */
 114      public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt)
 115      {
 116          $e = $evt->getException();
 117          $message = $e->getMessage();
 118          $code = $e->getCode();
 119          $this->logger->add(sprintf('!! %s (code: %s)', $message, $code));
 120          $message .= PHP_EOL;
 121          $message .= 'Log data:'.PHP_EOL;
 122          $message .= $this->logger->dump();
 123          $evt->cancelBubble();
 124          throw new Swift_TransportException($message, $code, $e->getPrevious());
 125      }
 126  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1