1. Go to this page and download the library: Download gopimosali/global-logger 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/ */
gopimosali / global-logger example snippets
use Illuminate\Support\Facades\Log;
// Standard logging - now ayment failed', ['order_id' => 456]);
// Logs now production
// - application: my-app
// Request starts - request_id generated: 550e8400...
Log::info('User login attempt'); // ✅ Has request_id
Log::info('Checking database'); // ✅ Same request_id
Log::error('Invalid password'); // ✅ Same request_id
// All logs from this request share the same request_id
use Illuminate\Support\Facades\{Log, Http};
$requestId = Log::getContextManager()->getRequestId();
// Pass to external service
$response = Http::withHeaders([
'X-Request-ID' => $requestId
])->post('https://external-service.com/api', [
'data' => 'value'
]);
// Now external service logs can use the same request_id!
Log::getContextManager()->addContext([
'feature_flag' => 'new_checkout',
'ab_test_variant' => 'B',
'tenant_id' => 'tenant-123'
]);
// All subsequent logs in this request
$contextManager = Log::getContextManager();
// Get standard request_id
$requestId = $contextManager->getRequestId();
// 550e8400-e29b-41d4-a716-446655440000
// Convert to X-Ray format
$xrayTraceId = $contextManager->toXRayTraceId();
// 1-65a5b12c-550e8400e29b41d4a716
// Convert to Datadog format
$datadogTraceId = $contextManager->toDatadogTraceId();
// 6145998120563704832
use Illuminate\Support\Facades\DB;
// Find all logs from one request
DB::table('global_logs')
->where('request_id', '550e8400-e29b-41d4-a716-446655440000')
->orderBy('created_at')
->get();
// Find errors in last hour
DB::table('global_logs')
->where('level', 'error')
->where('created_at', '>', now()->subHour())
->get();