PHP code example of marick / laravel-google-cloud-logging

1. Go to this page and download the library: Download marick/laravel-google-cloud-logging 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/ */

    

marick / laravel-google-cloud-logging example snippets


'google_cloud' => [
    'driver' => 'google_cloud',
    'location' => env('GOOGLE_CLOUD_LOGGING_LOCATION'),
],

use Illuminate\Support\Facades\Log;

Log::debug('user logged in', [
    'user' => 5,
]);

use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\Log;

Context::add('user', 5);

Log::alert('user logged in');

'google_cloud' => [
    'driver' => 'google_cloud',
    'labels' => ['environment' => 'production'],
],

Log::debug('user logged in', [
    'labels' => ['request_id' => $requestId],
]);

use Marick\LaravelGoogleCloudLogging\CloudLogging;

CloudLogging::withLabels(['tenant_id' => $tenantId]);

// Or lazily via a closure, resolved at log time:
CloudLogging::withLabels(fn () => ['user_id' => auth()->id()]);

'google_cloud' => [
    'driver' => 'google_cloud',
    'location' => env('GOOGLE_CLOUD_LOGGING_LOCATION'),
    'log_name' => env('GOOGLE_CLOUD_LOG_NAME', 'laravel'),
],
dotenv
LOG_CHANNEL=google_cloud
json
{
  "sourceLocation": {
    "file": "/var/www/html/app/Http/Controllers/UserController.php",
    "line": "42",
    "function": "App\\Http\\Controllers\\UserController::store"
  }
}