PHP code example of plusinfolab / logstation

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

    

plusinfolab / logstation example snippets


// config/logstation.php

'authorization' => [
    'callback' => function ($request) {
        // Example 1: Allow specific users
        return in_array($request->user()?->email, [
            '[email protected]',
            '[email protected]',
        ]);
        
        // Example 2: Use Laravel Gate
        return Gate::allows('viewLogstation', $request->user());
        
        // Example 3: Check user role
        return $request->user()?->hasRole('admin');
        
        // Example 4: Environment-based
        return app()->environment(['local', 'staging']);
    },
],

use Illuminate\Support\Facades\Gate;

Gate::define('viewLogstation', function ($user) {
    return in_array($user->email, [
        '[email protected]',
    ]);
});

// app/Policies/LogStationPolicy.php
public function view(?User $user): bool
{
    return $user && $user->isAdmin();
}

'enabled' => env('LOGSTATION_ENABLED', !app()->environment('production')),

'driver' => env('LOGSTATION_DRIVER', 'database'),

'database' => [
    'connection' => env('LOGSTATION_DB_CONNECTION', config('database.default')),
],

'connections' => [
    'logstation' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'database' => 'logstation',
        'username' => env('DB_USERNAME'),
        'password' => env('DB_PASSWORD'),
        // ... other settings
    ],
],

'retention' => [
    'days' => env('LOGSTATION_RETENTION_DAYS', 7),
],

'watchers' => [
    PlusinfoLab\Logstation\Watchers\LogWatcher::class => [
        'enabled' => true,
        'channels' => ['stack', 'single', 'daily'],
        'levels' => ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'],
    ],
    PlusinfoLab\Logstation\Watchers\ExceptionWatcher::class => [
        'enabled' => true,
    ],
    PlusinfoLab\Logstation\Watchers\QueryWatcher::class => [
        'enabled' => false,
        'slow' => 100, // Log queries slower than 100ms
    ],
],

'authorization' => [
    'callback' => function ($request) {
        return app()->environment('local') ||
               $request->user()?->email === env('LOGSTATION_ADMIN_EMAIL');
    },
],

Gate::define('viewLogstation', function ($user) {
    return in_array($user->email, [
        '[email protected]',
    ]);
});

'broadcasting' => [
    'enabled' => env('LOGSTATION_BROADCASTING', false),
    'channel' => 'logstation',
],

use PlusinfoLab\Logstation\Facades\Logstation;

// Record a log entry
Logstation::recordLog([
    'level_name' => 'error',
    'message' => 'Something went wrong',
    'context' => ['user_id' => 123],
]);

// Search logs
$logs = Logstation::search([
    'level' => 'error',
    'start_date' => now()->subDays(7),
    'search' => 'payment',
], perPage: 50);

// Get statistics
$stats = Logstation::getStatistics();

// Find specific entry
$entry = Logstation::find($id);

// Delete entry
Logstation::delete($id);

protected function schedule(Schedule $schedule)
{
    $schedule->command('logstation:prune')->daily();
}

$schedule->command('logstation:prune')->daily();

'watchers' => [
    PlusinfoLab\Logstation\Watchers\QueryWatcher::class => [
        'enabled' => false, // Disable query watcher
    ],
],
bash
php artisan logstation:install
bash
php artisan vendor:publish --tag=logstation-config
bash
php artisan make:policy LogStationPolicy