v-pack/laravel-gcloud-logging

Google Cloud Logging package for Laravel

1.0.0 2025-03-16 22:46 UTC

This package is not auto-updated.

Last update: 2025-03-17 14:43:43 UTC


README

Introduction

This package allows Laravel applications to log requests and responses to Google Cloud Logging. It includes a custom Monolog driver and a middleware to capture request logs, including cURL representations.

Installation

1. Install the Package

composer require username/laravel-gcloud-logging

2. Set Up Google Cloud Credentials

  1. Generate a Service Account Key in the Google Cloud Console.
  2. Download the JSON key file and place it in a secure directory in your Laravel project.
  3. Add the following environment variables in .env:
    GOOGLE_APPLICATION_CREDENTIALS=/path/to/google-service-account.json
    GOOGLE_CLOUD_PROJECT=your-project-id
    GOOGLE_CLOUD_LOG_NAME=your-log-name
    LOG_CHANNEL=google
    

Configuration

3. Publish the Config File (Optional)

If needed, publish the configuration file:

php artisan vendor:publish --tag=gcloud-logging-config

4. Custom Logging Driver

This package provides a custom logging driver. Ensure it is registered in config/logging.php:

'channels' => [
    'google' => [
        'driver' => 'custom',
        'via' => \VPACK\GCloudLogging\GoogleCloudLogger::class,
        'level' => 'debug',
    ],
],

Middleware for Logging Requests

5. Register Middleware

To log incoming requests and responses, add the middleware to app/Http/Kernel.php:

protected $middleware = [
    \VPACK\GCloudLogging\Middleware\LogCurlRequest::class,
];

Usage

6. Logging in Code

You can log manually using Laravel's Log facade:

use Illuminate\Support\Facades\Log;

Log::info('This is a test log', ['context' => 'example']);

7. View Logs in Google Cloud

  1. Open Google Cloud Logging.
  2. Filter logs by resource.type="global" or your custom log name.
  3. Monitor real-time logs.

Updating the Package

If new updates are available, update the package using:

composer update username/laravel-gcloud-logging

License

This package is open-source and licensed under the MIT License.