XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Events/CommandListener.php';
12 //@require 'Swift/Events/CommandEvent.php';
13 //@require 'Swift/Events/ResponseListener.php';
14 //@require 'Swift/Events/ResponseEvent.php';
15 //@require 'Swift/Events/TransportChangeListener.php';
16 //@require 'Swift/Events/TransportChangeEvent.php';
17 //@require 'Swift/Events/TransportExceptionEvent.php';
18 //@require 'Swift/Events/TransportExceptionListener.php';
19 //@require 'Swift/Events/TransportException.php';
20 //@require 'Swift/Plugins/Logger.php';
21 
34 {
35 
37  private $_logger;
38 
44  public function __construct(Swift_Plugins_Logger $logger)
45  {
46  $this->_logger = $logger;
47  }
48 
54  public function add($entry)
55  {
56  $this->_logger->add($entry);
57  }
58 
62  public function clear()
63  {
64  $this->_logger->clear();
65  }
66 
72  public function dump()
73  {
74  return $this->_logger->dump();
75  }
76 
82  public function commandSent(Swift_Events_CommandEvent $evt)
83  {
84  $command = $evt->getCommand();
85  $this->_logger->add(sprintf(">> %s", $command));
86  }
87 
94  {
95  $response = $evt->getResponse();
96  $this->_logger->add(sprintf("<< %s", $response));
97  }
98 
105  {
106  $transportName = get_class($evt->getSource());
107  $this->_logger->add(sprintf("++ Starting %s", $transportName));
108  }
109 
116  {
117  $transportName = get_class($evt->getSource());
118  $this->_logger->add(sprintf("++ %s started", $transportName));
119  }
120 
127  {
128  $transportName = get_class($evt->getSource());
129  $this->_logger->add(sprintf("++ Stopping %s", $transportName));
130  }
131 
138  {
139  $transportName = get_class($evt->getSource());
140  $this->_logger->add(sprintf("++ %s stopped", $transportName));
141  }
142 
149  {
150  $e = $evt->getException();
151  $message = $e->getMessage();
152  $this->_logger->add(sprintf("!! %s", $message));
153  $message .= PHP_EOL;
154  $message .= 'Log data:' . PHP_EOL;
155  $message .= $this->_logger->dump();
156  $evt->cancelBubble();
157  throw new Swift_TransportException($message);
158  }
159 
160 }