You are here

class LogFileManager in File Log 8

Same name in this branch
  1. 8 src/LogFileManager.php \Drupal\filelog\LogFileManager
  2. 8 src/ProxyClass/LogFileManager.php \Drupal\filelog\ProxyClass\LogFileManager
Same name and namespace in other branches
  1. 2.0.x src/LogFileManager.php \Drupal\filelog\LogFileManager

Provide file-handling methods for the logfile.

This is a separate service to allow it to be injected into the logger as a proxy and circumvent the circular dependency between logger and file system.

Hierarchy

Expanded class hierarchy of LogFileManager

2 files declare their use of LogFileManager
FileLogRotationTest.php in tests/src/Unit/FileLogRotationTest.php
FileLogTest.php in tests/src/Unit/FileLogTest.php
1 string reference to 'LogFileManager'
filelog.services.yml in ./filelog.services.yml
filelog.services.yml
1 service uses LogFileManager
filelog.file_manager in ./filelog.services.yml
Drupal\filelog\LogFileManager

File

src/LogFileManager.php, line 14

Namespace

Drupal\filelog
View source
class LogFileManager implements LogFileManagerInterface {
  public const FILENAME = 'drupal.log';

  /**
   * The filelog settings.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * The file system service.
   *
   * @var \Drupal\Core\File\FileSystemInterface
   */
  protected $fileSystem;

  /**
   * LogFileManager constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The config_factory service.
   * @param \Drupal\Core\File\FileSystemInterface $fileSystem
   *   The file_system service.
   */
  public function __construct(ConfigFactoryInterface $configFactory, FileSystemInterface $fileSystem) {
    $this->config = $configFactory
      ->get('filelog.settings');
    $this->fileSystem = $fileSystem;
  }

  /**
   * {@inheritdoc}
   */
  public function getFileName() : string {
    return $this->config
      ->get('location') . '/' . static::FILENAME;
  }

  /**
   * {@inheritdoc}
   */
  public function ensurePath() : bool {
    $path = $this->config
      ->get('location');
    return $this->fileSystem
      ->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LogFileManager::$config protected property The filelog settings.
LogFileManager::$fileSystem protected property The file system service.
LogFileManager::ensurePath public function Ensure that the log directory exists. Overrides LogFileManagerInterface::ensurePath
LogFileManager::FILENAME public constant
LogFileManager::getFileName public function Get the complete filename of the log. Overrides LogFileManagerInterface::getFileName
LogFileManager::__construct public function LogFileManager constructor.