summaryrefslogtreecommitdiff
path: root/src/Drivers
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nth.ee>2024-11-15 16:48:41 +0200
committerAsko Nõmm <asko@nth.ee>2024-11-15 16:48:41 +0200
commit88ee33c51b9696eb9c4b31afeae9487b21c0565f (patch)
treeca776922d74e8203cb6a5a97747b005581e74f25 /src/Drivers
parentc69944457919ddf133da7573fe9aa41246f98957 (diff)
Create file and path if it does not exist.
Diffstat (limited to 'src/Drivers')
-rw-r--r--src/Drivers/FileSystemDriver.php24
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