pagevamp/laravel-stack-driver-logger

8,443 4
Install
composer require pagevamp/laravel-stack-driver-logger
Latest Version:v1.0.3
PHP:>=5.4
License:MIT
Last Updated:Mar 27, 2018
Links: GitHub  ·  Packagist
Maintainer: developernaren

Laravel Stack Driver Logger

Google Cloud Stack Driver error monitoring integration for Laravel projects. This library adds a listener to Laravel's logging component. Laravel's session information will be sent in to Stack Driver, as well as some other helpful information such as 'environment', 'server', and 'session'.

Installation

Install using composer:

composer require pagevamp/laravel-stack-driver-logger

Add the service provider to the 'providers' array in config/app.php:

Pagevamp\Providers\StackDriverLoggerServiceProvider::class,

If you only want to enable Stack Driver reporting for certain environments you can conditionally load the service provider in your AppServiceProvider:

    public function register()
    {
        if ($this->app->environment('production')) {
            $this->app->register(\Pagevamp\Providers\StackDriverLoggerServiceProvider::class);
        }
    }

Configuration

This package supports configuration through the services configuration file located in config/services.php. All configuration variables will be directly passed to Stack Driver:

'stack_driver_logger' => [
    'credentials' => [
        'keyFile' => json_decode(trim(env('GC_LOG_SERVICE_CRED'), "'"), 1),
    ],
    'log_name' => env('GC_LOG_NAME', 'builder-log'),
],

Usage

To automatically monitor exceptions, simply use the Log facade in your error handler in app/Exceptions/Handler.php:

public function report(Exception $exception)
{
    \Log::error($exception); //Stack Driver
    parent::report($exception);
}

Your other log messages will also be sent to Stack Driver:

\Log::debug('Here is some debug information');

NOTE: Fatal exceptions will always be sent to Stack Driver.

Context informaton

You can pass user information as context like this:

\Log::error('Something went wrong', [
    'person' => ['id' => 123, 'username' => 'John Doe', 'email' => 'john@doe.com']
]);

Or pass some extra information:

\Log::warning('Something went wrong', [
    'download_size' => 3432425235
]);

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444