PHP code example of shadowbane / laravel-gelf-logger

1. Go to this page and download the library: Download shadowbane/laravel-gelf-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/ */

    

shadowbane / laravel-gelf-logger example snippets


'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'gelf'],
    ],
],

use Illuminate\Support\Facades\Log;

Log::channel('gelf')->info('User logged in', [
    'user_id' => 123,
    'ip_address' => '192.168.1.1',
]);

Log::channel('gelf')->error('Payment failed', [
    'order_id' => 456,
    'amount' => 99.99,
]);

try {
    // Your code
} catch (\Exception $e) {
    Log::channel('gelf')->error('Failed to process order: ' . $e->getMessage(), [
        'exception' => $e,
        'order_id' => 123,
        'user_id' => 456,
    ]);
}

Log::channel('gelf')->warning('High memory usage', [
    'memory_used' => '512MB',
    'memory_limit' => '256MB',
    'server' => 'web-01',
]);

// In AppServiceProvider::boot() or middleware
use Illuminate\Support\Facades\Context;

Context::add('request_id', uniqid());

// config/gelf-logger.php
'processors' => [
    \Monolog\Processor\MemoryUsageProcessor::class,
    \Monolog\Processor\WebProcessor::class,
],
bash
php artisan vendor:publish --tag=gelf-logger-config
json
{
  "extras": "{\"memory_used\":\"512MB\",\"memory_limit\":\"256MB\",\"server\":\"web-01\"}"
}
bash
php artisan gelf:send-test-exception