PHP code example of onamfc / laravel-devlogger

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

    

onamfc / laravel-devlogger example snippets


use DevLogger;

// Basic logging
DevLogger::info('User logged in', ['user_id' => 123]);
DevLogger::error('Payment failed', ['order_id' => 456, 'error' => 'Card declined']);
DevLogger::debug('Debug information', ['data' => $debugData]);

// With queue context
DevLogger::onQueue('email-queue')->info('Email sent', ['recipient' => '[email protected]']);

// With tags
DevLogger::withTags(['payment', 'critical'])->error('Payment gateway timeout');

// Method chaining
DevLogger::onQueue('reports')
    ->withTags(['report', 'daily'])
    ->info('Daily report generated');

try {
    // Some risky operation
    $result = $this->riskyOperation();
} catch (Exception $e) {
    DevLogger::logException($e, ['context' => 'additional info']);
    throw $e; // Re-throw if needed
}



namespace App\Exceptions;

use DevLoggerPackage\Exceptions\DevLoggerExceptionHandler;

class Handler extends DevLoggerExceptionHandler
{
    // Your existing exception handling code
}

use DevLoggerPackage\Facades\DevLogger;

public function report(Throwable $exception)
{
    if ($this->shouldReport($exception) && config('devlogger.auto_catch_exceptions', true)) {
        DevLogger::logException($exception, [
            'url' => request()->fullUrl(),
            'method' => request()->method(),
            'input' => request()->except(['password', 'password_confirmation', '_token']),
        ]);
    }

    parent::report($exception);
}


->withExceptions(function (Exceptions $exceptions) {
   
    $exceptions->report(function (Throwable $e){
        if (config('devlogger.auto_catch_exceptions', true)) {
            \DevLoggerPackage\Facades\DevLogger::logException($e, [
                'url' => request()?->fullUrl(),
                'method' => request()?->method(),
                'input' => request()?->except(['password', 'password_confirmation', '_token']),
            ]);
        }
        return true;
    });
    
})->create();

use DevLoggerPackage\Models\DeveloperLog;

// Query logs
$errorLogs = DeveloperLog::level('error')->open()->get();
$recentLogs = DeveloperLog::dateRange(now()->subDays(7), now())->get();
$queueLogs = DeveloperLog::queue('email-queue')->get();

// Manage log status
$log = DeveloperLog::find(1);
$log->markAsClosed(auth()->id());
$log->markAsOpen();

// Work with tags
$log->addTags(['reviewed', 'fixed']);
$log->removeTags(['critical']);

return [
    // Default log level
    'log_level' => env('DEVLOGGER_LOG_LEVEL', 'debug'),
    
    // Database connection
    'database_connection' => env('DEVLOGGER_DB_CONNECTION', null),
    
    // Table name
    'table_name' => env('DEVLOGGER_TABLE_NAME', 'developer_logs'),
    
    // Enable database logging
    'enable_database_logging' => env('DEVLOGGER_ENABLE_DB', true),
    
    // Auto-catch exceptions
    'auto_catch_exceptions' => env('DEVLOGGER_AUTO_CATCH', true),
    
    // Fallback Laravel channels
    'fallback_channels' => env('DEVLOGGER_FALLBACK_CHANNELS', null),
    
    // Log retention in days
    'retention_days' => env('DEVLOGGER_RETENTION_DAYS', 30),
    
    // Paths to exclude from auto-logging
    'excluded_paths' => [
        'vendor/',
        'storage/framework/',
    ],
];
bash
php artisan migrate