protected function FileLog::openFile in File Log 8
Same name and namespace in other branches
- 2.0.x src/Logger/FileLog.php \Drupal\filelog\Logger\FileLog::openFile()
Open the logfile for writing.
Return value
bool Returns TRUE if the log file is available for writing.
Throws
\Drupal\filelog\FileLogException
1 call to FileLog::openFile()
- FileLog::log in src/
Logger/ FileLog.php - Logs with an arbitrary level.
File
- src/
Logger/ FileLog.php, line 125
Class
- FileLog
- File-based logger.
Namespace
Drupal\filelog\LoggerCode
protected function openFile() : bool {
if ($this->logFile) {
return TRUE;
}
// When creating a new log file, save the creation timestamp.
$filename = $this->fileManager
->getFileName();
$create = !file_exists($filename);
if (!$this->fileManager
->ensurePath()) {
$this->logFile = $this
->stderr();
throw new FileLogException('The log directory has disappeared.');
}
if ($this->logFile = fopen($filename, 'ab')) {
if ($create) {
$this->state
->set('filelog.rotation', $this->time
->getRequestTime());
}
return TRUE;
}
// Log errors to STDERR until the end of the current request.
$this->logFile = $this
->stderr();
throw new FileLogException('The logfile could not be opened for writing. Logging to STDERR.');
}