PHP code example of lucderheld / php-greylog-exception
1. Go to this page and download the library: Download lucderheld/php-greylog-exception 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/ */
lucderheld / php-greylog-exception example snippets
gException\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();
//...
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();
//...
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');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.