summaryrefslogtreecommitdiff
path: root/framework/Util
diff options
context:
space:
mode:
authorgodzilla80@gmx.net <>2009-05-18 23:52:33 +0000
committergodzilla80@gmx.net <>2009-05-18 23:52:33 +0000
commita0b494e3887875b2f5cf235ca0214a317b353e81 (patch)
treef3acefd1d3abf10128b20cc6496a15c7b1522872 /framework/Util
parentd61bcbaa167fefb93034e4986113f09c29943d4f (diff)
ENH: new log route subclass for FirePHP: TFirePhpLogRoute - FirePHP is ideally suited for AJAX development where clean JSON and XML responses are required
Diffstat (limited to 'framework/Util')
-rw-r--r--framework/Util/TLogRouter.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/framework/Util/TLogRouter.php b/framework/Util/TLogRouter.php
index d37c6896..79035a7a 100644
--- a/framework/Util/TLogRouter.php
+++ b/framework/Util/TLogRouter.php
@@ -988,4 +988,78 @@ EOD;
}
}
+
+/**
+ * TFirePhpLogRoute class.
+ *
+ * TFirePhpLogRoute prints log messages in the firebug log console via firephp.
+ *
+ * {@link http://www.getfirebug.com/ FireBug Website}
+ * {@link http://www.firephp.org/ FirePHP Website}
+ *
+ * @author Yves Berkholz <godzilla80[at]gmx[dot]net>
+ * @version $Id$
+ * @package System.Util
+ * @since 3.1.5
+ */
+class TFirePhpLogRoute extends TLogRoute
+{
+ public function processLogs($logs)
+ {
+ if(empty($logs) || $this->getApplication()->getMode()==='Performance') return;
+
+ require_once Prado::getPathOfNamespace('System.3rdParty.FirePHPCore') . '/FirePHP.class.php';
+ $firephp = FirePHP::getInstance(true);
+ $firephp -> setOptions(array('useNativeJsonEncode' => false));
+
+ $firephp -> group('System.Util.TLogRouter(TFirePhpLogRoute)', array('Collapsed' => true));
+
+ $firephp ->log('Time, Message');
+
+ $first = $logs[0][3];
+ $c = count($logs);
+ for($i=0,$n=$c;$i<$n;++$i)
+ {
+ $message = $logs[$i][0];
+ $level = $logs[$i][1];
+ $category = $logs[$i][2];
+
+ if ($i<$n-1)
+ {
+ $delta = $logs[$i+1][3] - $logs[$i][3];
+ $total = $logs[$i+1][3] - $first;
+ }
+ else
+ {
+ $delta = '?';
+ $total = $logs[$i][3] - $first;
+ }
+
+ $message = sPrintF('+%0.6f: %s', $delta, preg_replace('/\(line[^\)]+\)$/','',$message));
+ $firephp ->fb($message, $category, self::translateLogLevel($level));
+ }
+ $firephp ->log( sPrintF('%0.6f', $total), 'Cumulated Time');
+ $firephp -> groupEnd();
+ }
+
+ protected static function translateLogLevel($level)
+ {
+ switch($level)
+ {
+ case TLogger::INFO:
+ return FirePHP::INFO;
+ case TLogger::DEBUG:
+ case TLogger::NOTICE:
+ return FirePHP::LOG;
+ case TLogger::WARNING:
+ return FirePHP::WARN;
+ case TLogger::ERROR:
+ case TLogger::ALERT:
+ case TLogger::FATAL:
+ return FirePHP::ERROR;
+ }
+ return FirePHP::LOG;
+ }
+}
+
?>