Add date and time for logging. #330

This commit is contained in:
Korina Cordero 2020-02-28 03:21:29 +00:00
parent 8b96855395
commit 4c27b4da06
2 changed files with 12 additions and 3 deletions

View file

@ -5,6 +5,8 @@ namespace App\EventListener;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use DateTime;
abstract class EntityListener
{
@ -15,6 +17,9 @@ abstract class EntityListener
public function onFlush(OnFlushEventArgs $args)
{
$event_time = new DateTime();
$log_time = $event_time->format('Y-m-d H:i:s');
$em = $args->getEntityManager();
$unit_of_work = $em->getUnitOfWork();
$deleted_entities = $unit_of_work->getScheduledEntityDeletions();
@ -34,7 +39,7 @@ abstract class EntityListener
$old_value = $values[0];
$new_value = $values[1];
error_log('Changed ' . $field . ' from ' . $old_value . ' to ' . $new_value);
error_log($log_time . ' - Changed ' . $field . ' from ' . $old_value . ' to ' . $new_value);
}
}
@ -42,7 +47,7 @@ abstract class EntityListener
{
$deleted_id = $deleted_entity->getID();
error_log('Deleted object with id ' . $deleted_id);
error_log($log_time . ' - Deleted object with id ' . $deleted_id);
}
}

View file

@ -11,11 +11,15 @@ use App\Entity\User;
use App\Entity\Role;
use App\Entity\Hub;
use DateTime;
class UserEntityListener extends EntityListener
{
public function postPersist($user, LifecycleEventArgs $args)
{
error_log('Created user with id ' . $user->getID() . ' and username ' . $user->getUsername());
$event_time = new DateTime();
$log_time = $event_time->format('Y-m-d H:i:s');
error_log($log_time . ' - Created user with id ' . $user->getID() . ' and username ' . $user->getUsername());
}
//public function onFlush(OnFlushEventArgs $args)