TYPO3  7.6
LoggerPlugin.php
Go to the documentation of this file.
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 
17 {
19  private $_logger;
20 
26  public function __construct(Swift_Plugins_Logger $logger)
27  {
28  $this->_logger = $logger;
29  }
30 
36  public function add($entry)
37  {
38  $this->_logger->add($entry);
39  }
40 
44  public function clear()
45  {
46  $this->_logger->clear();
47  }
48 
54  public function dump()
55  {
56  return $this->_logger->dump();
57  }
58 
64  public function commandSent(Swift_Events_CommandEvent $evt)
65  {
66  $command = $evt->getCommand();
67  $this->_logger->add(sprintf('>> %s', $command));
68  }
69 
76  {
77  $response = $evt->getResponse();
78  $this->_logger->add(sprintf('<< %s', $response));
79  }
80 
87  {
88  $transportName = get_class($evt->getSource());
89  $this->_logger->add(sprintf('++ Starting %s', $transportName));
90  }
91 
98  {
99  $transportName = get_class($evt->getSource());
100  $this->_logger->add(sprintf('++ %s started', $transportName));
101  }
102 
109  {
110  $transportName = get_class($evt->getSource());
111  $this->_logger->add(sprintf('++ Stopping %s', $transportName));
112  }
113 
120  {
121  $transportName = get_class($evt->getSource());
122  $this->_logger->add(sprintf('++ %s stopped', $transportName));
123  }
124 
131  {
132  $e = $evt->getException();
133  $message = $e->getMessage();
134  $code = $e->getCode();
135  $this->_logger->add(sprintf('!! %s (code: %s)', $message, $code));
136  $message .= PHP_EOL;
137  $message .= 'Log data:'.PHP_EOL;
138  $message .= $this->_logger->dump();
139  $evt->cancelBubble();
140  throw new Swift_TransportException($message, $code, $e->getPrevious());
141  }
142 }