PHP code example of mxnwire / laravel-logbarrel

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

    

mxnwire / laravel-logbarrel example snippets


'channels' => [
    'requests' => [
        'driver' => 'daily',
        'path' => storage_path('logs/requests.log'),
        'days' => 14,
    ],
],

use Mxnwire\LogBarrel\Facades\LogBarrel;

class CheckoutController
{
    public function store(Request $request)
    {
        // Don't log this request at all.
        LogBarrel::disable();

        // ...or force-log it even when globally off / outside the configured groups.
        LogBarrel::enable();

        // Attach extra context to the entry.
        LogBarrel::context(['order_id' => $order->id]);

        // Redact extra body keys on top of the configured list.
        LogBarrel::redact('ssn');                 // or ['ssn', 'card_number']

        // Capture only specific fields, or drop specific ones.
        LogBarrel::only('method', 'url', 'user'); // whitelist
        LogBarrel::without('body');               // blacklist

        // Send this request's entry to a different channel / message.
        LogBarrel::channel('audit')->message('checkout_completed');
    }
}

logbarrel()->disable();
logbarrel()->context(['order_id' => $order->id])->channel('audit');

Route::middleware('logbarrel')->group(function () {
    // ...
});
bash
php artisan vendor:publish --tag=logbarrel-config