fei / audit-client
Audit client
Installs: 17 634
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 26
Forks: 0
Open Issues: 0
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-11-19 11:43:48 UTC
README
Installation
Just add the following requirement to your composer.json
file:
"fei/audit-client": "^1.2.0"
Configuration
The audit event client needs some options to work properly. The available options that can be passed to the __construct()
or setOptions()
methods are :
Notes: Audit is an alias of Fei\Service\AuditEvent\Client\Audit AuditEvent is an alias of Fei\Service\Audit\Entity\AuditEvent
Usage
Initialization
An Audit client should always be initialized by a dependency injection component, since it requires at least one dependency, which is the transport. Moreover, the BASEURL parameter should also depends on environment.
// 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);
Pushing a simple notification
Once you have set up the Audit, you can start pushing notifications by calling the notify()
method on the Audit:
$audit = $container->get('audit.client'); $audit->notify('AuditEvent message'); // default level is AuditEvent::LVL_INFO $audit->notify('Debug message', array('level' => AuditEvent::LVL_DEBUG));
While its possible to pass more than just the level using the second (array) parameter, it is recommended not to do so. If you want to pass more informations, like a context, please take a look at the following section.
Pushing a AuditEvent instance
The more reliable way to push a notification is to instantiate it by yourself, and then send it through notify()
, that will also accept AuditEvent instances:
$audit = $container->get('audit.client'); $auditEvent = new AuditEvent(array('message' => 'AuditEvent message')); $auditEvent ->setLevel(AuditEvent::LVL_WARNING) ->setContext(array('key' => 'value') ; $audit->notify($auditEvent);