Repository: serverless/serverless-azure-functions (ts)

Issue:
Specifying `verbose` flag fails deployment
<!--
1. Please check if an issue already exists. This bug may have already been documented
2. Check out and follow our Guidelines: https://github.com/serverless/serverless-azure-functions/CONTRIBUTING.md
3. Fill out the whole template so we have a good overview on the issue
4. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
5. Please follow the template, otherwise we'll have to ask you to update it
-->

# Specifying `verbose` flag fails deployment

When passing the `verbose` flag while deploying, the deployment fails with an error message saying `logLevelStr.toLowerCase is not a function`.

FYI: if I don't specify the `verbose` flag, deployment is ok.

## What I did

I created a new `sls` project using the following command:
> Using `serverless` version `1.71.3`
```
sls create -t azure-python --name azure-demo --path azure-demo
```

Next, I updated `serverless-azure-functions` to latest version (~ `2.0.4`)

Here's my `package.json`:

```
{
  "name": "azure-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "serverless-azure-functions": "^2.0.4"
  }
}
```

Running `sls deploy` works just fine, but using the `verbose` flag fails with the following stacktrace:

> PS: I tried with and without a value for `verbose` (~ source code says it should default to `info`)

```
➜ sls deploy --verbose

  Type Error ---------------------------------------------

  TypeError: logLevelStr.toLowerCase is not a function
      at new LoggingService (/Users/pprins/projects/innogy/azure/azure-demo/node_modules/serverless-azure-functions/lib/services/loggingService.js:30:24)
      at AzurePackagePlugin.AzureBasePlugin (/Users/pprins/projects/innogy/azure/azure-demo/node_modules/serverless-azure-functions/lib/plugins/azureBasePlugin.js:12:31)
      at new AzurePackagePlugin (/Users/pprins/projects/innogy/azure/azure-demo/node_modules/serverless-azure-functions/lib/plugins/package/azurePackagePlugin.js:59:28)
      at PluginManager.addPlugin (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:78:28)
      at new AzureIndex (/Users/pprins/projects/innogy/azure/azure-demo/node_modules/serverless-azure-functions/lib/index.js:29:39)
      at PluginManager.addPlugin (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:78:28)
      at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:115:31
      at Array.forEach (<anonymous>)
      at PluginManager.loadAllPlugins (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:115:8)
      at /usr/local/lib/node_modules/serverless/lib/Serverless.js:96:35
      at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:673:18)
      at PromiseArray._resolve (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise_array.js:127:19)
      at PromiseArray._promiseFulfilled (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise_array.js:145:14)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:609:26)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:673:18)
      at Promise._resolveCallback (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:466:57)
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:559:17)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:673:18)
      at PropertiesPromiseArray.PromiseArray._resolve (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise_array.js:127:19)
      at PropertiesPromiseArray._promiseFulfilled (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/props.js:78:14)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:609:26)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:439:21)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.14.1
     Framework Version:         1.71.3
     Plugin Version:            3.6.12
     SDK Version:               2.3.0
     Components Version:        2.30.11
```

Pull request description:
fix: Fix log level setting to handle --verbose
<!--
1. Please check out and follow our Contributing Guidelines: https://github.com/serverless/serverless-azure-functions/CONTRIBUTING.md
2. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the PR
3. Please follow the template, otherwise we'll have to ask you to update it and it will take longer until your PR is merged
-->

## What did you implement:

Fix log level setting to handle boolean case, previously expected empty string

Closes #470 

<!--
Briefly describe the feature if no issue exists for this PR
-->

## How did you implement it:

Updated the conditions to check for boolean in `--verbose` option, set to most verbose level

<!--
If this is a nontrivial change please briefly describe your implementation so its easy for us to understand and review your code.
-->

## How can we verify it:

Run a command with `--verbose` on the end. Previously failed

<!--
Add any applicable config, commands, screenshots or other resources
to make it easy for us to verify this works. The easier you make it for us
to review a PR, the faster we can review and merge it.

Examples:
* serverless.yml - Fully functioning to easily deploy changes
* Screenshots - Showing the difference between your output and the master
* Cloud Configuration - List cloud resources and show that the correct configuration is in place
* Other - Anything else that comes to mind to help us evaluate
-->

## Todos:

_**Note: Run `npm run test:ci` to run all validation checks on proposed changes**_

- [x] Ensure there are no lint errors.  
       **Validate via `npm run lint`**  
       _Note: Some reported issues can be automatically fixed by running `npm run lint:fix`_
- [x] Write tests and confirm existing functionality is not broken.  
       **Validate via `npm test`**
- [x] Write documentation
- [x] Provide verification config / commands / resources
- [x] Enable "Allow edits from maintainers" for this PR
- [x] Update the messages below

**_Is this ready for review?:_** YES  
**_Is it a breaking change?:_** NO


Patch:
diff --git a/src/services/loggingService.ts b/src/services/loggingService.ts
index cf411c0..e653f32 100644
--- a/src/services/loggingService.ts
+++ b/src/services/loggingService.ts
@@ -22,18 +22,25 @@ export class LoggingService {
   private logLevel: LogLevel;
 
   public constructor(private serverless: Serverless, private options: ServerlessAzureOptions) {
-    
-    // Check for 'verbose' or 'v'. Would use the sls shortcuts at the plugin level, 
-    // but this will be utilized across the plugins, so we check for both
-    const logLevelStr = Utils.get(options, "verbose");
+    const verbosity = Utils.get(options, "verbose");
+    const defaultLogLevel = LogLevel.INFO;
 
-    this.logLevel = (logLevelStr !== undefined) ? Utils.get({
-      "error": LogLevel.ERROR,
-      "warn": LogLevel.WARN,
-      "info": LogLevel.INFO,
-      "debug": LogLevel.DEBUG,
-      "": LogLevel.DEBUG
-    }, logLevelStr.toLowerCase()) : LogLevel.INFO;
+    if (verbosity === true) {
+      // --verbose flag is passed with no specified level
+      this.logLevel = LogLevel.DEBUG;
+    } else if (typeof verbosity === "string") {
+      // --verbose {level} is passed
+      this.logLevel = Utils.get({
+        "error": LogLevel.ERROR,
+        "warn": LogLevel.WARN,
+        "info": LogLevel.INFO,
+        "debug": LogLevel.DEBUG,
+        "": LogLevel.DEBUG
+      }, verbosity.toLowerCase(), defaultLogLevel);
+    } else {
+      // --verbose not passed, use default
+      this.logLevel = defaultLogLevel;
+    }    
   }
 
   /**


Test patch:
diff --git a/src/services/loggingService.test.ts b/src/services/loggingService.test.ts
index 7dec002..59f68e4 100644
--- a/src/services/loggingService.test.ts
+++ b/src/services/loggingService.test.ts
@@ -46,9 +46,9 @@ describe("Logging Service", () => {
     expect(sls.cli.log).lastCalledWith("[ERROR] Error");
   });
 
-  it("empty string as option value sets logging level to debug", () => {
+  it("boolean as option value sets logging level to debug", () => {
     const sls = MockFactory.createTestServerless();
-    loggingService = createService(sls, {"verbose": ""});
+    loggingService = createService(sls, {"verbose": true});
     loggingService.debug("Debug");
     expect(sls.cli.log).toBeCalledWith("[DEBUG] Debug");
   });