PHP code example of vinkius-labs / watchdog-discord

1. Go to this page and download the library: Download vinkius-labs/watchdog-discord 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/ */

    

vinkius-labs / watchdog-discord example snippets


use VinkiusLabs\WatchdogDiscord\Facades\WatchdogDiscord;

// Log exceptions with context
try {
    $result = $riskyOperation->execute();
} catch (\Exception $e) {
    WatchdogDiscord::send($e, 'error', [
        'operation' => 'payment_processing',
        'user_id' => auth()->id()
    ]);
    throw $e;
}

// Log custom messages
WatchdogDiscord::sendLog('warning', 'High memory usage detected', [
    'memory_usage' => memory_get_usage(true),
    'peak_memory' => memory_get_peak_usage(true)
]);

// Emergency level (severity: 10)
WatchdogDiscord::emergency('Database server down');

// Alert level (severity: 9)  
WatchdogDiscord::alert('Payment gateway unreachable');

// Critical level (severity: 8)
WatchdogDiscord::critical('Application crashed');

// Error level (severity: 6)
WatchdogDiscord::error('User authentication failed');

// Warning level (severity: 4)
WatchdogDiscord::warning('High memory usage');

// Notice level (severity: 2)
WatchdogDiscord::notice('New admin user created');

// Info level (severity: 1) 
WatchdogDiscord::info('Backup completed successfully');

// Debug level (severity: 1)
WatchdogDiscord::debug('Cache warming started');

// Apply to specific routes
Route::middleware('watchdog-discord:error')->group(function () {
    Route::post('/api/payments', [PaymentController::class, 'process']);
});

// Global middleware (app/Http/Kernel.php)
protected $middleware = [
    \VinkiusLabs\WatchdogDiscord\Middleware\WatchdogDiscordMiddleware::class,
];

use VinkiusLabs\WatchdogDiscord\DiscordNotifier;

class PaymentService
{
    public function __construct(
        private DiscordNotifier $notifier
    ) {}
    
    public function processPayment($data)
    {
        try {
            return $this->gateway->charge($data);
        } catch (\Exception $e) {
            $this->notifier->send($e, 'critical', [
                'payment_data' => $data,
                'gateway' => $this->gateway->getName()
            ]);
            throw $e;
        }
    }
}

// config/database.php
'redis' => [
    'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'port' => env('REDIS_PORT', '6379'),
        'database' => env('REDIS_DB', '0'),
    ],
],
bash
php artisan vendor:publish --provider="VinkiusLabs\WatchdogDiscord\WatchdogDiscordServiceProvider" --tag="watchdog-discord-config"
bash
php artisan migrate
bash
# Supervisor configuration
php artisan queue:work redis --queue=watchdog_notifications --sleep=3 --tries=3