2017 © Pedro Peláez
 

library php-greylog-exception

A php exception logging implementation to send log-messages to a graylog compatible backend.

image

lucderheld/php-greylog-exception

A php exception logging implementation to send log-messages to a graylog compatible backend.

  • Tuesday, November 15, 2016
  • by lucderheld
  • Repository
  • 1 Watchers
  • 3 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

php-greylog-exception

Is a very usefull state of the art exception class and handler for PHP 7, (*1)

Latest Stable Version Total Downloads Build Status Build Status2 Code Coverage Scrutinizer Code Quality

Usage / Installation

Add php-greylog-exception to composer.json either by running composer require lucderheld/php-greylog-exception or by defining it manually:, (*2)

"require": {
   // ...
   "lucderheld/php-greylog-exception": "1.0"
   // ...
}

Reinstall dependencies: composer install, (*3)

Install GrayLog2-Server:

How GrayLog2 can be installed is well documented at http://docs.graylog.org/en/2.1/pages/installation.html The easiest way to test GreyLog is to run it as a Virtual-Machine:, (*4)

Install GrayLog2-Server as VM, (*5)

1. Usage Example


<?php require 'vendor/autoload.php'; use GreyLogException\GreyLogException; use GreyLogException\GreyLogExceptionConfig; GreyLogExceptionConfig::$sApplicationNameToLog = "SampleApplicationName"; GreyLogExceptionConfig::$sGreyLogServerIp = "127.0.0.1"; class KernelException extends GreyLogException { const SAMPLE_EXCEPTION = [10000001, GreyLogException::WARNING, "This is the exception error text with a variable '%s'"]; } class Kernel { public static $bBooted = false; public function __construct() { try { if (!Kernel::$bBooted) { throw new KernelException(KernelException::SAMPLE_EXCEPTION, "someValue"); } } catch (KernelException $e) { echo "Exception " . $e->getCode() . " was sent to GreyLog-Server " . GreyLogExceptionConfig::$sGreyLogServerIp; } } } new Kernel();

GreyLog output:

Example output, (*6)

2. Combination with own functions

php-greylog-exception can be combined with user defined exception-functions. The functions are triggered before the exception is logged to GreyLog. To define a exception-function, just create a static-function and name it the same as the actual exception., (*7)

Example:


//... class KernelException extends GreyLogException { const NOT_BOOTED = [10000002, GreyLogException::NOTICE, "This exceptions fires the function KernelException::NOT_BOOTED() before logging the exception to GrayLog"]; public static function NOT_BOOTED(){ Kernel::$bBooted = true; echo "The function ".__FUNCTION__." was called!"; } } class Kernel { public static $bBooted = false; public function __construct() { try { if (!Kernel::$bBooted) { throw new KernelException(KernelException::NOT_BOOTED); } } catch (KernelException $e) { echo "Exception " . $e->getCode() . " was sent to GreyLog-Server " . GreyLogExceptionConfig::$sGreyLogServerIp; } } } new Kernel();

PHP-Output:

The function NOT_BOOTED was called!Exception 10000002 was sent to GreyLog-Server 127.0.0.1, (*8)

3. Parameter logging

When an exception occours it is important to have as many informations as possible. The php-greylog-exception-class collects all the parameters that where called and saves them as serialized strings., (*9)

Example:

//...

class KernelException extends GreyLogException {

    const PARAMETER_SAMPLE = [10000003, GreyLogException::ERROR, "This exception is a sample exception for showing variables"];

}

class Kernel {

    public static $bBooted = false;

    public function __construct(array $_aSampleArray) {
        if (!Kernel::$bBooted) {
            throw new KernelException(KernelException::PARAMETER_SAMPLE);
        }
    }

}

class SampleClass {}

new Kernel(array(1, "two", new SampleClass()), 'NotNeededParameter');

GreyLog output:

Example parameter output, (*10)

License

The library is licensed under the GPL3 license. For details check out the LICENSE file., (*11)

Development & Contributing

You are welcome to modify, extend and bugfix as much as you like! :-) If you have any questions/proposals/etc. you are welcome to contact me via email., (*12)

The Versions

15/11 2016

dev-master

9999999-dev

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg

13/11 2016

0.4.1

0.4.1.0

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg

13/11 2016

v1.0

1.0.0.0

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg

13/11 2016

0.4

0.4.0.0

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg

12/11 2016

0.3

0.3.0.0

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg

12/11 2016

v0.2

0.2.0.0

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg

12/11 2016

0.1

0.1.0.0

A php exception logging implementation to send log-messages to a graylog compatible backend.

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Lukas Spangenberg