summaryrefslogtreecommitdiff
path: root/framework/core.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/core.php')
-rw-r--r--framework/core.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/framework/core.php b/framework/core.php
index 08481d09..3be75010 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -374,6 +374,10 @@ class PradoBase
* @var TApplication the application instance
*/
private static $_application=null;
+ /**
+ * @var TLogger logger instance
+ */
+ private static $_logger=null;
/**
* @return string the version of Prado framework
@@ -718,6 +722,74 @@ class PradoBase
$logger->info($msg);
return $logger;
}
+
+ public static function log($msg,$level,$category='Uncategorized')
+ {
+ if(self::$_logger===null)
+ self::$_logger=new TLogger;
+ self::$_logger->log($msg,$level,$category);
+ }
+
+ public static function getLogger()
+ {
+ if(self::$_logger===null)
+ self::$_logger=new TLogger;
+ return self::$_logger;
+ }
+}
+
+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,microtime());
+ }
+
+ 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($level & $this->_levels)
+ return $value;
+ else
+ return false;
+ }
}
?> \ No newline at end of file