Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
4 / 4 |
| Log | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
4 / 4 |
| setLogger | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| unexpected_exception | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| __callStatic | |
100.00% |
1 / 1 |
2 | |
100.00% |
2 / 2 |
|||
| 1 | <?php |
| 2 | |
| 3 | // {{{ License |
| 4 | // This file is part of GNU social - https://www.gnu.org/software/social |
| 5 | // |
| 6 | // GNU social is free software: you can redistribute it and/or modify |
| 7 | // it under the terms of the GNU Affero General Public License as published by |
| 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | // (at your option) any later version. |
| 10 | // |
| 11 | // GNU social is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU Affero General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU Affero General Public License |
| 17 | // along with GNU social. If not, see <http://www.gnu.org/licenses/>. |
| 18 | // }}} |
| 19 | |
| 20 | /** |
| 21 | * GNU social's logger wrapper around Symfony's, |
| 22 | * keeping our old static interface, which is more convenient and just as powerful |
| 23 | * |
| 24 | * @package GNUsocial |
| 25 | * @category Log |
| 26 | * |
| 27 | * @author Hugo Sales <hugo@hsal.es> |
| 28 | * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org |
| 29 | * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later |
| 30 | */ |
| 31 | |
| 32 | namespace App\Core; |
| 33 | |
| 34 | use App\Util\Exception\ServerException; |
| 35 | use Psr\Log\LoggerInterface; |
| 36 | |
| 37 | abstract class Log |
| 38 | { |
| 39 | private static ?LoggerInterface $logger; |
| 40 | |
| 41 | public static function setLogger($l): void |
| 42 | { |
| 43 | self::$logger = $l; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Log a critical error when a really unexpected exception occured. This indicates a bug in the software |
| 48 | * |
| 49 | * @throws ServerException |
| 50 | * @codeCoverageIgnore |
| 51 | */ |
| 52 | public static function unexpected_exception(\Exception $e) |
| 53 | { |
| 54 | $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
| 55 | self::critical('Unexpected exception of class: "' . get_class($e) . '" was thrown in ' . get_called_class() . '::' . $backtrace[1]['function']); |
| 56 | throw new ServerException('Unexpected exception', 500, $e); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Simple static wrappers around Monolog's functions |
| 61 | */ |
| 62 | public static function __callStatic(string $name, array $args) |
| 63 | { |
| 64 | if (isset(self::$logger)) { |
| 65 | return self::$logger->{$name}(...$args); |
| 66 | } else { |
| 67 | // @codeCoverageIgnoreStart |
| 68 | return null; |
| 69 | // @codeCoverageIgnoreEnd |
| 70 | } |
| 71 | } |
| 72 | } |