summaryrefslogtreecommitdiff
path: root/framework/Log/TLogger.php
diff options
context:
space:
mode:
authorxue <>2006-01-08 18:13:02 +0000
committerxue <>2006-01-08 18:13:02 +0000
commit09596d92b2eea0f70c98cc5abca6f5dbd4629802 (patch)
tree3e1c656d18ee46510bd76033e7b36ca2bd4dc05d /framework/Log/TLogger.php
parent4a2c7c4e9ac75c1420e95624fb9ee34ab178c52f (diff)
Completed TLogger, TLogRouter, TFileLogRoute, TEmailLogRoute
Diffstat (limited to 'framework/Log/TLogger.php')
-rw-r--r--framework/Log/TLogger.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/framework/Log/TLogger.php b/framework/Log/TLogger.php
new file mode 100644
index 00000000..f9b9b47a
--- /dev/null
+++ b/framework/Log/TLogger.php
@@ -0,0 +1,57 @@
+<?php
+
+class TLogger extends TComponent
+{
+ const DEBUG=0x01;
+ const INFO=0x02;
+ const NOTICE=0x04;
+ const WARNING=0x08;
+ const ERROR=0x10;
+ const ALERT=0x20;
+ const FATAL=0x40;
+ private $_logs=array();
+ private $_levels;
+ private $_categories;
+
+ public function log($message,$level,$category='Uncategorized')
+ {
+ $this->_logs[]=array($message,$level,$category,time());
+ }
+
+ public function getLogs($levels=null,$categories=null)
+ {
+ $this->_levels=$levels;
+ $this->_categories=$categories;
+ if(empty($levels) && empty($categories))
+ 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'))));
+ }
+ }
+
+ private function filterByCategories($value)
+ {
+ foreach($this->_categories as $category)
+ {
+ if(strpos($value[2],$category)===0)
+ return $value;
+ }
+ return false;
+ }
+
+ private function filterByLevels($value)
+ {
+ if($value[1] & $this->_levels)
+ return $value;
+ else
+ return false;
+ }
+}
+
+?> \ No newline at end of file