/**
* Method to initialise the log file. This will create the folder path to the file if it doesn't already
* exist and also get a new file header if the file doesn't already exist. If the file already exists it
* will simply open it for writing.
*
* @return void
*
* @since 1.7.0
* @throws \RuntimeException
*/
protected function initFile()
{
// We only need to make sure the file exists
if (File::exists($this->path)) {
return;
}
// Make sure the folder exists in which to create the log file.
Folder::create(\dirname($this->path));
// Build the log file header.
$head = $this->generateFileHeader();
if (!File::write($this->path, $head)) {
throw new \RuntimeException('Cannot write to log file.');
}
}