cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject cordova-lib git commit: CB-10791 Add adjustLoggerLevel to cordova-common.CordovaLogger
Date Thu, 10 Mar 2016 14:33:00 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 317cfdb37 -> 0386ac2cd


CB-10791 Add adjustLoggerLevel to cordova-common.CordovaLogger

Adds corresponding tests


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

Branch: refs/heads/master
Commit: 0386ac2cd76671001ce3d566148522cfd8de614a
Parents: 317cfdb
Author: daserge <v-seshak@microsoft.com>
Authored: Wed Mar 9 22:20:01 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Thu Mar 10 12:36:00 2016 +0300

----------------------------------------------------------------------
 cordova-common/spec/CordovaLogger.spec.js | 28 ++++++++++++++++++++++++++
 cordova-common/src/CordovaLogger.js       | 17 ++++++++++++++++
 2 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/0386ac2c/cordova-common/spec/CordovaLogger.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/CordovaLogger.spec.js b/cordova-common/spec/CordovaLogger.spec.js
index fd96488..5c27db1 100644
--- a/cordova-common/spec/CordovaLogger.spec.js
+++ b/cordova-common/spec/CordovaLogger.spec.js
@@ -160,5 +160,33 @@ describe('CordovaLogger class', function() {
                 expect(logger.stderrCursor.write.calls[0].args[0]).toBe('Error: error_message');
             });
         });
+
+        describe('adjustLevel method', function () {
+            it('should properly adjust log level', function () {
+                var resetLogLevel = function() {
+                    logger.setLevel('normal');
+                };
+
+                resetLogLevel();
+                expect(logger.adjustLevel({verbose: true}).logLevel).toEqual('verbose');
+
+                resetLogLevel();
+                expect(logger.adjustLevel(['--verbose']).logLevel).toEqual('verbose');
+
+                resetLogLevel();
+                expect(logger.adjustLevel({silent: true}).logLevel).toEqual('error');
+
+                resetLogLevel();
+                expect(logger.adjustLevel(['--silent']).logLevel).toEqual('error');
+
+                resetLogLevel();
+                expect(logger.adjustLevel({verbose: true, silent: true}).logLevel).toEqual('verbose');
+
+                resetLogLevel();
+                expect(logger.adjustLevel(['--verbose', '--silent']).logLevel).toEqual('verbose');
+
+                resetLogLevel();
+            });
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/0386ac2c/cordova-common/src/CordovaLogger.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/CordovaLogger.js b/cordova-common/src/CordovaLogger.js
index 38bfe69..0a4a49c 100644
--- a/cordova-common/src/CordovaLogger.js
+++ b/cordova-common/src/CordovaLogger.js
@@ -153,6 +153,23 @@ CordovaLogger.prototype.setLevel = function (logLevel) {
 };
 
 /**
+ * Adjusts the current logger level according to the passed options.
+ *
+ * @param   {Object|Array}  opts  An object or args array with options
+ *
+ * @return  {CordovaLogger}     Current instance, to allow calls chaining.
+ */
+CordovaLogger.prototype.adjustLevel = function (opts) {
+    if (opts.verbose || (Array.isArray(opts) && opts.indexOf('--verbose') !== -1))
{
+        this.setLevel('verbose');
+    } else if (opts.silent || (Array.isArray(opts) && opts.indexOf('--silent') !==
-1)) {
+        this.setLevel('error');
+    }
+
+    return this;
+};
+
+/**
  * Attaches logger to EventEmitter instance provided.
  *
  * @param   {EventEmitter}  eventEmitter  An EventEmitter instance to attach


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message