summaryrefslogtreecommitdiff
path: root/framework/Util/TFirebugLogRoute.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2015-01-20 21:46:23 +0100
committerFabio Bas <ctrlaltca@gmail.com>2015-01-20 21:46:23 +0100
commit001e69daef223679ad2331e61e78f45aec590f0a (patch)
treec26b6fe7cdca1d1749c439046124534fc27bf197 /framework/Util/TFirebugLogRoute.php
parent1729b4bffedbcd0e0bdff80b74aa9944312d817c (diff)
One class per file: framework/Util
Diffstat (limited to 'framework/Util/TFirebugLogRoute.php')
-rw-r--r--framework/Util/TFirebugLogRoute.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/framework/Util/TFirebugLogRoute.php b/framework/Util/TFirebugLogRoute.php
new file mode 100644
index 00000000..4493e6f6
--- /dev/null
+++ b/framework/Util/TFirebugLogRoute.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * TLogRouter, TLogRoute, TFileLogRoute, TEmailLogRoute class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @package System.Util
+ */
+
+/**
+ * TFirebugLogRoute class.
+ *
+ * TFirebugLogRoute prints selected log messages in the firebug log console.
+ *
+ * {@link http://www.getfirebug.com/ FireBug Website}
+ *
+ * @author Enrico Stahn <mail@enricostahn.com>, Christophe Boulain <Christophe.Boulain@gmail.com>
+ * @package System.Util
+ * @since 3.1.2
+ */
+class TFirebugLogRoute extends TBrowserLogRoute
+{
+ protected function renderHeader ()
+ {
+ $string = <<<EOD
+
+<script type="text/javascript">
+/*<![CDATA[*/
+if (typeof(console) == 'object')
+{
+ console.log ("[Cumulated Time] [Time] [Level] [Category] [Message]");
+
+EOD;
+
+ return $string;
+ }
+
+ protected function renderMessage ($log, $info)
+ {
+ $logfunc = $this->getFirebugLoggingFunction($log[1]);
+ $total = sprintf('%0.6f', $info['total']);
+ $delta = sprintf('%0.6f', $info['delta']);
+ $msg = trim($this->formatLogMessage($log[0], $log[1], $log[2], ''));
+ $msg = preg_replace('/\(line[^\)]+\)$/', '', $msg); //remove line number info
+ $msg = "[{$total}] [{$delta}] ".$msg; // Add time spent and cumulated time spent
+ $string = $logfunc . '(\'' . addslashes($msg) . '\');' . "\n";
+
+ return $string;
+ }
+
+
+ protected function renderFooter ()
+ {
+ $string = <<<EOD
+
+}
+</script>
+
+EOD;
+
+ return $string;
+ }
+
+ protected function getFirebugLoggingFunction($level)
+ {
+ switch ($level)
+ {
+ case TLogger::DEBUG:
+ case TLogger::INFO:
+ case TLogger::NOTICE:
+ return 'console.log';
+ case TLogger::WARNING:
+ return 'console.warn';
+ case TLogger::ERROR:
+ case TLogger::ALERT:
+ case TLogger::FATAL:
+ return 'console.error';
+ default:
+ return 'console.log';
+ }
+ }
+
+} \ No newline at end of file