Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| common_log_UDPAppender | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| doLog | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| __destruct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * Short description of class common_log_UDPAppender |
| 29 | * |
| 30 | * @access public |
| 31 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 32 | * @package generis |
| 33 | |
| 34 | */ |
| 35 | class common_log_UDPAppender extends common_log_BaseAppender |
| 36 | { |
| 37 | // --- ASSOCIATIONS --- |
| 38 | |
| 39 | |
| 40 | // --- ATTRIBUTES --- |
| 41 | |
| 42 | /** |
| 43 | * Short description of attribute host |
| 44 | * |
| 45 | * @access public |
| 46 | * @var string |
| 47 | */ |
| 48 | public $host = '127.0.0.1'; |
| 49 | |
| 50 | /** |
| 51 | * Short description of attribute port |
| 52 | * |
| 53 | * @access public |
| 54 | * @var int |
| 55 | */ |
| 56 | public $port = 5775; |
| 57 | |
| 58 | /** |
| 59 | * Short description of attribute resource |
| 60 | * |
| 61 | * @access public |
| 62 | * @var resource |
| 63 | */ |
| 64 | public $resource = null; |
| 65 | |
| 66 | // --- OPERATIONS --- |
| 67 | |
| 68 | /** |
| 69 | * Short description of method init |
| 70 | * |
| 71 | * @access public |
| 72 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 73 | * @param array configuration |
| 74 | * @return boolean |
| 75 | */ |
| 76 | public function init($configuration) |
| 77 | { |
| 78 | $returnValue = (bool) false; |
| 79 | |
| 80 | |
| 81 | if (isset($configuration['host'])) { |
| 82 | $this->host = $configuration['host']; |
| 83 | } |
| 84 | |
| 85 | if (isset($configuration['port'])) { |
| 86 | $this->port = $configuration['port']; |
| 87 | } |
| 88 | |
| 89 | $returnValue = parent::init($configuration); |
| 90 | |
| 91 | |
| 92 | return (bool) $returnValue; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Short description of method doLog |
| 97 | * |
| 98 | * @access public |
| 99 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 100 | * @param Item item |
| 101 | * @return mixed |
| 102 | */ |
| 103 | public function doLog(common_log_Item $item) |
| 104 | { |
| 105 | |
| 106 | if (is_null($this->resource)) { |
| 107 | $this->resource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); |
| 108 | socket_set_nonblock($this->resource); |
| 109 | } |
| 110 | if ($this->resource !== false) { |
| 111 | $message = json_encode([ |
| 112 | 's' => $item->getSeverity(), |
| 113 | 'd' => $item->getDescription(), |
| 114 | 'p' => $this->prefix, |
| 115 | 't' => $item->getTags(), |
| 116 | 'f' => $item->getCallerFile(), |
| 117 | 'l' => $item->getCallerLine(), |
| 118 | 'b' => $item->getBacktrace() |
| 119 | ]); |
| 120 | @socket_sendto($this->resource, $message, strlen($message), 0, $this->host, $this->port); |
| 121 | //ignore errors, socket might already be closed because php is shutting down |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Short description of method __destruct |
| 127 | * |
| 128 | * @access public |
| 129 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 130 | * @return mixed |
| 131 | */ |
| 132 | public function __destruct() |
| 133 | { |
| 134 | |
| 135 | // don't close since we might still need it |
| 136 | /* |
| 137 | if (!is_null($this->resource) && $this->resource !== false) { |
| 138 | socket_close($this->resource); |
| 139 | } |
| 140 | parent::__destruct(); |
| 141 | */ |
| 142 | } |
| 143 | } |