log = ezcLog::getInstance(); // Set the writer. $this->writer = new ezcDebugMemoryWriter(); $filter = new ezcLogFilter(); $filter->severity = ezcLog::DEBUG; $this->log->attach( $filter, $this->writer ); $this->reset(); } public function reset() { $this->writer->reset(); $this->timer = new ezcDebugTimer(); } /** * Returns the instance of the class. * * @returns Instance of this class. */ public static function getInstance() { if ( is_null( ezcDebug::$instance )) { ezcDebug::$instance = new ezcDebug(); } return ezcDebug::$instance; } /** * Set the formatter for the output. * * The HTML formatter is set by default. */ public function setReporter( $reporter ) { $this->reporter = $reporter; } /** * Get the formatted output. */ public function getOutput() { if ( is_null( $this->reporter ) ) $this->reporter = new ezcDebugHtmlReporter(); return $this->reporter->getOutput( $this->writer->getStructure(), $this->timer->getStructure() ); } /** * Starts the timer. * * @param string name Name of the timer. * @param string source Source of the timer. * @param string group Group or category. To which group belongs the * timer. * @return void */ public function startTimer( $name, $source, $group ) { $this->timer->startTimer( $name, $source, $group ); } /** * Stores the time from the running timer, and starts a new timer. * * @param string $newName Name of the new timer. * @param string $oldName The previous timer that must be stopped. * Only needed when multiple timers are running. */ public function switchTimer( $newName, $oldName = false ) { $this->timer->switchTimer( $newName, $oldName ); } /** * Stop the timer * * @param $name Need to supply a name only when multiple timers are running. */ public function stopTimer( $name = false ) { $this->timer->stopTimer( $name ); } /** * Forward the messages to the log. * */ public function log( $message, $verbosity, array $extraInfo = array() ) { // Add the verbosity $extraInfo = array_merge( array( "verbosity" => $verbosity ), $extraInfo ); return $this->log->log( $message, ezcLog::DEBUG, $extraInfo ); } /** * Dispatches the message and error type to the correct debug or log * function. * * This function should be used as the set_error_handler from the * trigger_error function. * * Use for example the following code in your application: * * * function debugHandler( $a, $b, $c, $d ) * { * ezcDebug::debugHandler( $a, $b, $c, $d ); * } * * set_error_handler( "debugHandler" ); * * * Use trigger_error to log warning, error, etc: * * * trigger_error( "[Paynet, templates] Cannot load template", E_USER_WARNING ); * */ public static function debugHandler( $errno, $errstr, $errfile, $errline ) { $log = ezcLog::getInstance(); $debug = ezcDebug::getInstance(); $lm = new ezcDebugMessage( $errstr, $errno, $log->source, $log->category ); $debug->log( $lm->message, $lm->severity, array( "source" => $lm->source, "category" => $lm->category, "verbosity" => $lm->verbosity, "file" => $errfile, "line" => $errline ) ); } public static function getVerbosityName( $verbosity ) { switch ( $verbosity ) { case ezcDebug::NOTICE: return "Notice"; case ezcDebug::WARNING: return "Warning"; case ezcDebug::ERROR: return "Error"; default: return "Unknown"; } } } ?>