fei / logger-package
Objective PHP应用程序的日志客户端包集成
v2.2.0
2020-03-12 10:50 UTC
Requires
- fei/logger-client: ^1.2
- objective-php/application: ^1.1
This package is auto-updated.
Last update: 2024-09-20 08:50:41 UTC
README
本包为Objective PHP应用程序提供日志客户端集成。
安装
Logger Package需要PHP 7.0或更高版本才能正确运行。
您需要使用composer require fei/logger-package
将其集成到Objective PHP项目中。
集成
如下所示,Logger Package必须连接到应用程序初始化方法。
Logger Package创建一个将被应用程序中间件使用的Logger客户端服务。
重要:此包必须在第一步(在此情况下,为bootstrap)连接。
<?php use ObjectivePHP\Application\AbstractApplication; use Fei\Service\Logger\Package\LoggerPackage; class Application extends AbstractApplication { public function init() { // Define some application steps $this->addSteps('bootstrap', 'init', 'auth', 'route', 'rendering'); // Initializations... // Plugging the Logger Package in the bootstrap step $this->getStep('bootstrap') ->plug(LoggerPackage::class); // Another initializations... } }
您可以在其他步骤中运行此包。为此,您只需做类似的事情
<?php use ObjectivePHP\Application\AbstractApplication; use Fei\Service\Logger\Package\LoggerPackage; class Application extends AbstractApplication { public function init() { // Define some application steps $this->addSteps('bootstrap', 'init', 'auth', 'route', 'rendering'); // Initializations... // Plugging the Logger Package in the bootstrap step $this->getStep('bootstrap') ->plug(new LoggerPackage('identifier.service', 'my.step')); // Another initializations... } }
identifier.service
:表示日志的服务名称(默认为logger.client
)my.step
:表示服务将运行的步骤,在此情况下,您可以放置init
、auth
、route
、rendering
(默认为bootstrap
)
应用程序配置
在您的配置目录中创建一个文件,并按照以下方式放置您的Logger配置
<?php use Fei\ApiClient\Config\BasicTransportConfig; use Fei\ApiClient\Config\BeanstalkTransportConfig; use Fei\Service\Logger\Package\Config\LoggerClientConfig; return [ (new LoggerClientConfig('https://logger.test.flash-global.net')) ->setSyncTransportConfig(new BasicTransportConfig()) ->setAsyncTransportConfig(new BeanstalkTransportConfig('beanstalk.default')) ];
在上面的示例中,您需要设置此配置
LoggerClientConfig
:该参数表示API可以联系以发送日志的URLBeanstalkTransportConfig
:表示beanstalk的服务ID
请查阅logger-client
文档以获取有关如何使用此客户端的更多信息。