Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| UserIdProcessor | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getUserId | |
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) 2017 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\oatbox\log\logger\processor; |
| 23 | |
| 24 | use Monolog\Logger; |
| 25 | |
| 26 | /** |
| 27 | * Class UserIdProcessor |
| 28 | * |
| 29 | * @package oat\oatbox\log\logger\processor |
| 30 | */ |
| 31 | class UserIdProcessor |
| 32 | { |
| 33 | /** |
| 34 | * @var string |
| 35 | */ |
| 36 | protected $level; |
| 37 | |
| 38 | /** |
| 39 | * UserIdProcessor constructor. |
| 40 | * @param int $level |
| 41 | */ |
| 42 | public function __construct($level = Logger::DEBUG) |
| 43 | { |
| 44 | $this->level = $level; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param array $record |
| 49 | * @return array |
| 50 | * @throws \common_exception_Error |
| 51 | */ |
| 52 | public function __invoke(array $record) |
| 53 | { |
| 54 | // No action required when the log level is too low. |
| 55 | if ($record['level'] < $this->level) { |
| 56 | return $record; |
| 57 | } |
| 58 | |
| 59 | $record['user_id'] = $this->getUserId(); |
| 60 | |
| 61 | return $record; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @return string |
| 66 | * @throws \common_exception_Error |
| 67 | */ |
| 68 | private function getUserId() |
| 69 | { |
| 70 | return \common_session_SessionManager::getSession()->getUser()->getIdentifier(); |
| 71 | } |
| 72 | } |