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);
}
}