1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17: 18:
19: class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_Events_ResponseListener, Swift_Events_TransportChangeListener, Swift_Events_TransportExceptionListener, Swift_Plugins_Logger
20: {
21:
22: private $_logger;
23:
24: 25: 26: 27: 28:
29: public function __construct(Swift_Plugins_Logger $logger)
30: {
31: $this->_logger = $logger;
32: }
33:
34: 35: 36: 37: 38:
39: public function add($entry)
40: {
41: $this->_logger->add($entry);
42: }
43:
44: 45: 46:
47: public function clear()
48: {
49: $this->_logger->clear();
50: }
51:
52: 53: 54: 55: 56:
57: public function dump()
58: {
59: return $this->_logger->dump();
60: }
61:
62: 63: 64: 65: 66:
67: public function commandSent(Swift_Events_CommandEvent $evt)
68: {
69: $command = $evt->getCommand();
70: $this->_logger->add(sprintf(">> %s", $command));
71: }
72:
73: 74: 75: 76: 77:
78: public function responseReceived(Swift_Events_ResponseEvent $evt)
79: {
80: $response = $evt->getResponse();
81: $this->_logger->add(sprintf("<< %s", $response));
82: }
83:
84: 85: 86: 87: 88:
89: public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt)
90: {
91: $transportName = get_class($evt->getSource());
92: $this->_logger->add(sprintf("++ Starting %s", $transportName));
93: }
94:
95: 96: 97: 98: 99:
100: public function transportStarted(Swift_Events_TransportChangeEvent $evt)
101: {
102: $transportName = get_class($evt->getSource());
103: $this->_logger->add(sprintf("++ %s started", $transportName));
104: }
105:
106: 107: 108: 109: 110:
111: public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt)
112: {
113: $transportName = get_class($evt->getSource());
114: $this->_logger->add(sprintf("++ Stopping %s", $transportName));
115: }
116:
117: 118: 119: 120: 121:
122: public function transportStopped(Swift_Events_TransportChangeEvent $evt)
123: {
124: $transportName = get_class($evt->getSource());
125: $this->_logger->add(sprintf("++ %s stopped", $transportName));
126: }
127:
128: 129: 130: 131: 132:
133: public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt)
134: {
135: $e = $evt->getException();
136: $message = $e->getMessage();
137: $this->_logger->add(sprintf("!! %s", $message));
138: $message .= PHP_EOL;
139: $message .= 'Log data:' . PHP_EOL;
140: $message .= $this->_logger->dump();
141: $evt->cancelBubble();
142: throw new Swift_TransportException($message);
143: }
144: }
145: