_logfilename = $logfilename; } $this->_logfile = fopen($this->_logfilename,'a'); } public function __destruct() { fclose($this->_logfile); } public function setDebugLevel($debuglvl) { $this->_debuglvl = $debuglvl; } public function add($msg) {//{{{ $this->_messages[] = $msg; switch ($this->_debuglvl) { case DEBUG_NONE: break; case DEBUG_EXIT: case DEBUG_PUBLIC: $this->printAll(); case DEBUG_LOG: $this->writeLog($msg); } if ($this->_debuglvl == DEBUG_EXIT) { exit; } }//}}} public function printAll() { if ($this->toDisplay()) { foreach ($this->_messages as $m) { print('*** '.$m."\n"); } $this->clear(); } } public function toDisplay() { return (count($this->_messages) > 0); } public function clear() { $this->_messages = array(); } private function writeLog($msg) { fwrite($this->_logfile,$msg."\n"); } } ?>