Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
18 / 21 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| common_log_BaseAppender | |
85.71% |
18 / 21 |
|
66.67% |
2 / 3 |
14.57 | |
0.00% |
0 / 1 |
| log | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
4 | |||
| getLogThreshold | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| init | |
75.00% |
9 / 12 |
|
0.00% |
0 / 1 |
9.00 | |||
| doLog | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 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_BaseAppender |
| 29 | * |
| 30 | * @abstract |
| 31 | * @access public |
| 32 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 33 | * @package generis |
| 34 | |
| 35 | */ |
| 36 | abstract class common_log_BaseAppender implements common_log_Appender |
| 37 | { |
| 38 | // --- ASSOCIATIONS --- |
| 39 | |
| 40 | |
| 41 | // --- ATTRIBUTES --- |
| 42 | |
| 43 | /** |
| 44 | * The message mask, where the least significant bit corresponds to the |
| 45 | * important severity (trace) |
| 46 | * |
| 47 | * @access private |
| 48 | * @var Integer |
| 49 | */ |
| 50 | private $mask = null; |
| 51 | |
| 52 | /** |
| 53 | * an array of tags of which one must be present |
| 54 | * for the logItem to be logged |
| 55 | * |
| 56 | * @access public |
| 57 | * @var array |
| 58 | */ |
| 59 | public $tags = []; |
| 60 | |
| 61 | /** |
| 62 | * the prefix that will be added to each log message. |
| 63 | * |
| 64 | * @access protected |
| 65 | * @var string |
| 66 | */ |
| 67 | protected $prefix = ''; |
| 68 | |
| 69 | // --- OPERATIONS --- |
| 70 | |
| 71 | /** |
| 72 | * decides whenever the Item should be logged by doLog |
| 73 | * |
| 74 | * @access public |
| 75 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 76 | * @param Item item |
| 77 | * @return mixed |
| 78 | * @see doLog |
| 79 | */ |
| 80 | public function log(common_log_Item $item) |
| 81 | { |
| 82 | if ( |
| 83 | (1 << $item->getSeverity() & $this->mask) > 0 |
| 84 | && (empty($this->tags) || count(array_intersect($item->getTags(), $this->tags))) > 0 |
| 85 | ) { |
| 86 | $this->doLog($item); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Short description of method getLogThreshold |
| 92 | * |
| 93 | * @access public |
| 94 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 95 | * @return int |
| 96 | */ |
| 97 | public function getLogThreshold() |
| 98 | { |
| 99 | $returnValue = (int) 0; |
| 100 | |
| 101 | |
| 102 | $threshold = 0; |
| 103 | while (($this->mask & 1 << $threshold) == 0) { |
| 104 | $threshold++; |
| 105 | } |
| 106 | $returnValue = $threshold; |
| 107 | |
| 108 | |
| 109 | return (int) $returnValue; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Short description of method init |
| 114 | * |
| 115 | * @access public |
| 116 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 117 | * @param array configuration |
| 118 | * @return boolean |
| 119 | */ |
| 120 | public function init($configuration) |
| 121 | { |
| 122 | $returnValue = (bool) false; |
| 123 | |
| 124 | |
| 125 | if (isset($configuration['mask']) && is_numeric($configuration['mask'])) { |
| 126 | // take over the mask |
| 127 | $this->mask = intval($configuration['mask']); |
| 128 | } elseif (isset($configuration['threshold']) && is_numeric($configuration['threshold'])) { |
| 129 | // map the threshold to a mask |
| 130 | $this->mask = max(0, (1 << common_Logger::FATAL_LEVEL + 1) - (1 << $configuration['threshold'])); |
| 131 | } else { |
| 132 | // log everything |
| 133 | $this->mask = (1 << common_Logger::FATAL_LEVEL + 1) - 1; |
| 134 | } |
| 135 | |
| 136 | if (isset($configuration['tags'])) { |
| 137 | $this->tags = is_array($configuration['tags']) ? $configuration['tags'] : [$configuration['tags']]; |
| 138 | } |
| 139 | |
| 140 | if (isset($configuration['prefix'])) { |
| 141 | $this->prefix = $configuration['prefix']; |
| 142 | } |
| 143 | $returnValue = true; |
| 144 | |
| 145 | |
| 146 | return (bool) $returnValue; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Logs the item |
| 151 | * |
| 152 | * @abstract |
| 153 | * @access public |
| 154 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 155 | * @param Item item |
| 156 | * @return mixed |
| 157 | */ |
| 158 | abstract public function doLog(common_log_Item $item); |
| 159 | } |