reworked debugger as helper class
This commit is contained in:
parent
9da93a73d9
commit
3e3bb02ef5
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace local_treestudyplan;
|
||||
|
||||
class debug {
|
||||
|
||||
public static function dump($tag,$object)
|
||||
{
|
||||
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".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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
50
classes/local/helpers/debugger.php
Normal file
50
classes/local/helpers/debugger.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace local_treestudyplan;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class debugger {
|
||||
|
||||
private $fname;
|
||||
private $tag;
|
||||
private $enabled = false;
|
||||
|
||||
public function __construct($filename,$tag)
|
||||
{
|
||||
global $CFG;
|
||||
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user