PHP code example of arseno25 / exception-logger

1. Go to this page and download the library: Download arseno25/exception-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arseno25 / exception-logger example snippets


use Arseno25\ExceptionLogger\Logging\DatabaseLoggerHandler;

'channels' => [
    // ...
    'exception_logger' => [
        'driver' => 'monolog',
        'level' => 'error',
        'handler' => DatabaseLoggerHandler::class,
    ],
],

'stack' => [
    'driver' => 'stack',
    'channels' => ['single', 'exception_logger'],
    'ignore_exceptions' => false,
],

use Arseno25\ExceptionLogger\ExceptionLoggerPlugin;

->plugins([
    ExceptionLoggerPlugin::make(),
])

'critical' => [
    'exceptions' => [
        \Illuminate\Database\QueryException::class,
        \PDOException::class,
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
    ],
    'keywords' => [
        'database', 'connection', 'timeout', 'memory', 'fatal',
    ],
],

'telegram' => [
    'enabled' => env('EXCEPTION_LOGGER_TELEGRAM_ENABLED', false),
    'token' => env('TELEGRAM_BOT_TOKEN'),
    'chat_id' => env('TELEGRAM_CHAT_ID'),
    'throttle_minutes' => 5,
],

'slack' => [
    'enabled' => env('EXCEPTION_LOGGER_SLACK_ENABLED', false),
    'webhook_url' => env('EXCEPTION_LOGGER_SLACK_WEBHOOK_URL'),
    'channel' => env('EXCEPTION_LOGGER_SLACK_CHANNEL', '#exceptions'),
    'username' => env('EXCEPTION_LOGGER_SLACK_USERNAME', 'Exception Logger'),
    'throttle_minutes' => 5,
],

'discord' => [
    'enabled' => env('EXCEPTION_LOGGER_DISCORD_ENABLED', false),
    'webhook_url' => env('EXCEPTION_LOGGER_DISCORD_WEBHOOK_URL'),
    'username' => env('EXCEPTION_LOGGER_DISCORD_USERNAME', 'Exception Logger'),
    'throttle_minutes' => 5,
],

'email' => [
    'enabled' => env('EXCEPTION_LOGGER_EMAIL_ENABLED', false),
    'to' => env('EXCEPTION_LOGGER_EMAIL_TO'),
    'from' => [
        'address' => env('EXCEPTION_LOGGER_EMAIL_FROM_ADDRESS', env('MAIL_FROM_ADDRESS')),
        'name' => env('EXCEPTION_LOGGER_EMAIL_FROM_NAME', 'Exception Logger'),
    ],
    'subject_prefix' => env('EXCEPTION_LOGGER_EMAIL_SUBJECT_PREFIX', '[Exception Alert]'),
    'throttle_minutes' => 5,
],

'ai' => [
    'enabled' => env('EXCEPTION_LOGGER_AI_ENABLED', false),
    'api_key' => env('EXCEPTION_LOGGER_AI_API_KEY'),
    'base_url' => env('EXCEPTION_LOGGER_AI_BASE_URL', 'https://api.openai.com/v1'),
    'model' => env('EXCEPTION_LOGGER_AI_MODEL', 'gpt-3.5-turbo'),
    'temperature' => 0.5,
],

use Arseno25\ExceptionLogger\Widgets\ExceptionStatsOverview;

class MyCustomDashboard extends Filament\Pages\Dashboard
{
    protected function getHeaderWidgets(): array
    {
        return [
            ExceptionStatsOverview::class,
        ];
    }
}



namespace App\Filament\Widgets;

use Arseno25\ExceptionLogger\Widgets\ExceptionStatsOverview;
use Flowframe\Trend\Trend;

class CustomExceptionWidget extends ExceptionStatsOverview
{
    protected ?string $heading = 'Custom Error Analytics';

    protected function getData(): array
    {
        // Custom data logic - last 30 days instead of 7
        $data = Trend::model(ExceptionLog::class)
            ->between(
                start: now()->subDays(30),
                end: now(),
            )
            ->perDay()
            ->count();

        return [
            'datasets' => [
                [
                    'label' => 'Exceptions (30 Days)',
                    'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
                    'borderColor' => '#8b5cf6', // Purple
                    'backgroundColor' => '#ede9fe',
                    'fill' => true,
                ],
            ],
            'labels' => $data->map(fn (TrendValue $value) => $value->date),
        ];
    }
}

'pruning' => [
    'enabled' => true,
    'retention_days' => 30,
],

protected function schedule(Schedule $schedule): void
{
    $schedule->command('model:prune')->daily();
}
bash
php artisan vendor:publish --tag="exception-logger-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="exception-logger-config"