nmc/laravel-cloud-logging

Google Cloud Logging For Laravel

1.2.0 2024-10-04 17:49 UTC

This package is auto-updated.

Last update: 2024-11-04 17:59:39 UTC


README

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require nmc/laravel-cloud-logging

You can publish the config file with:

php artisan vendor:publish --provider="Nmc\CloudLogging\CloudLoggingServiceProvider" --tag="cloud-logging-config"

This is the contents of the published config file:

return [
    'enable_error_reporting' => env('CLOUD_LOGGING_ENABLE_ERROR_REPORTING', isset($_SERVER['GAE_SERVICE']) ?? false),
    'logger' => [
        'driver' => 'stackdriver',
        'level' => env('LOG_LEVEL', 'debug'),
        'name' => env('CLOUD_LOGGING_NAME', 'laravel-cloud-logging'),
        'project' => env('CLOUD_LOGGING_PROJECT_ID'),
        'credentials' => env('CLOUD_LOGGING_CREDENTIALS', config_path('stackdriver.json')),
    ],
];

Edit app/Exceptions/Handler.php

    use Nmc\CloudLogging\CloudErrorReporting;

    public function register(): void
    {
        $this->reportable(function (Throwable $e) {
            if (CloudErrorReporting::isEnabled()) {
                CloudErrorReporting::report($e);
            }
        });
    }

Usage

use Illuminate\Support\Facades\Log;
Log::channel('stackdriver')->info('Test');

License

The MIT License (MIT). Please see License File for more information.