PHP code example of robbiekibler / laravel-posthog-logs

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

    

robbiekibler / laravel-posthog-logs example snippets


'channels' => [
    // ... other channels

    'posthog' => [
        'driver' => 'posthog',
    ],
],

// Use PostHog as default
'default' => env('LOG_CHANNEL', 'posthog'),

// Or add to a stack
'stack' => [
    'driver' => 'stack',
    'channels' => ['single', 'posthog'],
],

use Illuminate\Support\Facades\Log;

// Basic logging
Log::info('User logged in');
Log::warning('Rate limit approaching');
Log::error('Payment failed', ['order_id' => 123]);

// With context
Log::channel('posthog')->info('Order created', [
    'order_id' => $order->id,
    'customer_id' => $customer->id,
    'total' => $order->total,
]);

Log::info('Processing request', [
    'trace_id' => $traceId,
    'span_id' => $spanId,
    'user_id' => $userId,
]);

'posthog' => [
    'driver' => 'posthog',
    'level' => 'warning',  // Only send warnings and above
    'service_name' => 'my-api',
    'environment' => 'staging',
],

// config/posthog-logs.php
'resource_attributes' => [
    'team.name' => 'backend',
    'version' => '1.3.0',
],
bash
php artisan vendor:publish --tag="posthog-logs-config"
bash
php artisan posthog:test