Use InfluxDB for logging. #330
This commit is contained in:
parent
f46c56c41e
commit
b2154e28b8
6 changed files with 91 additions and 33 deletions
|
|
@ -14,6 +14,7 @@
|
|||
"data-dog/audit-bundle": "^0.1.10",
|
||||
"edwinhoksberg/php-fcm": "^1.0",
|
||||
"guzzlehttp/guzzle": "^6.3",
|
||||
"influxdb/influxdb-php": "^1.15",
|
||||
"predis/predis": "^1.1",
|
||||
"sensio/framework-extra-bundle": "^5.1",
|
||||
"setasign/fpdf": "^1.8",
|
||||
|
|
|
|||
65
composer.lock
generated
65
composer.lock
generated
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b101ecfbc1f6f2270f0e8ad326035b7e",
|
||||
"content-hash": "cbde0e7f1fa49277c6196a3c677c3a51",
|
||||
"packages": [
|
||||
{
|
||||
"name": "catalyst/auth-bundle",
|
||||
|
|
@ -1836,6 +1836,67 @@
|
|||
],
|
||||
"time": "2019-07-01T23:21:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "influxdb/influxdb-php",
|
||||
"version": "1.15.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/influxdata/influxdb-php.git",
|
||||
"reference": "bf3415f81962e1ab8c939bc1a08a85f500bead35"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/influxdata/influxdb-php/zipball/bf3415f81962e1ab8c939bc1a08a85f500bead35",
|
||||
"reference": "bf3415f81962e1ab8c939bc1a08a85f500bead35",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^6.0",
|
||||
"php": "^5.5 || ^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Curl extension, needed for Curl driver",
|
||||
"stefanotorresi/influxdb-php-async": "An asyncronous client for InfluxDB, implemented via ReactPHP."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"InfluxDB\\": "src/InfluxDB"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gianluca Arbezzano",
|
||||
"email": "gianarb92@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Daniel Martinez",
|
||||
"email": "danimartcas@hotmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Stephen Hoogendijk",
|
||||
"email": "stephen@tca0.nl"
|
||||
}
|
||||
],
|
||||
"description": "InfluxDB client library for PHP",
|
||||
"keywords": [
|
||||
"client",
|
||||
"influxdata",
|
||||
"influxdb",
|
||||
"influxdb class",
|
||||
"influxdb client",
|
||||
"influxdb library",
|
||||
"time series"
|
||||
],
|
||||
"time": "2019-05-30T00:15:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jdorn/sql-formatter",
|
||||
"version": "v1.2.17",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,14 @@ services:
|
|||
public: false # Allows optimizing the container by removing unused services; this also means
|
||||
# fetching services directly from the container via $container->get() won't work.
|
||||
# The best practice is to be explicit about your dependencies anyway.
|
||||
|
||||
# influxdb
|
||||
influxdb_client:
|
||||
class: InfluxDB\Client
|
||||
arguments: ['%env(INFLUXDB_HOST)%', '%env(INFLUXDB_PORT)%']
|
||||
influxdb_database:
|
||||
class: InfluxDB\Database
|
||||
arguments: ['%env(INFLUXDB_DB)%', '@influxdb_client']
|
||||
|
||||
# makes classes in src/ available to be used as services
|
||||
# this creates a service per class whose id is the fully-qualified class name
|
||||
|
|
@ -262,7 +270,7 @@ services:
|
|||
App\EventListener\EntityListener\UserEntityListener:
|
||||
arguments:
|
||||
$token_storage: "@security.token_storage"
|
||||
$log_em: "@doctrine.orm.logging_entity_manager"
|
||||
$log_db: '@influxdb_database'
|
||||
tags:
|
||||
- name: 'doctrine.event_listener'
|
||||
event: 'onFlush'
|
||||
|
|
|
|||
|
|
@ -2,25 +2,24 @@
|
|||
|
||||
namespace App\EventListener;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Event\OnFlushEventArgs;
|
||||
|
||||
use App\Entity\Logging\EntityLog;
|
||||
use InfluxDB\Point;
|
||||
|
||||
use DateTime;
|
||||
|
||||
abstract class EntityListener
|
||||
{
|
||||
protected $token_storage;
|
||||
protected $log_em;
|
||||
protected $log_db;
|
||||
|
||||
public function __construct(TokenStorage $token_storage, EntityManagerInterface $log_em)
|
||||
public function __construct(TokenStorageInterface $token_storage, $log_db)
|
||||
{
|
||||
$this->token_storage = $token_storage;
|
||||
$this->log_em = $log_em;
|
||||
$this->log_db = $log_db;
|
||||
}
|
||||
|
||||
public function onFlush(OnFlushEventArgs $args)
|
||||
|
|
@ -34,10 +33,6 @@ abstract class EntityListener
|
|||
$user = $this->token_storage->getToken()->getUser();
|
||||
$username = $user->getUsername();
|
||||
|
||||
$entity_log = new EntityLog();
|
||||
$entity_log->setUser($username)
|
||||
->setDateAction($event_time);
|
||||
|
||||
$field_changes = [];
|
||||
|
||||
$unit_of_work = $em->getUnitOfWork();
|
||||
|
|
@ -51,9 +46,6 @@ abstract class EntityListener
|
|||
foreach ($created_entities as $created_entity)
|
||||
{
|
||||
$log_message = 'Object with id ' . $created_entity->getID() . ' created.';
|
||||
|
||||
$entity_log->setAction('Create')
|
||||
->addChange('Object', $log_message);
|
||||
}
|
||||
|
||||
// get updated fields. This doesn't include lists of other entities.
|
||||
|
|
@ -74,12 +66,6 @@ abstract class EntityListener
|
|||
'new_value' => $values[1],
|
||||
];
|
||||
}
|
||||
|
||||
$entity_log->setAction('Update');
|
||||
if ($updated_entity instanceof User)
|
||||
{
|
||||
$entity_log->addChange('User', $field_changes);
|
||||
}
|
||||
}
|
||||
|
||||
// get deleted objects
|
||||
|
|
@ -87,12 +73,13 @@ abstract class EntityListener
|
|||
{
|
||||
$deleted_id = $deleted_entity->getID();
|
||||
$log_message = 'Object with id ' . $deleted_id . ' deleted.';
|
||||
|
||||
$entity_log->setAction('Delete')
|
||||
->addChange('Object', $log_message);
|
||||
}
|
||||
|
||||
$this->log_em->persist($entity_log);
|
||||
$this->log_db->writePoints([new Point(
|
||||
'User',
|
||||
'Action',
|
||||
['status' => 'success']
|
||||
)]);
|
||||
|
||||
// TODO: find a way to get the list of "old" items, compare with list of updated items
|
||||
// so we can find out what was added/removed
|
||||
|
|
|
|||
|
|
@ -2,23 +2,21 @@
|
|||
|
||||
namespace App\EventListener\EntityListener;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
use App\EventListener\EntityListener;
|
||||
|
||||
class UserEntityListener extends EntityListener
|
||||
{
|
||||
protected $token_storage;
|
||||
protected $log_em;
|
||||
protected $log_db;
|
||||
|
||||
public function __construct(TokenStorage $token_storage, EntityManagerInterface $log_em)
|
||||
public function __construct(TokenStorageInterface $token_storage, $log_db)
|
||||
{
|
||||
$this->token_storage = $token_storage;
|
||||
$this->log_em = $log_em;
|
||||
$this->log_db = $log_db;
|
||||
|
||||
parent::__construct($token_storage, $log_em);
|
||||
parent::__construct($token_storage, $log_db);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,9 @@
|
|||
"guzzlehttp/psr7": {
|
||||
"version": "1.4.2"
|
||||
},
|
||||
"influxdb/influxdb-php": {
|
||||
"version": "1.15.0"
|
||||
},
|
||||
"jdorn/sql-formatter": {
|
||||
"version": "v1.2.17"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue