You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/05/06 22:22:33 UTC

js commit: CB-3327: Allow Logger plugin to log to both console and native

Updated Branches:
  refs/heads/master 26796d79e -> c2d78cb4c


CB-3327: Allow Logger plugin to log to both console and native


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

Branch: refs/heads/master
Commit: c2d78cb4c8279f9659933ea1858dae8743785246
Parents: 26796d7
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon May 6 16:20:01 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon May 6 16:21:06 2013 -0400

----------------------------------------------------------------------
 lib/common/plugin/logger.js             |   48 +++++++++++++++++--------
 lib/ios/plugin/ios/logger/plugininit.js |    2 +-
 2 files changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c2d78cb4/lib/common/plugin/logger.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/logger.js b/lib/common/plugin/logger.js
index 3056598..03a5d6b 100644
--- a/lib/common/plugin/logger.js
+++ b/lib/common/plugin/logger.js
@@ -46,10 +46,13 @@ var exec    = require('cordova/exec');
 var utils   = require('cordova/utils');
 
 var UseConsole   = true;
+var UseLogger    = true;
 var Queued       = [];
 var DeviceReady  = false;
 var CurrentLevel;
 
+var originalConsole = console;
+
 /**
  * Logging levels
  */
@@ -110,8 +113,7 @@ logger.level = function (value) {
  * Getter/Setter for the useConsole functionality
  *
  * When useConsole is true, the logger will log via the
- * browser 'console' object.  Otherwise, it will use the
- * native Logger plugin.
+ * browser 'console' object.
  */
 logger.useConsole = function (value) {
     if (arguments.length) UseConsole = !!value;
@@ -136,6 +138,18 @@ logger.useConsole = function (value) {
 };
 
 /**
+ * Getter/Setter for the useLogger functionality
+ *
+ * When useLogger is true, the logger will log via the
+ * native Logger plugin.
+ */
+logger.useLogger = function (value) {
+    // Enforce boolean
+    if (arguments.length) UseLogger = !!value;
+    return UseLogger;
+};
+
+/**
  * Logs a message at the LOG level.
  *
  * Parameters passed after message are used applied to
@@ -204,24 +218,26 @@ logger.logLevel = function(level /* , ... */) {
         return;
     }
 
-    // if not using the console, use the native logger
-    if (!UseConsole) {
+    // Log using the native logger if that is enabled
+    if (UseLogger) {
         exec(null, null, "Logger", "logLevel", [level, message]);
-        return;
     }
 
-    // make sure console is not using logger
-    if (console.__usingCordovaLogger) {
-        throw new Error("console and logger are too intertwingly");
-    }
+    // Log using the console if that is enabled
+    if (UseConsole) {
+        // make sure console is not using logger
+        if (console.__usingCordovaLogger) {
+            throw new Error("console and logger are too intertwingly");
+        }
 
-    // log to the console
-    switch (level) {
-        case logger.LOG:   console.log(message); break;
-        case logger.ERROR: console.log("ERROR: " + message); break;
-        case logger.WARN:  console.log("WARN: "  + message); break;
-        case logger.INFO:  console.log("INFO: "  + message); break;
-        case logger.DEBUG: console.log("DEBUG: " + message); break;
+        // log to the console
+        switch (level) {
+            case logger.LOG:   originalConsole.log(message); break;
+            case logger.ERROR: originalConsole.log("ERROR: " + message); break;
+            case logger.WARN:  originalConsole.log("WARN: "  + message); break;
+            case logger.INFO:  originalConsole.log("INFO: "  + message); break;
+            case logger.DEBUG: originalConsole.log("DEBUG: " + message); break;
+        }
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c2d78cb4/lib/ios/plugin/ios/logger/plugininit.js
----------------------------------------------------------------------
diff --git a/lib/ios/plugin/ios/logger/plugininit.js b/lib/ios/plugin/ios/logger/plugininit.js
index 2c5f2f9..cf4e261 100644
--- a/lib/ios/plugin/ios/logger/plugininit.js
+++ b/lib/ios/plugin/ios/logger/plugininit.js
@@ -21,4 +21,4 @@
 
 // use the native logger
 var logger = require("cordova/plugin/logger");
-logger.useConsole(false);
+logger.useConsole(true);