PHP code example of twentysix22 / laraveleslogs

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

    

twentysix22 / laraveleslogs example snippets

 bash
php artisan vendor:publish --provider="Twentysix22\LaravelESLogs\LaravelESLogsServiceProvider"
 bash 
php artisan laraveleslogs:configure
 bash 
php artisan laraveleslogs:tidy
 bash 
Route::get('/', function () {
    return view('welcome');
})->middleware('log:home');
 php 


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Twentysix22\LaravelESLogs\Services\Logging\Requests\ReportsRequestContext;

class TestController extends Controller
{
    use ReportsRequestContext;

    public function test()
    {
        $this->logContext([
            'key' => 'value',
            'key2' => 'value2',
        ]);

        $this->logGlobalContext([
            'globalkey' => 'value',
            'globalkey2' => 'value2',
        ]);

        return response()->json([
           'hello' => 'world',
        ]);
    }
}
 php 
use Twentysix22\LaravelESLogs\Services\Logging\Jobs\ReportsJobContext;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    use ReportsJobContext;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->logContext([
            'key' => 'value',
            'key2' => 'value2',
        ]);

        $this->logGlobalContext([
            'globalkey' => 'value',
            'globalkey2' => 'value2',
        ]);
    }
}
 php 
$this->setContextName('custom-context-name');