function EventLogSubscriber::logEventInfo
Logs all events in the stage life cycle.
Parameters
\Drupal\package_manager\Event\StageEvent $event: The event object.
File
-
core/
modules/ package_manager/ tests/ modules/ package_manager_test_event_logger/ src/ EventSubscriber/ EventLogSubscriber.php, line 46
Class
- EventLogSubscriber
- Defines an event subscriber to test logging during events in Package Manager.
Namespace
Drupal\package_manager_test_event_logger\EventSubscriberCode
public function logEventInfo(StageEvent $event) : void {
$log_file = \Drupal::service(PathLocator::class)->getProjectRoot() . '/' . self::LOG_FILE_NAME;
if (file_exists($log_file)) {
$log_data = file_get_contents($log_file);
$log_data = json_decode($log_data, TRUE, flags: JSON_THROW_ON_ERROR);
}
else {
$log_data = [];
}
$log_data[] = [
'event' => $event::class,
'stage' => $event->stage::class,
];
file_put_contents($log_file, json_encode($log_data, JSON_UNESCAPED_SLASHES));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.