<?php

declare(strict_types=1);

namespace Apexl\Io\Logger\Hooks;

use Apexl\Io\Interfaces\AbstractHook;
use Apexl\Io\Logger\Traits\GetsSimpleTrace;
use Throwable;

final readonly class ErrorListener implements AbstractHook
{
    use GetsSimpleTrace;

    public function hooks(): array
    {
        return ['error'];
    }

    public function __invoke(Throwable $thrown): void
    {
        \Apexl\Io\Logger\logger('error')->error(sprintf('%s: %s', $thrown::class, $thrown->getMessage()), [
            'trace' => self::simpleTrace($thrown->getTrace()),
        ]);
    }
}
