Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_Log | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
| log | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| getLevel | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
56 | |||
| 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) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Class Log |
| 24 | * |
| 25 | * Controller is used to aggregate log given from tao client side (or other client services). |
| 26 | * |
| 27 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 28 | */ |
| 29 | class tao_actions_Log extends \tao_actions_CommonModule |
| 30 | { |
| 31 | /** |
| 32 | * Log the message sent from client side |
| 33 | */ |
| 34 | public function log() |
| 35 | { |
| 36 | $result = []; |
| 37 | if ($this->hasRequestParameter('messages')) { |
| 38 | $messages = json_decode($this->getRawParameter('messages'), true); |
| 39 | foreach ($messages as $message) { |
| 40 | \common_Logger::singleton()->log( |
| 41 | $this->getLevel($message['level']), |
| 42 | json_encode($message), |
| 43 | ['frontend'] |
| 44 | ); |
| 45 | } |
| 46 | } |
| 47 | $this->returnJson($result); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Map log level |
| 52 | * @todo make it compatible with PRS-3 log levels |
| 53 | * @param $level |
| 54 | * @return int |
| 55 | */ |
| 56 | private function getLevel($level) |
| 57 | { |
| 58 | $result = \common_Logger::TRACE_LEVEL; |
| 59 | switch ($level) { |
| 60 | case 'fatal': |
| 61 | $result = \common_Logger::FATAL_LEVEL; |
| 62 | break; |
| 63 | case 'error': |
| 64 | $result = \common_Logger::ERROR_LEVEL; |
| 65 | break; |
| 66 | case 'warn': |
| 67 | $result = \common_Logger::WARNING_LEVEL; |
| 68 | break; |
| 69 | case 'info': |
| 70 | $result = \common_Logger::INFO_LEVEL; |
| 71 | break; |
| 72 | case 'debug': |
| 73 | $result = \common_Logger::DEBUG_LEVEL; |
| 74 | break; |
| 75 | case 'trace': |
| 76 | $result = \common_Logger::DEBUG_LEVEL; |
| 77 | break; |
| 78 | } |
| 79 | return $result; |
| 80 | } |
| 81 | } |