From aaa5a0dad391527d8f91b7550ff9cd5225a70a4e Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 22 Nov 2021 00:34:12 +0100 Subject: [PATCH] Remove superfluous file stats when setting file logging to true --- src/MDOutputHandler.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/MDOutputHandler.php b/src/MDOutputHandler.php index 3484a7b..ca0ddbf 100644 --- a/src/MDOutputHandler.php +++ b/src/MDOutputHandler.php @@ -30,6 +30,8 @@ final class MDOutputHandler { /** @var string[] */ private array $_log_queue = []; + /** @var boolean */ + private bool $_logfile_status_checked = false; /** * Writes log file contents to log file. @@ -38,7 +40,21 @@ final class MDOutputHandler { */ public function flush_to_logfile():void { + echo "Will flush to log file" . PHP_EOL . PHP_EOL . PHP_EOL; + + if ($this->_logfile_status_checked === false) { + + if (!\is_dir(__DIR__ . "/../logs")) { + \mkdir(__DIR__ . "/../logs", 0775); + } + + \touch($this->_logfile); + $this->_logfile_status_checked = true; + + } + \file_put_contents($this->_logfile, implode(PHP_EOL, $this->_log_queue), FILE_APPEND); + $this->_log_queue = []; } @@ -97,11 +113,6 @@ final class MDOutputHandler { $this->_file_logging = $input; - if ($this->_file_logging === true) { - if (!\is_dir(__DIR__ . "/../logs")) mkdir(__DIR__ . "/../logs", 0775); - \touch($this->_logfile); - } - } /**