From 6984e737b706c73baaa5c3c921762706f958d4da Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Tue, 21 Apr 2020 11:31:27 +0200 Subject: feat: Logger throws Exceptions instead of die added FilesTests for future files related tests --- app/class/Logger.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/class/Logger.php b/app/class/Logger.php index 939dbf8..5d2695c 100644 --- a/app/class/Logger.php +++ b/app/class/Logger.php @@ -2,6 +2,7 @@ namespace Wcms; +use InvalidArgumentException; use Throwable; /** @@ -10,7 +11,7 @@ use Throwable; */ class Logger { - private static $file = null; + private static $file = false; private static $verbosity = 4; /** @@ -21,7 +22,18 @@ class Logger */ public static function init(string $path, int $verbosity = 4) { - self::$file = fopen($path, "a") or die("Unable to open log file!"); + if (!is_dir(dirname($path))) { + throw new InvalidArgumentException("Parent directory of '$path' does not exist."); + } + if (!is_writable(dirname($path))) { + throw new InvalidArgumentException("Parent directory of '$path' is not writable."); + } + if (is_file($path) && !is_writable($path)) { + throw new InvalidArgumentException("The logfile '$path' is not writable."); + } + self::$file = fopen($path, "a"); + if (self::$file === false) { + } self::$verbosity = $verbosity; } -- cgit v1.2.3