2017 © Pedro Peláez
 

library laravel-graylog

Log your Laravel application errors to Graylog

image

muchrm/laravel-graylog

Log your Laravel application errors to Graylog

  • Tuesday, March 27, 2018
  • by muchrm
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 3 Versions
  • 29 % Grown

The README.md

Notic

This is forcked version of swisnl/laravel-graylog2 i'm using it on my project Don't use me yet., (*1)

Graylog Logging for Laravel 5.x

Latest Stable Version Build Status, (*2)

Installation

  1. Run composer require for this package: composer require muchrm/laravel-graylog
  2. Add the service provider to app.php if you don't like auto discovery: Muchrm\Graylog\GraylogServiceProvider
  3. Run php artisan vendor:publish to publish the config file to ./config/graylog.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., (*3)

Message Processors

Processors add extra functionality to the handler. You can register processors by modifying the AppServiceProvider:, (*4)

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

The following processors are available by default:, (*5)

ExceptionProcessor, (*6)

Adds exception data to the message if there is any., (*7)

RequestProcessor, (*8)

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

Custom processors

You can define a custom processor by implementing Muchrm\Graylog\Processor\ProcessorInterface. The result should look something like this:, (*10)

<?php

namespace App\Processors;

use Auth;
use Muchrm\Graylog\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., (*11)

Logging arbitrary data

You can instantiate the Graylog class to send additional GELF messages:, (*12)

// Send default log message
Graylog::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');
Graylog::logMessage($message);

Troubleshooting

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

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., (*13)

The Versions

27/03 2018

dev-master

9999999-dev

Log your Laravel application errors to Graylog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pongpanot Chuaysakun

laravel logging graylog

27/03 2018

0.5.2

0.5.2.0

Log your Laravel application errors to Graylog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pongpanot Chuaysakun

laravel logging graylog

27/03 2018

0.5.1

0.5.1.0

Log your Laravel application errors to Graylog

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pongpanot Chuaysakun

laravel logging graylog