fei / audit-client
审计客户端
v2.0.5
2018-07-06 13:14 UTC
Requires
- php: ^7.0
- fei/api-client: ^1.1.0
- fei/audit-common: ^1.0.1
Requires (Dev)
- codeception/codeception: ^2.2
- fzaninotto/faker: ^1.6
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-09-19 11:24:14 UTC
README
安装
只需将以下需求添加到您的 composer.json
文件中
"fei/audit-client": "^1.2.0"
配置
审计事件客户端需要一些选项才能正常工作。可以通过 __construct()
或 setOptions()
方法传递给这些选项,包括
注意:审计是Fei\Service\AuditEvent\Client\Audit的别名 审计事件是Fei\Service\Audit\Entity\AuditEvent的别名
用法
初始化
审计客户端应始终通过依赖注入组件初始化,因为它至少需要一个依赖项,即传输。此外,BASEURL参数也应该依赖于环境。
// sample configuration for production environment $audit = new Audit(array( Audit::OPTION_BASEURL => 'http://audit.flash-global.net', Audit::OPTION_FILTER => AuditEvent::LVL_DEBUG, ) ); // inject transport classes $audit->setTransport(new BasicTransport()); // optionnal asynchronous transport, that will be automatically used to push notifications // // NOTE this transport requires a beanstalk queue able to listen to its requests $pheanstalk = new Pheanstalk('localhost'); $asyncTransport = new BeanstalkProxyTransport; $asyncTransport->setPheanstalk($pheanstalk); $audit->setAsyncTransport($asyncTransport);
推送简单通知
一旦设置了审计,您可以通过在Audit上调用 notify()
方法开始推送通知
$audit = $container->get('audit.client'); $audit->notify('AuditEvent message'); // default level is AuditEvent::LVL_INFO $audit->notify('Debug message', array('level' => AuditEvent::LVL_DEBUG));
虽然可以使用第二个(数组)参数传递除了级别之外的内容,但建议不要这样做。如果您想传递更多信息,如上下文,请参阅以下部分。
推送AuditEvent实例
推送通知更可靠的方法是自行实例化,然后通过 notify()
发送,该方法也接受AuditEvent实例
$audit = $container->get('audit.client'); $auditEvent = new AuditEvent(array('message' => 'AuditEvent message')); $auditEvent ->setLevel(AuditEvent::LVL_WARNING) ->setContext(array('key' => 'value') ; $audit->notify($auditEvent);