Looking to hire Laravel developers? Try LaraJobs

laravel-google-cloud-logging maintained by marick

Last update
2026/04/13 23:05 (dev-master)
License
Links
Downloads
31 492

Comments
comments powered by Disqus

Companion packages: Cloud Scheduler, Cloud Tasks

Introduction

This package lets you use Google Cloud Logging as the log driver for Laravel.

The package will automatically detect the environment it's running in (currently supports Cloud Run or App Engine), and attach the correct labels to the log entry so the logs appear in the application service.

Installation

Install the package with Composer:

composer require marick/laravel-google-cloud-logging

Add a new logging channel in config/logging.php:

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

Use the new channel:

LOG_CHANNEL=google_cloud

[!IMPORTANT] A location is mandatory to make log entries appear in Cloud Run or App Engine.

How to

Use log context

use Illuminate\Support\Facades\Log;

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

The above context will be added in Cloud Logging:

{
  "jsonPayload": {
    "message": "user logged in"
  },
  "labels": {
    "user": 5
  }
}

Use Context

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

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

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

The above context will be added in Cloud Logging:

{
  "jsonPayload": {
    "message": "user logged in"
  },
  "labels": {
    "user": 5
  }
}