schema31 / php-monitoring
此包的最新版本(0.0.1)没有提供许可证信息。
0.0.1
2020-09-08 13:32 UTC
Requires
This package is auto-updated.
Last update: 2024-09-08 23:06:43 UTC
README
======
PHP的日志类。它需要 Schema31/php-gcloud-monitoring-sdk
安装
您可以使用 composer 安装库
$ composer require schema31/php-monitoring
如何使用
配置
内部配置
您可以将配置值传递
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(); }