All Projects → swisnl → laravel-graylog2

swisnl / laravel-graylog2

Licence: MIT license
Log your Laravel application errors to Graylog2

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-graylog2

Graylog-Plugin-AlertManager-Callback
A plugin for Graylog which provides the possibility to send alerts to the Prometheus AlertManager API.
Stars: ✭ 23 (+15%)
Mutual labels:  graylog2

Graylog2 Logging for Laravel 5.x

License Build Status Made by SWIS

🚨 THIS PACKAGE HAS BEEN ABANDONED 🚨

We don't use this package anymore in our own projects and cannot justify the time needed to maintain it anymore. That's why we have chosen to abandon it. Feel free to fork our code and maintain your own copy or use one of the many alternatives.

Installation

  1. Run composer require for this package: composer require swisnl/laravel-graylog2
  2. Add the service provider to app.php if you don't like auto discovery: Swis\Graylog2\Graylog2ServiceProvider
  3. Run php artisan vendor:publish to publish the config file to ./config/graylog2.php.
  4. Configure it to your liking
  5. Done!

Logging exceptions

The default settings enable logging of exceptions. It will add the HTTP request to the GELF message, but it will not add POST values. Check the graylog2.log-requests config to enable or disable this behavior.

Minimum log level

You can adjust the minimum log level by changing the value log_levelin configuration.

Message Processors

Processors add extra functionality to the handler. You can register processors by modifying the AppServiceProvider:

public function register()
{
    //...
    Graylog2::registerProcessor(new \Swis\Graylog2\Processor\ExceptionProcessor());
    Graylog2::registerProcessor(new \Swis\Graylog2\Processor\RequestProcessor());
    Graylog2::registerProcessor(new MyCustomProcessor());
    //...
}

The following processors are available by default:

ExceptionProcessor

Adds exception data to the message if there is any.

RequestProcessor

Adds the current Laravel Request to the message. It adds the url, method and ip by default.

Custom processors

You can define a custom processor by implementing Swis\Graylog2\Processor\ProcessorInterface. The result should look something like this:

<?php

namespace App\Processors;

use Auth;
use Swis\Graylog2\Processor\ProcessorInterface;

class MyCustomProcessor implements ProcessorInterface
{
    public function process($message, $exception, $context)
    {
        $message->setAdditional('domain', config('app.url'));

        if (Auth::user()) {
            $message->setAdditional('user_id', Auth::id());
        }

        return $message;
    }
}

Don't report exceptions

In app/Exceptions/Handler.php you can define the $dontReport array with Exception classes that won't be reported to the logger. For example, you can blacklist the \Illuminate\Database\Eloquent\ModelNotFoundException. Check the Laravel Documentation about errors for more information.

Logging arbitrary data

You can instantiate the Graylog2 class to send additional GELF messages:

// Send default log message
Graylog2::log('emergency', 'Dear Sir/Madam, Fire! Fire! Help me!. 123 Cavendon Road. Looking forward to hearing from you. Yours truly, Maurice Moss.', ['facility' => 'ICT']);

// Send custom GELF Message
$message = new \Gelf\Message();
$message->setLevel('emergency');
$message->setShortMessage('Fire! Fire! Help me!');
$message->setFullMessage('Dear Sir/Madam, Fire! Fire! Help me!. 123 Cavendon Road. Looking forward to hearing from you. Yours truly, Maurice Moss.');
$message->setFacility('ICT');
$message->setAdditional('employee', 'Maurice Moss');
Graylog2::logMessage($message);

Troubleshooting

Long messages (or exceptions) won't show up in Graylog2

You might need to increase the size of the UDP chunks in the UDP Transport (see the config file). Otherwise, you can send packets in TCP mode.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].