summaryrefslogtreecommitdiff
path: root/framework/Util/TLogger.php
diff options
context:
space:
mode:
authorjavalizard <>2010-04-14 03:48:41 +0000
committerjavalizard <>2010-04-14 03:48:41 +0000
commit3ab953b22dc3200f864fe8282d1ebff0498e98ee (patch)
treed09899e75728508004d298fe3bdcfc822e05c2e6 /framework/Util/TLogger.php
parentb2b00ee68812dc455e5fe3ea816d7af16d500b2d (diff)
changed the gmdate to just date. TLogger now captures the memory footprint and controls. TLogRouter now can specify logs that require the header with the IHeaderRoute interface. so the TFirePhpLogRoute can work. TLogRoutes can be disabled and all of the routes can be gotten. Each TLogRoute also can have a control filter, user role filter (so, for instance, if you wanted a browser log route on a production site but only for developers), a meta id is also stored for linking to other data in the system, the user id if a user is logged in, active (so routes can be turned off but not deleted), and an error should something go bad with a log route it shouldn't take down the page. Updated the docs on the category filter having to be an array instead of a string. This includes some functions for serializing the Log Router classes as xml. Also the browser route does a quartile analysis on the times and memory footprint of each log item (independently), and highlights the log lines that are memory hogs or time hogs. We can use this as a basis for a set of analysis classes? This includes some interesting functions which does array of array key index to value sorting. For instance getting all rows from a database table. eg. $arr array(array('key'=>'value1', ...), array('key'=>...), array(...)). vsort($arr, 'key'). We may want to move some of this stuff around
Diffstat (limited to 'framework/Util/TLogger.php')
-rw-r--r--framework/Util/TLogger.php88
1 files changed, 63 insertions, 25 deletions
diff --git a/framework/Util/TLogger.php b/framework/Util/TLogger.php
index 51005883..388a5241 100644
--- a/framework/Util/TLogger.php
+++ b/framework/Util/TLogger.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2010 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Util
@@ -14,8 +14,8 @@
* TLogger class.
*
* TLogger records log messages in memory and implements the methods to
- * retrieve the messages with filter conditions, including log levels and
- * log categories.
+ * retrieve the messages with filter conditions, including log levels,
+ * log categories, and by control.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
@@ -46,6 +46,10 @@ class TLogger extends TComponent
* @var array list of categories to be filtered
*/
private $_categories;
+ /**
+ * @var array list of control client ids to be filtered
+ */
+ private $_controls;
/**
* Logs a message.
@@ -55,59 +59,77 @@ class TLogger extends TComponent
* TLogger::DEBUG, TLogger::INFO, TLogger::NOTICE, TLogger::WARNING,
* TLogger::ERROR, TLogger::ALERT, TLogger::FATAL.
* @param string category of the message
+ * @param string|TControl control of the message
*/
- public function log($message,$level,$category='Uncategorized')
+ public function log($message,$level,$category='Uncategorized', $ctl=null)
{
- $this->_logs[]=array($message,$level,$category,microtime(true));
+ if($ctl) {
+ if($ctl instanceof TControl)
+ $ctl = $ctl->ClientId;
+ else if(!is_string($ctl))
+ $ctl = null;
+ } else
+ $ctl = null;
+ $this->_logs[]=array($message,$level,$category,microtime(true),memory_get_usage(),$ctl);
}
/**
* Retrieves log messages.
- * Messages may be filtered by log levels and/or categories.
+ * Messages may be filtered by log levels and/or categories and/or control client ids.
* A level filter is specified by an integer, whose bits indicate the levels interested.
* For example, (TLogger::INFO | TLogger::WARNING) specifies INFO and WARNING levels.
- * A category filter is specified by concatenating interested category names
- * with commas. A message whose category name starts with any filtering category
- * will be returned. For example, a category filter 'System.Web, System.IO'
+ * A category filter is specified by an array of categories to filter.
+ * A message whose category name starts with any filtering category
+ * will be returned. For example, a category filter array('System.Web','System.IO')
* will return messages under categories such as 'System.Web', 'System.IO',
* 'System.Web.UI', 'System.Web.UI.WebControls', etc.
- * Level filter and category filter are combinational, i.e., only messages
- * satisfying both filter conditions will they be returned.
+ * A control client id filter is specified by an array of control client id
+ * A message whose control client id starts with any filtering naming panels
+ * will be returned. For example, a category filter array('ctl0_body_header',
+ * 'ctl0_body_content_sidebar')
+ * will return messages under categories such as 'ctl0_body_header', 'ctl0_body_content_sidebar',
+ * 'ctl0_body_header_title', 'ctl0_body_content_sidebar_savebutton', etc.
+ * Level filter, category filter, and control filter are combinational, i.e., only messages
+ * satisfying all filter conditions will they be returned.
* @param integer level filter
- * @param string category filter
- * @param array list of messages. Each array elements represents one message
+ * @param array category filter
+ * @param array control filter
+ * @return array list of messages. Each array elements represents one message
* with the following structure:
* array(
* [0] => message
* [1] => level
* [2] => category
* [3] => timestamp (by microtime(), float number));
+ * [4] => memory in bytes
+ * [5] => control client id
*/
- public function getLogs($levels=null,$categories=null)
+ public function getLogs($levels=null,$categories=null,$controls=null)
{
$this->_levels=$levels;
$this->_categories=$categories;
- if(empty($levels) && empty($categories))
+ $this->_controls=$controls;
+ if(empty($levels) && empty($categories) && empty($controls))
return $this->_logs;
- else if(empty($levels))
- return array_values(array_filter(array_filter($this->_logs,array($this,'filterByCategories'))));
- else if(empty($categories))
- return array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
- else
- {
- $ret=array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
- return array_values(array_filter(array_filter($ret,array($this,'filterByCategories'))));
- }
+ $logs = $this->_logs;
+ if(!empty($levels))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByLevels')) ));
+ if(!empty($categories))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByCategories')) ));
+ if(!empty($controls))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByControl')) ));
+ return $logs;
}
/**
- * Filter function used by {@link getLogs}
+ * Filter function used by {@link getLogs}.
* @param array element to be filtered
*/
private function filterByCategories($value)
{
foreach($this->_categories as $category)
{
+ // element 2 is the category
if($value[2]===$category || strpos($value[2],$category.'.')===0)
return $value;
}
@@ -120,10 +142,26 @@ class TLogger extends TComponent
*/
private function filterByLevels($value)
{
+ // element 1 are the levels
if($value[1] & $this->_levels)
return $value;
else
return false;
}
+
+ /**
+ * Filter function used by {@link getLogs}
+ * @param array element to be filtered
+ */
+ private function filterByControl($ctl)
+ {
+ // element 5 are the control client ids
+ foreach($this->_controls as $control)
+ {
+ if($value[5]===$control || strpos($value[5],$control)===0)
+ return $value;
+ }
+ return false;
+ }
}