PHP code example of swisnl / laravel-graylog2

1. Go to this page and download the library: Download swisnl/laravel-graylog2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swisnl / laravel-graylog2 example snippets


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



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;
    }
}


// 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);