You are here

class AuditLogStorage in Audit Log 8

Same name and namespace in other branches
  1. 8.2 src/AuditLogStorage.php \Drupal\audit_log\AuditLogStorage

Writes audit log events to enabled logging destinations.

@package Drupal\audit_log

Hierarchy

Expanded class hierarchy of AuditLogStorage

1 string reference to 'AuditLogStorage'
audit_log.services.yml in ./audit_log.services.yml
audit_log.services.yml
1 service uses AuditLogStorage
audit_log.storage in ./audit_log.services.yml
Drupal\audit_log\AuditLogStorage

File

src/AuditLogStorage.php, line 12

Namespace

Drupal\audit_log
View source
class AuditLogStorage {

  /**
   * An array of available log destinations to be written to.
   *
   * @var array
   */
  protected $storage_backends;

  /**
   * Writes the audit event to each available logging destination.
   *
   * @param \Drupal\audit_log\AuditLogEventInterface $event
   *   The audit event to be logged.
   */
  public function save(AuditLogEventInterface $event) {
    foreach ($this
      ->sortStorageBackends() as $storage_backend) {
      $storage_backend
        ->save($event);
    }
  }

  /**
   * Adds a log destination to the processing pipeline.
   *
   * @param \Drupal\audit_log\StorageBackend\StorageBackendInterface $storage_backend
   *   The logging destination to write events to.
   * @param int $priority
   *   A priority specification for the storage backend s.
   *
   *   Must be a positive integer.
   *
   *   Lower number storage backend s are processed
   *   before higher number storage backend s.
   */
  public function addStorageBackend(StorageBackendInterface $storage_backend, $priority = 0) {
    $this->storage_backends[$priority][] = $storage_backend;
  }

  /**
   * Sorts the available logging destinations by priority.
   *
   * @return array
   *   The sorted array of logging destinations.
   */
  protected function sortStorageBackends() {
    $sorted = [];
    krsort($this->storage_backends);
    foreach ($this->storage_backends as $storage_backends) {
      $sorted = array_merge($sorted, $storage_backends);
    }
    return $sorted;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuditLogStorage::$storage_backends protected property An array of available log destinations to be written to.
AuditLogStorage::addStorageBackend public function Adds a log destination to the processing pipeline.
AuditLogStorage::save public function Writes the audit event to each available logging destination.
AuditLogStorage::sortStorageBackends protected function Sorts the available logging destinations by priority.