You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/04/16 21:35:20 UTC

git commit: Fixes CB-518 - Remove redundant makeStructured logging in console.log

Updated Branches:
  refs/heads/master 2de1d613e -> 4052c4480


Fixes CB-518 - Remove redundant makeStructured logging in console.log


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/4052c448
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/4052c448
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/4052c448

Branch: refs/heads/master
Commit: 4052c4480f853d0d136ae1703c94c0d568e27766
Parents: 2de1d61
Author: shazron <sh...@gmail.com>
Authored: Mon Apr 16 12:35:14 2012 -0700
Committer: shazron <sh...@gmail.com>
Committed: Mon Apr 16 12:35:14 2012 -0700

----------------------------------------------------------------------
 lib/ios/plugin/ios/console.js |   90 ++++++++++++------------------------
 1 files changed, 30 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/4052c448/lib/ios/plugin/ios/console.js
----------------------------------------------------------------------
diff --git a/lib/ios/plugin/ios/console.js b/lib/ios/plugin/ios/console.js
index 278dfbb..3645912 100644
--- a/lib/ios/plugin/ios/console.js
+++ b/lib/ios/plugin/ios/console.js
@@ -1,33 +1,6 @@
 var exec = require('cordova/exec');
 
 /**
- * String indentation/formatting
- */
-function indent(str) {
-    return str.replace(/^/mg, "    ");
-}
-/**
- * Format a string for pretty logging
- */
-function makeStructured(obj, maxDepth, depth) {
-    var str = "";
-	depth = depth || 0;
-	
-    for (var i in obj) {
-        try {
-			if (typeof(obj[i]) == 'object' && maxDepth && depth < maxDepth) {
-			    str += i + ":\n" + indent(makeStructured(obj[i], maxDepth, depth+1)) + "\n";
-			} else {
-                str += i + " = " + indent(String(obj[i])).replace(/^ {4}/, "") + "\n";
-            }
-        } catch(e) {
-            str += i + " = EXCEPTION: " + e.message + "\n";
-        }
-    }
-    return str;
-}
-
-/**
  * This class provides access to the debugging console.
  * @constructor
  */
@@ -47,58 +20,55 @@ DebugConsole.prototype.setLevel = function(level) {
     this.logLevel = level;
 };
 
-/**
- * Utility function for rendering and indenting strings, or serializing
- * objects to a string capable of being printed to the console.
- * @param {Object|String} message The string or object to convert to an indented string
- * @private
- */
-DebugConsole.prototype.processMessage = function(message, maxDepth) {
-	if (maxDepth === undefined) maxDepth = 0;
-    if (typeof(message) != 'object') {
-        return (this.isDeprecated ? "WARNING: debug object is deprecated, please use console object \n" + message : message);
-    } else {
-        return ("Object:\n" + makeStructured(message, maxDepth));
-    }
-};
+var stringify = function(message) {
+	try {
+		if (typeof message === "object" && JSON && JSON.stringify) {
+			return JSON.stringify(message);
+		} else {
+			return message.toString();
+		} 
+	} catch (e) {
+		return e.toString();
+	}
+}
 
 /**
  * Print a normal log message to the console
  * @param {Object|String} message Message or object to print to the console
  */
-DebugConsole.prototype.log = function(message, maxDepth) {
-    if (this.logLevel <= DebugConsole.INFO_LEVEL)
-        exec(null, null, 'Debug Console', 'log',
-            [ this.processMessage(message, maxDepth), { logLevel: 'INFO' } ]
-        );
-    else
+DebugConsole.prototype.log = function(message) {
+    if (this.logLevel <= DebugConsole.INFO_LEVEL) {
+        exec(null, null, 'Debug Console', 'log', [ stringify(message), { logLevel: 'INFO' } ]);
+	}
+    else if (this.winConsole && this.winConsole.log) {
         this.winConsole.log(message);
+	}
 };
 
 /**
  * Print a warning message to the console
  * @param {Object|String} message Message or object to print to the console
  */
-DebugConsole.prototype.warn = function(message, maxDepth) {
-    if (this.logLevel <= DebugConsole.WARN_LEVEL)
-        exec(null, null, 'Debug Console', 'log',
-            [ this.processMessage(message, maxDepth), { logLevel: 'WARN' } ]
-        );
-    else
-        this.winConsole.error(message);
+DebugConsole.prototype.warn = function(message) {
+    if (this.logLevel <= DebugConsole.WARN_LEVEL) {
+        exec(null, null, 'Debug Console', 'log', [ stringify(message), { logLevel: 'WARN' } ]);
+    }
+    else if (this.winConsole && this.winConsole.warn) {
+        this.winConsole.warn(message);
+    }
 };
 
 /**
  * Print an error message to the console
  * @param {Object|String} message Message or object to print to the console
  */
-DebugConsole.prototype.error = function(message, maxDepth) {
-    if (this.logLevel <= DebugConsole.ERROR_LEVEL)
-        exec(null, null, 'Debug Console', 'log',
-            [ this.processMessage(message, maxDepth), { logLevel: 'ERROR' } ]
-        );
-    else
+DebugConsole.prototype.error = function(message) {
+    if (this.logLevel <= DebugConsole.ERROR_LEVEL) {
+        exec(null, null, 'Debug Console', 'log', [ stringify(message), { logLevel: 'ERROR' } ]);
+	}
+    else if (this.winConsole && this.winConsole.error){
         this.winConsole.error(message);
+	}
 };
 
 module.exports = new DebugConsole();