Neos\Flow\Log\Backend\FileBackend::open PHP Метод

open() публичный Метод

Carries out all actions necessary to prepare the logging backend, such as opening the log file or opening a database connection.
public open ( ) : void
Результат void
    public function open()
    {
        $this->severityLabels = [LOG_EMERG => 'EMERGENCY', LOG_ALERT => 'ALERT    ', LOG_CRIT => 'CRITICAL ', LOG_ERR => 'ERROR    ', LOG_WARNING => 'WARNING  ', LOG_NOTICE => 'NOTICE   ', LOG_INFO => 'INFO     ', LOG_DEBUG => 'DEBUG    '];
        if (file_exists($this->logFileUrl) && $this->maximumLogFileSize > 0 && filesize($this->logFileUrl) > $this->maximumLogFileSize) {
            $this->rotateLogFile();
        }
        if (file_exists($this->logFileUrl)) {
            $this->fileHandle = fopen($this->logFileUrl, 'ab');
        } else {
            $logPath = dirname($this->logFileUrl);
            if (!file_exists($logPath) || !is_dir($logPath) && !is_link($logPath)) {
                if ($this->createParentDirectories === false) {
                    throw new CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access because the parent directory does not exist.', 1243931200);
                }
                Files::createDirectoryRecursively($logPath);
            }
            $this->fileHandle = fopen($this->logFileUrl, 'ab');
            if ($this->fileHandle === false) {
                throw new CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1243588980);
            }
            $streamMeta = stream_get_meta_data($this->fileHandle);
            if ($streamMeta['wrapper_type'] === 'plainfile') {
                fclose($this->fileHandle);
                chmod($this->logFileUrl, 0666);
                $this->fileHandle = fopen($this->logFileUrl, 'ab');
            }
        }
        if ($this->fileHandle === false) {
            throw new CouldNotOpenResourceException('Could not open log file "' . $this->logFileUrl . '" for write access.', 1229448440);
        }
    }

Usage Example

 /**
  * @test
  */
 public function appendIgnoresMessagesAboveTheSeverityThreshold()
 {
     $logFileUrl = vfsStream::url('testDirectory') . '/test.log';
     $backend = new FileBackend(['logFileUrl' => $logFileUrl]);
     $backend->setSeverityThreshold(LOG_EMERG);
     $backend->open();
     $backend->append('foo', LOG_INFO);
     $this->assertSame(0, vfsStreamWrapper::getRoot()->getChild('test.log')->size());
 }