schema31/php-monitoring

There is no license information available for the latest version (0.0.1) of this package.

0.0.1 2020-09-08 13:32 UTC

This package is auto-updated.

Last update: 2024-10-08 23:25:19 UTC


README

======

Packagist

Logger class for PHP. It require the Schema31/php-gcloud-monitoring-sdk

Install

You can install the library using composer:

$ composer require schema31/php-monitoring

How to use

Configurations

Internal configuration

You can pass the configuration values:

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

...

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

Configuration constants

You can define constants and the library use it automatically:

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

Sending a message

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

Sending an exception

You can send a log based on an exception:

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

Or

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