Updated Branches: refs/heads/master 05cffae81 -> d581fc913
[ios] route console methods to original console Cordova's console.log does not log to remote web-inspector https://issues.apache.org/jira/browse/CB-1539 The code was only routing console methods to the original console if they did NOT match the current level. Change to ALWAYS call the original console methods. Made a little cleaner and safer as well. 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/d581fc91 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/d581fc91 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/d581fc91 Branch: refs/heads/master Commit: d581fc913c974f3734aee8d0fda2d2f12afadd97 Parents: 05cffae Author: Patrick Mueller <pmue...@apache.org> Authored: Wed Sep 26 09:21:20 2012 -0400 Committer: Patrick Mueller <pmue...@apache.org> Committed: Wed Sep 26 09:21:20 2012 -0400 ---------------------------------------------------------------------- lib/ios/plugin/ios/console.js | 31 ++++++++++++++++++++----------- 1 files changed, 20 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d581fc91/lib/ios/plugin/ios/console.js ---------------------------------------------------------------------- diff --git a/lib/ios/plugin/ios/console.js b/lib/ios/plugin/ios/console.js index 6ec196d..98857c6 100644 --- a/lib/ios/plugin/ios/console.js +++ b/lib/ios/plugin/ios/console.js @@ -26,7 +26,6 @@ var exec = require('cordova/exec'); * @constructor */ var DebugConsole = function() { - this.winConsole = window.console; this.logLevel = DebugConsole.INFO_LEVEL; }; @@ -41,7 +40,10 @@ DebugConsole.prototype.setLevel = function(level) { this.logLevel = level; }; -var stringify = function(message) { +/** + * create a nice string for an object + */ +function stringify(message) { try { if (typeof message === "object" && JSON && JSON.stringify) { try { @@ -59,16 +61,25 @@ var stringify = function(message) { }; /** + * remember the original console and it's methods + */ +var origConsole = window.console || {} + +var origConsole_log = origConsole ? origConsole.log : function(){} +var origConsole_warn = origConsole ? origConsole.warn : function(){} +var origConsole_error = origConsole ? origConsole.error : function(){} + + +/** * 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) { + origConsole_log.apply(origConsole, arguments) + 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); - } }; /** @@ -76,12 +87,11 @@ DebugConsole.prototype.log = function(message) { * @param {Object|String} message Message or object to print to the console */ DebugConsole.prototype.warn = function(message) { + origConsole_warn.apply(origConsole, arguments) + 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); - } }; /** @@ -89,12 +99,11 @@ DebugConsole.prototype.warn = function(message) { * @param {Object|String} message Message or object to print to the console */ DebugConsole.prototype.error = function(message) { + origConsole_error.apply(origConsole, arguments) + 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();