diff options
| author | Asko Nõmm <asko@nth.ee> | 2024-11-15 16:48:41 +0200 |
|---|---|---|
| committer | Asko Nõmm <asko@nth.ee> | 2024-11-15 16:48:41 +0200 |
| commit | 88ee33c51b9696eb9c4b31afeae9487b21c0565f (patch) | |
| tree | ca776922d74e8203cb6a5a97747b005581e74f25 /src | |
| parent | c69944457919ddf133da7573fe9aa41246f98957 (diff) | |
Create file and path if it does not exist.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Drivers/FileSystemDriver.php | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/Drivers/FileSystemDriver.php b/src/Drivers/FileSystemDriver.php index 551b741..292ba63 100644 --- a/src/Drivers/FileSystemDriver.php +++ b/src/Drivers/FileSystemDriver.php @@ -29,27 +29,19 @@ class FileSystemDriver implements Driver $file_name = "{$date->format('Y-m-d')}.log"; $path = $this->directory . DIRECTORY_SEPARATOR . $file_name; - // If the log file does not exist, try creating one - if (!$this->exists($path)) { - throw new \RuntimeException('Log file could not be created at path: ' . $path); - } - - // We managed to get this far, but still can't write to the log file - if (!$this->isWriteable($path)) { - throw new \RuntimeException('Log file is not writeable at path: ' . $path); - } - + $this->createLogFileIfNotExist($path); $this->write($path, $serializedMessage . PHP_EOL); } - public function exists(string $path): bool + public function createLogFileIfNotExist(string $path): void { - return file_exists($path); - } + if (!file_exists($this->directory)) { + mkdir($this->directory, 0600, true); + } - public function isWriteable(string $path): bool - { - return is_writeable($path); + if (is_writable($this->directory)) { + touch($path); + } } public function write(string $path, string $data): void |
