Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LoggerAggregator | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| log | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2016 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox\log; |
| 23 | |
| 24 | use oat\oatbox\Configurable; |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use Psr\Log\LoggerInterface; |
| 27 | use Psr\Log\AbstractLogger; |
| 28 | use Psr\Log\LoggerTrait; |
| 29 | |
| 30 | /** |
| 31 | * An aggregator that broadcast logs to multiple loggers |
| 32 | * |
| 33 | * @author Joel Bout <joel@taotesting.com> |
| 34 | */ |
| 35 | class LoggerAggregator extends ConfigurableService implements LoggerInterface |
| 36 | { |
| 37 | use LoggerTrait; |
| 38 | |
| 39 | /** |
| 40 | * @var LoggerInterface[] |
| 41 | */ |
| 42 | private $loggers; |
| 43 | |
| 44 | /** |
| 45 | * Instantiate the aggregator. |
| 46 | * |
| 47 | * @param LoggerInterface[] $options |
| 48 | * @throws \common_Exception If one of logger isnot a Psr3 logger |
| 49 | */ |
| 50 | public function __construct($options = []) |
| 51 | { |
| 52 | parent::__construct($options); |
| 53 | |
| 54 | foreach ($this->getOptions() as $logger) { |
| 55 | if (!$logger instanceof LoggerInterface) { |
| 56 | throw new \common_Exception( |
| 57 | 'Non PSR-3 compatible logger ' . get_class($logger) . ' added to ' . __CLASS__ |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | $this->loggers = $this->getOptions(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * (non-PHPdoc) |
| 67 | * @see \Psr\Log\LoggerInterface::log() |
| 68 | */ |
| 69 | public function log($level, $message, array $context = []) |
| 70 | { |
| 71 | foreach ($this->loggers as $logger) { |
| 72 | $logger->log($level, $message, $context); |
| 73 | } |
| 74 | } |
| 75 | } |