From 3e3bb02ef5cdfed0fb8e0d7c0f9ec121ec0f3010 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Mon, 26 Jun 2023 12:59:15 +0200 Subject: [PATCH] reworked debugger as helper class --- classes/debug.php | 30 ------------------ classes/local/helpers/debugger.php | 50 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 30 deletions(-) delete mode 100644 classes/debug.php create mode 100644 classes/local/helpers/debugger.php diff --git a/classes/debug.php b/classes/debug.php deleted file mode 100644 index 142257f..0000000 --- a/classes/debug.php +++ /dev/null @@ -1,30 +0,0 @@ -cachejs) && $CFG->cachejs == false){ - $f = fopen("/tmp/log.txt","a"); - fwrite($f,$tag . ":\n".print_r($object,true)."\n"); - fclose($f); - - } - } - public static function msg($tag,$str) - { - global $CFG; - // assume debug environment if cachejs is false - if(isset($CFG->cachejs) && $CFG->cachejs == false){ - $f = fopen("/tmp/log.txt","a"); - fwrite($f,$tag . ":\n".$str."\n"); - fclose($f); - - } - } - -} \ No newline at end of file diff --git a/classes/local/helpers/debugger.php b/classes/local/helpers/debugger.php new file mode 100644 index 0000000..6736a55 --- /dev/null +++ b/classes/local/helpers/debugger.php @@ -0,0 +1,50 @@ +fname = $filename; + $this->tag = $tag; + + // assume debug environment if cachejs is false + $this->enabled = (isset($CFG->cachejs) && $CFG->cachejs == false); + + } + + public function dump($object) + { + global $CFG; + $this->writeblock(print_r($object,true)); + + } + + public function write($str) + { + $this->writeblock($str); + } + + private function writeblock($str){ + if($this->enabled){ + $now = new DateTime(); + + $tagline = "[ {$this->tag} - ".$now->format("c")." ]"; + + $fp = fopen($this->fname,"a"); + fwrite($fp,$tagline . ":\n".$str."\n"); + fclose($fp); + } + } + + +} \ No newline at end of file