[Mapbender-commits] r1261 - in trunk/mapbender: conf http/classes http/javascripts http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Apr 13 09:01:58 EDT 2007


Author: christoph
Date: 2007-04-13 09:01:58 -0400 (Fri, 13 Apr 2007)
New Revision: 1261

Modified:
   trunk/mapbender/conf/mapbender.conf-dist
   trunk/mapbender/http/classes/class_mb_exception.php
   trunk/mapbender/http/javascripts/map.php
   trunk/mapbender/http/php/mb_js_exception.php
Log:
improved exception handling

* log levels

* various options for js exceptions 

Modified: trunk/mapbender/conf/mapbender.conf-dist
===================================================================
--- trunk/mapbender/conf/mapbender.conf-dist	2007-04-13 12:51:20 UTC (rev 1260)
+++ trunk/mapbender/conf/mapbender.conf-dist	2007-04-13 13:01:58 UTC (rev 1261)
@@ -132,6 +132,12 @@
 define("TIME_LIMIT", "300");
 define("PHP_PATH", "/usr/local/bin/");
 
+define("LOG_LEVEL_LIST", "off,error,warning,all");
+define("LOG_LEVEL", "warning");
+
+// "on", "alert", "console", "off"
+define("LOG_JS", "on");
+
 ###HACK for GLOBALS
 $DBSERVER=DBSERVER;
   $DB=DB;

Modified: trunk/mapbender/http/classes/class_mb_exception.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_exception.php	2007-04-13 12:51:20 UTC (rev 1260)
+++ trunk/mapbender/http/classes/class_mb_exception.php	2007-04-13 13:01:58 UTC (rev 1261)
@@ -22,30 +22,63 @@
 * class exception
 *
 */
-class mb_exception{
-	
+include(dirname(__FILE__)."/../../conf/mapbender.conf");
+
+class mb_log {
+	var $log_levels = LOG_LEVEL_LIST;
+	var $mb_log_level = LOG_LEVEL;	
 	var $dir = "../../log/";
 	var $filename_prefix = "mb_error_";
+
+	function indexOf($level, $levelArray) {
+		$index = false;
+		for ($i=0; $i < count($levelArray); $i++) {
+			if ($levelArray[$i] == $level) {
+				$index = $i;
+			}
+		}
+		return $index;
+	}
+
+	function isValidLevel($level) {
+		$log_level_array = explode(",", $this->log_levels);
+		$isValid = in_array($level, $log_level_array);
+		$isAppropriate = ($this->indexOf($level, $log_level_array) <= $this->indexOf($this->mb_log_level, $log_level_array));
+		return $isValid && $isAppropriate;
+	}
 	
-	function mb_exception($n){
-		if(is_dir($this->dir)){
-			$logfile = $this->dir . $this->filename_prefix . date("Y_m_d") . ".log";
-			if($h = fopen($logfile,"a")){
-				$content = date("Y.m.d") . "," . date("H:i:s") . "," . $n .chr(13).chr(10);
-				if(!fwrite($h,$content)){
-					#exit;
+	function mb_log($n, $level){
+		if (!isset($this->mb_log_level)) {
+			$e = new mb_exception("class_mb_exception: please set LOG_LEVEL in mapbender.conf");
+		}
+		if ($this->isValidLevel($level)) {
+			if(is_dir($this->dir)){
+				$logfile = $this->dir . $this->filename_prefix . date("Y_m_d") . ".log";
+				if($h = fopen($logfile,"a")){
+					$content = date("Y.m.d") . "," . date("H:i:s") . "," . $n .chr(13).chr(10);
+					if(!fwrite($h,$content)){
+						#exit;
+					}
+					fclose($h);
 				}
-				fclose($h);
 			}
 		}
 	}
 }
 
-class mb_debug extends mb_exception {
-	var $filename_prefix = "mb_debug_";
+class mb_warning extends mb_log {
+	var $level = "warning";
 	
-	function mb_debug($message) {
-		$this->mb_exception($message);
+	function mb_warning($message) {
+		$this->mb_log($message, $this->level);
 	}
 }
+
+class mb_exception extends mb_log {
+	var $level = "error";
+	
+	function mb_exception($message) {
+		$this->mb_log($message, $this->level);
+	}
+}
 ?>
\ No newline at end of file

Modified: trunk/mapbender/http/javascripts/map.php
===================================================================
--- trunk/mapbender/http/javascripts/map.php	2007-04-13 12:51:20 UTC (rev 1260)
+++ trunk/mapbender/http/javascripts/map.php	2007-04-13 13:01:58 UTC (rev 1261)
@@ -27,6 +27,9 @@
 echo "var mb_styleID = '".md5($_SESSION["mb_user_name"])."';";
 echo "var mb_myBBOX = '".$_SESSION["mb_myBBOX"]."';";
 echo "var owsproxy = '".OWSPROXY."';";
+echo "var mb_log_js = '".LOG_JS."';";
+echo "var mb_log_level = '".LOG_LEVEL."';";
+echo "var log_levels = '".LOG_LEVEL_LIST."';";
 ?>
 var ie = document.all?1:0;
 var n6 = document.getElementById&&!document.all?1:0;
@@ -66,16 +69,58 @@
 var mb_trans = new Image; 
 mb_trans.src = "../img/transparent.gif";
 /*END OF GLOBALS*/
+
+var Mb_log = function() {
+	this.levelArray = log_levels.split(",");
+	this.log_level = mb_log_level;
+	this.log_js = mb_log_js;
 	
-function Mb_exception(message) {
-	try {
-		mb_ajaxWrap_post('../php/mb_js_exception.php', {text:message});
+	this.indexOfLevel = function(aLevel) {
+		for (var i = 0; i < this.levelArray.length; i++) {
+			if (aLevel == this.levelArray[i])  {
+				return i;
+			}
+		}
+		return false;
 	}
-	catch(e) {
-		alert(message);
+	this.isValidLevel = function(aLevel) {
+		var isNotOff = typeof(mb_log_js) != 'undefined' && this.log_js != "off";
+		var levelIndex = this.indexOfLevel(aLevel);
+		var isAppropriate = (typeof(levelIndex)=='number' && levelIndex < this.indexOfLevel(this.log_level));
+		return (isNotOff && isAppropriate);
 	}
+	this.throw = function (message, level) {
+		if (this.isValidLevel(level)) {
+			if (this.log_js == "on") {
+				try {
+					mb_ajaxWrap_post('../php/mb_js_exception.php', {level:level,text:message});
+				}
+				catch(e) {
+					alert(e + ": " + message);
+				}
+			}
+			else if (mb_log_js == "alert") {
+				alert(message);
+			}
+			else if (mb_log_js == "console") {
+				console.log("%s", message);
+			}
+		}
+	}
+}	
+	
+function Mb_exception(message) {
+	this.level = "error";
+	this.throw(message, this.level);
 }
+Mb_exception.prototype = new Mb_log();
 
+function Mb_warning(message) {
+	this.level = "warning";
+	this.throw(message, this.level);
+}
+Mb_warning.prototype = new Mb_log();
+
 function mb_ajax_get(url, param, callback) {
 	try {
 		mb_ajaxWrap_get(url, param, callback);

Modified: trunk/mapbender/http/php/mb_js_exception.php
===================================================================
--- trunk/mapbender/http/php/mb_js_exception.php	2007-04-13 12:51:20 UTC (rev 1260)
+++ trunk/mapbender/http/php/mb_js_exception.php	2007-04-13 13:01:58 UTC (rev 1261)
@@ -1,8 +1,17 @@
 <?php
-
 $message = $_POST['text'];
+$level = $_POST['level'];
 
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
-$e = new mb_exception($message);
 
+if ($level == "warning") {
+	$e = new mb_warning($message);
+}
+else if ($level == "error") {
+	$e = new mb_exception($message);
+}
+else {
+	$e = new mb_exception($message);
+}
+echo $type . " '" . $message . "' thrown.";
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list