2017 © Pedro Peláez
 

library graylog

A package to send logs to graylog

image

ubatgroup/graylog

A package to send logs to graylog

  • Friday, March 16, 2018
  • by JulienMoulinUbat
  • Repository
  • 0 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel wrapper for UbatGroup Graylog Server

It is a laravel wrapper for bzikarsky/gelf-php package., (*1)

This package was developed for an internal need. No maintenance's planned., (*2)

Installation

Install via composer, (*3)

composer require ubatgroup/graylog

Only for Laravel 5 to 5.3

Add it to your providers array in config/app.php:, (*4)

Ubatgroup\Graylog\GraylogServiceProvider::class

To use the facade, add it to your aliases array in config/app.php:, (*5)

'Graylog' => Ubatgroup\Graylog\Facades\Graylog::class

For Laravel 5.4 and more

Laravel auto discover new packages, (*6)

composer dump-autoload

Configuration

Set the graylog configuration into the .env file :, (*7)

  • GRAYLOG_SERVER : server graylog ip (if this key is not set, it uses 127.0.0.1)
  • GRAYLOG_PORT : server graylog port (if this key is not set, it uses 12201)
  • GRAYLOG_FACILITY : graylog facility filter (if this key is not set, it uses APP_URL key)
  • GRAYLOG_APPNAME : graylog source filter (if this key is not set, it uses APP_NAME key)
To override the configuration file :

First, publish the configuration file:, (*8)

php artisan vendor:publish --provider="Ubatgroup\Graylog\GraylogServiceProvider"

See the content of the published configuration file in config/graylog.php., (*9)

// Address serveur host
'server'   => env( 'GRAYLOG_SERVER', '127.0.0.1' ),

// Port server host
'port'     => env( 'GRAYLOG_PORT', 12201 ),

// facility to filter logs (common use application URL)
'facility' => env( 'GRAYLOG_FACILITY', env( 'APP_URL', null ) ),

// host to filter logs (common use application name)
'host'     => env( 'GRAYLOG_HOST', env( 'APP_NAME', null ) ),

// Add Auth::user data automatically as AdditionaData in every exception handle by the connected user
'auto_log_auth_user' => true,

Usage

 Graylog::emergency( $message, array $context = array() );
 Graylog::alert( $message, array $context = array() );
 Graylog::critical( $message, array $context = array() );
 Graylog::error( $message, array $context = array() );
 Graylog::warning( $message, array $context = array() );
 Graylog::notice( $message, array $context = array() );
 Graylog::info( $message, array $context = array() );
 Graylog::debug( $message, array $context = array() );

See the bzikarsky/gelf-php examples in his repo to find the available methods for the Graylog facade., (*10)

Example

Graylog::alert('There was a foo in bar', [
    'foo' => 'bar',
    'other_context_key' => 'other_context_value',
]);
try {
    throw new \Exception('Nice exception !');
} catch (\Exception $e) {
    Graylog::emergency('Exception handled !', [
        'exception' => $e,
        'additionnal_data' => 'Hello world!
    ]);
}

Note

  • If auto_log_auth_user config key and Auth::check() are true, Auth::user() data are auto added to the context array (auth_user key)
  • If you need to use $guard to get the authenticated user, turn false the auto_log_auth_user config key and add it manually in additionnal data array
  • Don't use special/accentuated chars in context key for additionals data

License

This package is released under the MIT Licence., (*11)

The Versions

16/03 2018

dev-master

9999999-dev

A package to send logs to graylog

  Sources   Download

MIT

The Requires

 

by Julien Moulin

16/03 2018

1.0

1.0.0.0

A package to send logs to graylog

  Sources   Download

MIT

The Requires

 

by Julien Moulin