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/common-1.1.x Commit: 0386ac2cd76671001ce3d566148522cfd8de614a Parents: 317cfdb Author: daserge <v-ses...@microsoft.com> Authored: Wed Mar 9 22:20:01 2016 +0300 Committer: daserge <v-ses...@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-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org