slickframework /
telemetry
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file is part of slick/telemetry package |
||
| 5 | * |
||
| 6 | * For the full copyright and license information, please view the LICENSE |
||
| 7 | * file that was distributed with this source code. |
||
| 8 | */ |
||
| 9 | |||
| 10 | declare(strict_types=1); |
||
| 11 | |||
| 12 | namespace Slick\Telemetry\Model; |
||
| 13 | |||
| 14 | use Psr\Log\LogLevel; |
||
| 15 | use Slick\Telemetry\Trackable; |
||
| 16 | use Throwable; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * ExceptionTrackable |
||
| 20 | * |
||
| 21 | * @package Slick\Telemetry\Model |
||
| 22 | */ |
||
| 23 | final class ExceptionTrackable implements Trackable |
||
| 24 | { |
||
| 25 | use TrackableMethods; |
||
| 26 | |||
| 27 | private Throwable $exception; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Creates a ExceptionTrackable |
||
| 31 | * |
||
| 32 | * @param Throwable $exception |
||
| 33 | * @param iterable $context |
||
| 34 | */ |
||
| 35 | public function __construct(Throwable $exception, iterable $context = []) |
||
| 36 | { |
||
| 37 | $this->message = $exception->getMessage(); |
||
| 38 | $this->exception = $exception; |
||
| 39 | $this->context = $context; |
||
| 40 | $this->logLevel = LogLevel::ALERT; |
||
| 41 | $this->label = Trackable::LABEL_EXCEPTION; |
||
| 42 | $this->context = array_merge($context, [ |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 43 | 'label' => $this->label, |
||
| 44 | 'exception' => get_class($this->exception), |
||
| 45 | 'file' => "{$exception->getFile()} ({$exception->getLine()})", |
||
| 46 | 'trace' => $this->exception->getTraceAsString() |
||
| 47 | ]); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * exception |
||
| 52 | * |
||
| 53 | * @return Throwable |
||
| 54 | */ |
||
| 55 | public function exception(): Throwable |
||
| 56 | { |
||
| 57 | return $this->exception; |
||
| 58 | } |
||
| 59 | } |
||
| 60 |