PHP code example of schema31 / php-monitoring

1. Go to this page and download the library: Download schema31/php-monitoring 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/ */

    

schema31 / php-monitoring example snippets


use Schema31\PhpMonitoring\Logger;
use Schema31\PhpMonitoring\LoggerConstants;

...

$logger = new Logger("streamName", "authentication", LoggerConstants::REST, LoggerConstants::DEBUG);


use Schema31\PhpMonitoring\Logger;
use Schema31\PhpMonitoring\LoggerConstants;

...

define('LOGGER_STREAMNAME', 'streamName');
define('LOGGER_AUTHENTICATION', 'authentication');
define('LOGGER_PROTOCOL', LoggerConstants::REST);
define('LOGGER_THRESHOLD', LoggerConstants::DEBUG);

$logger = new Logger();

//Method chaining is allowed
$logger->setProtocol(LoggerConstants::REST) //if you want to ovverride the default
->setLevel(LoggerConstants::ALERT)
->setFacility("PhpMonitoring")
->setFile(__FILE__)
->setLine(__LINE__)
->setShortMessage("Short Message " . uniqid())
->setFullMessage("Full Message")
->setSingleAdditional("key1", "value1")
->publish();

try{
    throw new \Exception("Test Exception");
}catch(\Exception $exc){
    $logger
    ->setException($exc)
    ->publish();
}

try{
    throw new \Exception("Test Exception");
}catch(\Exception $exc){
    $logger
    ->setException($exc)
    ->setFacility("PhpMonitoring") //You can override the facility of the exception
    ->setLevel(LoggerConstants::CRITICAL) //You can override the level of the exception
    ->setSingleAdditional("key1", "value1") //You can add other additionals
    ->publish();
}