PHP code example of pgtruesdell / laravel-logsnag

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

    

pgtruesdell / laravel-logsnag example snippets


return [
    // Your LogSnag project slug
    'project' => env('LOGSNAG_PROJECT', 'my-laravel-app'),

    // Default channel for the Monolog driver
    'channel' => env('LOGSNAG_CHANNEL', 'app-events'),

    // Your LogSnag API token
    'token' => env('LOGSNAG_TOKEN', ''),

    // Icon mapping for the Monolog driver (keyed by Monolog level name)
    'icons' => [
        'Debug'     => 'ℹ️',
        'Info'      => 'ℹ️',
        'Notice'    => '📌',
        'Warning'   => '⚠️',
        'Error'     => '⚠️',
        'Critical'  => '🔥',
        'Alert'     => '🔔️',
        'Emergency' => '💀',
    ],
];

use PGT\Logsnag\Facades\Logsnag;

// Minimal
Logsnag::log(channel: 'waitlist', event: 'User Signed Up');

// With all options
Logsnag::log(
    channel: 'billing',
    event: 'Subscription Renewed',
    description: 'Pro plan renewed for another year.',
    icon: '💳',
    notify: true,
    tags: ['plan' => 'pro', 'cycle' => 'yearly'],
    parser: \PGT\Logsnag\Enums\Parser::Markdown,
    userId: 'user-123',
    timestamp: now()->subMinutes(5)->timestamp,
);

logsnag(
    channel: 'waitlist',
    event: 'User Signed Up',
    description: 'A new user joined the waitlist.',
    icon: '🎉',
);

use PGT\Logsnag\Facades\Logsnag;

Logsnag::insight(title: 'Total Users', value: 1250, icon: '👥');
Logsnag::insight(title: 'MRR', value: 14999.99, icon: '💰');
Logsnag::insight(title: 'Status', value: 'Operational');

insight(title: 'Total Users', value: 1250, icon: '👥');

use PGT\Logsnag\Facades\Logsnag;

// Increment
Logsnag::mutateInsight(title: 'API Calls', incrementBy: 1);

// Decrement
Logsnag::mutateInsight(title: 'Open Tickets', incrementBy: -1);

// Float values
Logsnag::mutateInsight(title: 'Revenue', incrementBy: 49.99, icon: '💰');

mutate_insight(title: 'API Calls', incrementBy: 1);

use PGT\Logsnag\Facades\Logsnag;

Logsnag::identify(userId: 'user-123', properties: [
    'name' => 'Jane Doe',
    'email' => '[email protected]',
    'plan' => 'enterprise',
    'company' => 'Acme Inc.',
]);

identify(userId: 'user-123', properties: [
    'name' => 'Jane Doe',
    'plan' => 'enterprise',
]);

'channels' => [
    // ...

    'logsnag' => [
        'driver' => 'custom',
        'via' => \PGT\Logsnag\Logger\LogsnagLogger::class,
        'level' => 'error', // Minimum log level to send
    ],
],

use Illuminate\Support\Facades\Log;

Log::channel('logsnag')->info('User logged in', ['user_id' => 123]);
Log::channel('logsnag')->error('Payment failed', ['order_id' => 456]);

use PGT\Logsnag\Client\LogsnagClientException;
use PGT\Logsnag\Facades\Logsnag;

try {
    Logsnag::log(channel: 'app', event: 'Something');
} catch (LogsnagClientException $e) {
    // $e->getMessage() contains the error details
    // $e->response contains the HTTP response (if available)
}
bash
php artisan vendor:publish --tag="laravel-logsnag-config"