aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2020-04-21 11:31:27 +0200
committerVincent Peugnet <33429034+vincent-peugnet@users.noreply.github.com>2020-04-21 14:56:53 +0200
commit6984e737b706c73baaa5c3c921762706f958d4da (patch)
tree20858ee13c9b5e8cfffae2090904e051b2f874b7 /app
parent3355532be69a1c11a0637b1dfc994748b5de558f (diff)
downloadwcms-6984e737b706c73baaa5c3c921762706f958d4da.tar.gz
wcms-6984e737b706c73baaa5c3c921762706f958d4da.zip
feat: Logger throws Exceptions instead of die
added FilesTests for future files related tests
Diffstat (limited to 'app')
-rw-r--r--app/class/Logger.php16
1 files changed, 14 insertions, 2 deletions
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;
}