From 058a32533bc2faee5e871dafe52cbebe202ad605 Mon Sep 17 00:00:00 2001 From: Nils Blume Date: Thu, 31 Aug 2023 09:49:17 +0200 Subject: [PATCH] if log=false don't require logfile --- src/Config.php | 10 +++++++++- src/Handler.php | 22 +++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Config.php b/src/Config.php index f819f8e..cb6d9fa 100644 --- a/src/Config.php +++ b/src/Config.php @@ -113,7 +113,15 @@ final class Config $this->isAllowNetcupCreds() ) ) && - !empty($this->logFile); + ( + ( + $this->isLog() && + !empty($this->logFile) + ) || + ( + $this->isLog() == false + ) + ); } /** diff --git a/src/Handler.php b/src/Handler.php index c3fde67..5c1230f 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -92,10 +92,12 @@ final class Handler $this->apipassword = $this->config->getApiPassword(); } - if (is_readable($this->config->getLogFile())) { - $this->log = json_decode(file_get_contents($this->config->getLogFile()), true); - } else { - $this->log[$this->payload->getDomain()] = []; + if ($this->config->isLog()) { + if (is_readable($this->config->getLogFile())) { + $this->log = json_decode(file_get_contents($this->config->getLogFile()), true); + } else { + $this->log[$this->payload->getDomain()] = []; + } } } @@ -111,13 +113,15 @@ final class Handler */ private function doLog($msg) { - $this->log[$this->payload->getDomain()][] = sprintf('[%s] %s', date('c'), $msg); + if ($this->config->isLog()) { + $this->log[$this->payload->getDomain()][] = sprintf('[%s] %s', date('c'), $msg); - if ($this->config->isDebug()) { - printf('[DEBUG] %s %s', $msg, PHP_EOL); + if ($this->config->isDebug()) { + printf('[DEBUG] %s %s', $msg, PHP_EOL); + } + + return $this; } - - return $this; } private function doExit()