From 5890adb76457a5cee1e2b874eb656b969cceb758 Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 9 Jan 2006 06:30:04 +0000 Subject: Coloured TBrowserLogRoute --- framework/Log/TLogRouter.php | 61 ++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'framework/Log/TLogRouter.php') diff --git a/framework/Log/TLogRouter.php b/framework/Log/TLogRouter.php index 89214d80..ecf57823 100644 --- a/framework/Log/TLogRouter.php +++ b/framework/Log/TLogRouter.php @@ -152,7 +152,7 @@ abstract class TLogRoute extends TComponent /** * @var array lookup table for level names */ - private static $_levelNames=array( + protected static $_levelNames=array( TLogger::DEBUG=>'Debug', TLogger::INFO=>'Info', TLogger::NOTICE=>'Notice', @@ -163,7 +163,7 @@ abstract class TLogRoute extends TComponent /** * @var array lookup table for level values */ - private static $_levelValues=array( + protected static $_levelValues=array( 'debug'=>TLogger::DEBUG, 'info'=>TLogger::INFO, 'notice'=>TLogger::NOTICE, @@ -566,27 +566,34 @@ class TEmailLogRoute extends TLogRoute } } +/** + * TBrowserLogRoute class. + * + * TBrowserLogRoute prints selected log messages in the response. + * + * @author Xiang Wei Zhuo + * @version $Revision: $ $Date: $ + * @package System.Log + * @since 3.0 + */ class TBrowserLogRoute extends TLogRoute { public function processLogs($logs) { - $first = $logs[0][3]; - $prev = $first; - $total = 0; - $delta = 0; - $even = true; - echo $this->renderHeader(); + if(empty($logs) || $this->getApplication()->getMode()==='Performance') return; + $first = $logs[0][3]; $prev = $first; $total = 0; $delta = 0; $even = true; + $response = $this->getApplication()->getResponse(); + $response->write($this->renderHeader()); foreach($logs as $log) { $total += $log[3] - $first; $timing['total'] = $total; $timing['delta'] = $log[3]-$prev; - $timing['even'] = $even; + $timing['even'] = !($even = !$even); $prev=$log[3]; - $even = !$even; - echo $this->renderMessage($log,$timing); + $response->write($this->renderMessage($log,$timing)); } - echo $this->renderFooter(); + $response->write($this->renderFooter()); } protected function renderHeader() @@ -608,20 +615,42 @@ EOD; protected function renderMessage($log, $info) { - $color = $info['even'] ? "#fff" : "#eee"; + $bgcolor = $info['even'] ? "#fff" : "#eee"; $total = sprintf('%0.6f', $info['total']); $delta = sprintf('%0.6f', $info['delta']); + $color = $this->getColorLevel($log[1]); + $msg = preg_replace('/\(line[^\)]+\)$/','',$log[0]); //remove line number info $string = << - {$log[2]}{$log[0]}{$total}{$delta} + + {$log[2]}{$msg}{$total}{$delta} EOD; return $string; } + protected function getColorLevel($level) + { + switch($level) + { + case TLogger::DEBUG: return 'green'; + case TLogger::INFO: return 'black'; + case TLogger::NOTICE: return 'blue'; + case TLogger::WARNING: return '#f63'; + case TLogger::ALERT: return '#c00'; + case TLogger::FATAL: return 'red'; + } + } + protected function renderFooter() { - return ""; + $string = ""; + foreach(self::$_levelValues as $name => $level) + { + $string .= "getColorLevel($level); + $string .= ";margin: 0.5em;\">".strtoupper($name).""; + } + $string .= ""; + return $string; } } ?> \ No newline at end of file -- cgit v1.2.3