/** * Gets the plugin data that should be rendered on the output protocol stream. * * @param Glimpse $glimpse The current Glimpse instance. * @return array Array conforming to the Glimpse protocol definition. */ public function getData(Glimpse $glimpse) { $data = array(array('Message', 'Category', 'From First', 'From Last')); $traceData = Glimpse_Trace::retrieveMessages(); foreach ($traceData as $traceEntry) { $traceEntry[] = strtolower($traceEntry[1]); $data[] = $traceEntry; } return array("Trace" => count($data) > 0 ? $data : null); }
/** * Logs a message to the trace log. * * @param string $category Category to log (Info, Warn, Error, Fail). * @param string $message Message to log. */ public static function log($category = 'Info', $message = '') { // Timing $timeFromFirst = 0; $timeFromLast = 0; if (self::$_timingFirst == 0) { self::$_timingFirst = microtime(true); self::$_timingLast = self::$_timingFirst; } else { $timeFromFirst = (microtime(true) - self::$_timingFirst) * 1000; $timeFromLast = (microtime(true) - self::$_timingLast) * 1000; } // Log self::$_messages[] = array($message, $category, number_format($timeFromFirst, 2) . ' ms', number_format($timeFromLast, 2) . ' ms'); // Timing self::$_timingLast = microtime(true); }
<?php require_once '../source/index.php'; //'phar://../build/Glimpse.phar'; ?> <html> <head> <title>Hello world!</title> </head> <?php Glimpse_Trace::info('Rendering body...'); ?> <body> <h1>Hello world!</h1> <p>This is just a test.</p> </body> <?php Glimpse_Trace::info('Rendered body.'); ?> </html>