marick / laravel-google-cloud-logging
Fund package maintenance!
marickvantuil
Requires
- php: ^8.1 || 8.2 || 8.3
- google/cloud-logging: ^1.24
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/framework: ^10.0 || ^11.0
- laravel/pint: ^1.15
- nunomaduro/collision: ^7.0 || ^8.0
- orchestra/testbench: ^8.0 || ^9.0
- thecodingmachine/phpstan-safe-rule: ^1.2
This package is auto-updated.
Last update: 2024-10-25 20:34:56 UTC
README
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 } }