diff options
Diffstat (limited to 'framework/Util/TLogger.php')
-rw-r--r-- | framework/Util/TLogger.php | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/framework/Util/TLogger.php b/framework/Util/TLogger.php index a616df9a..c2435605 100644 --- a/framework/Util/TLogger.php +++ b/framework/Util/TLogger.php @@ -50,6 +50,10 @@ class TLogger extends TComponent * @var array list of control client ids to be filtered
*/
private $_controls;
+ /**
+ * @var float timestamp used to filter
+ */
+ private $_timestamp;
/**
* Logs a message.
@@ -75,7 +79,7 @@ class TLogger extends TComponent /**
* Retrieves log messages.
- * Messages may be filtered by log levels and/or categories and/or control client ids.
+ * Messages may be filtered by log levels and/or categories and/or control client ids and/or timestamp.
* 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 an array of categories to filter.
@@ -89,7 +93,9 @@ class TLogger extends TComponent * '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
+ * A timestamp filter is specified as an interger or float number.
+ * A message whose registered timestamp is less or equal the filter value will be returned.
+ * Level filter, category filter, control filter and timestamp filter are combinational, i.e., only messages
* satisfying all filter conditions will they be returned.
* @param integer level filter
* @param array category filter
@@ -104,12 +110,13 @@ class TLogger extends TComponent * [4] => memory in bytes
* [5] => control client id
*/
- public function getLogs($levels=null,$categories=null,$controls=null)
+ public function getLogs($levels=null,$categories=null,$controls=null,$timestamp=null)
{
$this->_levels=$levels;
$this->_categories=$categories;
$this->_controls=$controls;
- if(empty($levels) && empty($categories) && empty($controls))
+ $this->_timestamp=$timestamp;
+ if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp))
return $this->_logs;
$logs = $this->_logs;
if(!empty($levels))
@@ -118,10 +125,59 @@ class TLogger extends TComponent $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')) ));
+ if(!is_null($timestamp))
+ $logs = array_values(array_filter( array_filter($logs,array($this,'filterByTimeStamp')) ));
return $logs;
}
/**
+ * Deletes log messages from the queue.
+ * Messages may be filtered by log levels and/or categories and/or control client ids and/or timestamp.
+ * 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 an array of categories to filter.
+ * A message whose category name starts with any filtering category
+ * will be deleted. For example, a category filter array('System.Web','System.IO')
+ * will delete messages under categories such as 'System.Web', 'System.IO',
+ * 'System.Web.UI', 'System.Web.UI.WebControls', etc.
+ * 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 deleted. For example, a category filter array('ctl0_body_header',
+ * 'ctl0_body_content_sidebar')
+ * will delete messages under categories such as 'ctl0_body_header', 'ctl0_body_content_sidebar',
+ * 'ctl0_body_header_title', 'ctl0_body_content_sidebar_savebutton', etc.
+ * A timestamp filter is specified as an interger or float number.
+ * A message whose registered timestamp is less or equal the filter value will be returned.
+ * Level filter, category filter, control filter and timestamp filter are combinational, i.e., only messages
+ * satisfying all filter conditions will they be returned.
+ * @param integer level filter
+ * @param array category filter
+ * @param array control filter
+ */
+ public function deleteLogs($levels=null,$categories=null,$controls=null,$timestamp=null)
+ {
+ $this->_levels=$levels;
+ $this->_categories=$categories;
+ $this->_controls=$controls;
+ $this->_timestamp=$timestamp;
+ if(empty($levels) && empty($categories) && empty($controls) && is_null($timestamp))
+ {
+ $this->_logs=array();
+ return;
+ }
+ $logs = $this->_logs;
+ if(!empty($levels))
+ $logs = array_filter( array_filter($logs,array($this,'filterByLevels')) );
+ if(!empty($categories))
+ $logs = array_filter( array_filter($logs,array($this,'filterByCategories')) );
+ if(!empty($controls))
+ $logs = array_filter( array_filter($logs,array($this,'filterByControl')) );
+ if(!is_null($timestamp))
+ $logs = array_filter( array_filter($logs,array($this,'filterByTimeStamp')) );
+ $this->_logs = array_values( array_diff_key($this->_logs, $logs) );
+ }
+
+ /**
* Filter function used by {@link getLogs}.
* @param array element to be filtered
*/
@@ -153,7 +209,7 @@ class TLogger extends TComponent * Filter function used by {@link getLogs}
* @param array element to be filtered
*/
- private function filterByControl($ctl)
+ private function filterByControl($value)
{
// element 5 are the control client ids
foreach($this->_controls as $control)
@@ -163,5 +219,18 @@ class TLogger extends TComponent }
return false;
}
+
+ /**
+ * Filter function used by {@link getLogs}
+ * @param array element to be filtered
+ */
+ private function filterByTimeStamp($value)
+ {
+ // element 3 is the timestamp
+ if($value[3] <= $this->_timestamp)
+ return $value;
+ else
+ return false;
+ }
}
|