muchrm/laravel-graylog is a Laravel package for log your laravel application errors to graylog.
It currently has 1 GitHub stars and 39 downloads on Packagist (latest version 0.5.2).
Install it with composer require muchrm/laravel-graylog.
Discover more Laravel packages by muchrm
or browse all Laravel packages to compare alternatives.
Last updated
##Notic This is forcked version of swisnl/laravel-graylog2 i'm using it on my project Don't use me yet.
composer require muchrm/laravel-graylogMuchrm\Graylog\GraylogServiceProviderphp artisan vendor:publish to publish the config file to ./config/graylog.php.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.
Processors add extra functionality to the handler. You can register processors by modifying the AppServiceProvider:
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:
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.
You can define a custom processor by implementing Muchrm\Graylog\Processor\ProcessorInterface. The result should look something like this:
<?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;
}
}
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.
You can instantiate the Graylog class to send additional GELF messages:
// 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);
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.