/raygun-logger

Laravel package for logging errors to Raygun

Primary LanguagePHPMIT LicenseMIT

Laravel package for logging errors to Raygun

Latest Version on Packagist Total Downloads GitHub Actions

This package serves as a wrapper around Raygun4php to make it quick and easy to get your Laravel project logging to Raygun.

Warning This package is being developed alongside and being used with production applications. But it is not tagged for with version 1.0 because we can only validate those particular use cases. We will want to catch any edge cases and finalize every base use case before encouraging users to use this in critical projects.

Installation

You can install the package via composer:

composer require llewellyn-kevin/raygun-logger

In your application's config/logging.php, add the raygun channel config and add it to the stack config:

[
    'channel' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily', 'raygun'],
            // ...
        ],

        // ...

        'raygun' => [
            'driver' => 'raygun',
        ],
    ],
]

Update your .env with the Raygun url and key you want to use:

RAYGUN_URI=https://api.raygun.com
RAYGUN_KEY=[[project key here]]

You can test your install with a console command:

php artisan ragun:test

Or with a custom error message:

php artisan ragun:test "The fox already jumped over the dog."

This will check for environment variables, report on any missing, and send an exception with default or custom text to Raygun so you can check to make sure it shows up.

Usage

Errors should be automatically sent to raygun via the stack. But if you need to manually send an exception to Raygun for any reason you can do that with the RaygunLogger facade:

RaygunLogger::handle(new Exception('The fox already jumped over the dog.'));

You can add metadata to these requests in an associative array as well:

RaygunLogger::handle(new Exception('The fox already jumped over the dog.'), [
    'foxname' => 'Tod',
    'dogname' => 'Copper',
]);

Note This is the main method of the entire package. So it enforces all core logic. This means Exception types that have been blacklisted or do not meet the level requirement will still be suppressed and NOT be sent to Raygun.

Filtering

You may not want every error to show up in Raygun. There are two ways to suppress an error:

  1. Blacklist the exception type

In the raygun-logger config, you will find a parameter called blacklist. Any exceptions added to this array will not be reported to Raygun. To append to this list, you will first have to publish the config:

php artisan vendor:publish --tag=config
  1. Setting error levels

You may wish to specify the log levels for various exceptions in your application. You can register these levels in the RaygunLogger facade:

RaygunLogger::level(Exception::class, LogLevel::CRITICAL);

Then you may update the raygun-logger config with the base level you wish to report on. Only exceptions with the specified level or higher will be sent to Raygun.

Testing

This package uses Pest for it's tests. For simplicity, there is a composer script to run the whole suite:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email llewellynkevin1@gmail.com instead of using the issue tracker.

Credits

  • All Contributors
  • This package is massively inspired by the work done over at LaraBug. The goal was to have a LaraBug like experience for setting up Raygun. They have an amazing product and much of their code is used as the foundation for this package. If you don't need Raygun, you may give that a shot as a free alternative.

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.