Repository: amplify-education/serverless-domain-manager
Pull request #472 (2022-01-18 21:49:07)

Modern logs for Serverless Framework v3
<!--- Information about referencing Github Issues: https://help.github.com/articles/basic-writing-and-formatting-syntax/#referencing-issues-and-pull-requests --->
Fixes #448

**Description of Issue Fixed**
Refactoring off #448

**Changes proposed in this pull request**:

* Updated logs logic
* Updated packages

<!--- Please remember to allow edits from maintainers: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork --->



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0ec6db7..069bfc2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
+## [5.3.2] - 2021-01-19
+- Added logs for Serverless Framework v3. Thank you @medikoo ([448](https://github.com/amplify-education/serverless-domain-manager/pull/448))
+
 ## [5.3.1] - 2021-01-18
 - Updated output for `compiledCloudFormationTemplate`. Thank you @nalbion ([442](https://github.com/amplify-education/serverless-domain-manager/pull/442))
 - Fixed Route53 creation for `create_domain` action.
diff --git a/package-lock.json b/package-lock.json
index 418373c..c386483 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,30 +1,30 @@
 {
   "name": "serverless-domain-manager",
-  "version": "5.3.0",
+  "version": "5.3.2",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "serverless-domain-manager",
-      "version": "5.3.0",
+      "version": "5.3.2",
       "license": "MIT",
       "dependencies": {
-        "aws-sdk": "^2.1046.0",
+        "aws-sdk": "^2.1058.0",
         "chalk": "^4.1.2"
       },
       "devDependencies": {
         "@types/mocha": "^9.0.0",
-        "@types/node": "^17.0.8",
+        "@types/node": "^17.0.10",
         "aws-sdk-mock": "^5.5.1",
         "chai": "^4.3.4",
         "chai-spies": "^1.0.0",
-        "mocha": "^9.1.3",
+        "mocha": "^9.1.4",
         "mocha-param": "^2.0.1",
         "nyc": "^15.1.0",
         "randomstring": "^1.2.1",
         "request": "^2.88.2",
         "request-promise-native": "^1.0.9",
-        "serverless": "^2.69.1",
+        "serverless": "^2.72.0",
         "serverless-plugin-split-stacks": "^1.11.3",
         "shelljs": "^0.8.5",
         "ts-node": "^10.4.0",
@@ -1249,9 +1249,9 @@
       "dev": true
     },
     "node_modules/@types/node": {
-      "version": "17.0.8",
-      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.8.tgz",
-      "integrity": "sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==",
+      "version": "17.0.10",
+      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.10.tgz",
+      "integrity": "sha512-S/3xB4KzyFxYGCppyDt68yzBU9ysL88lSdIah4D6cptdcltc4NCPCAMc0+PCpg/lLIyC7IPvj2Z52OJWeIUkog==",
       "dev": true
     },
     "node_modules/@types/request": {
@@ -1737,9 +1737,9 @@
       "dev": true
     },
     "node_modules/aws-sdk": {
-      "version": "2.1057.0",
-      "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1057.0.tgz",
-      "integrity": "sha512-vRplJBXff0+KBJLx7PJQSz2mr6TOZZl+tPD9kNx0XIKUsdMxesm8FVL6VtAI7NG1XQ7UMGcPu6Mal3+j+mrveQ==",
+      "version": "2.1058.0",
+      "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1058.0.tgz",
+      "integrity": "sha512-q6bTq1DBBeBaU6GKKoTHmJj16WOQHhOoK7jwV93IT8pO0P1XH99gesFofhew3eT0h8Ev7quVKutk4B1kfnIXPQ==",
       "dependencies": {
         "buffer": "4.9.2",
         "events": "1.1.1",
@@ -5632,9 +5632,9 @@
       }
     },
     "node_modules/mocha": {
-      "version": "9.1.3",
-      "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.3.tgz",
-      "integrity": "sha512-Xcpl9FqXOAYqI3j79pEtHBBnQgVXIhpULjGQa7DVb0Po+VzmSIK9kanAiWLHoRR/dbZ2qpdPshuXr8l1VaHCzw==",
+      "version": "9.1.4",
+      "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.4.tgz",
+      "integrity": "sha512-+q2aV5VlJZuLgCWoBvGI5zEwPF9eEI0kr/sAA9Jm4xMND7RfIEyF8JE7C0JIg8WXRG+P1sdIAb5ccoHPlXLzcw==",
       "dev": true,
       "dependencies": {
         "@ungap/promise-all-settled": "1.1.2",
@@ -5958,15 +5958,23 @@
       }
     },
     "node_modules/node-fetch": {
-      "version": "2.6.6",
-      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
-      "integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
+      "version": "2.6.7",
+      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
+      "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
       "dev": true,
       "dependencies": {
         "whatwg-url": "^5.0.0"
       },
       "engines": {
         "node": "4.x || >=6.0.0"
+      },
+      "peerDependencies": {
+        "encoding": "^0.1.0"
+      },
+      "peerDependenciesMeta": {
+        "encoding": {
+          "optional": true
+        }
       }
     },
     "node_modules/node-preload": {
@@ -6145,15 +6153,6 @@
         "node": ">=0.10.0"
       }
     },
-    "node_modules/object-hash": {
-      "version": "2.2.0",
-      "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz",
-      "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==",
-      "dev": true,
-      "engines": {
-        "node": ">= 6"
-      }
-    },
     "node_modules/once": {
       "version": "1.4.0",
       "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -7335,9 +7334,9 @@
       }
     },
     "node_modules/serverless": {
-      "version": "2.71.0",
-      "resolved": "https://registry.npmjs.org/serverless/-/serverless-2.71.0.tgz",
-      "integrity": "sha512-2iKZqeEi0AcYo+jPxMRCGmWNZ56An+S0rrW8s9rmdSP8typ8cwGMWHQSwPxMVAP/UWASh9E8d8q6Uzoq8sJcnA==",
+      "version": "2.72.0",
+      "resolved": "https://registry.npmjs.org/serverless/-/serverless-2.72.0.tgz",
+      "integrity": "sha512-pK0QAtCnSy3haZ3mqJX50Yw+FXvx++JeEfX/D00ODpSSKPV7Z6C1N4/JZQw/kXkfYVK66VO3bzgKibHu2b0/qg==",
       "dev": true,
       "hasInstallScript": true,
       "dependencies": {
@@ -7349,7 +7348,7 @@
         "ajv": "^6.12.6",
         "ajv-keywords": "^3.5.2",
         "archiver": "^5.3.0",
-        "aws-sdk": "^2.1053.0",
+        "aws-sdk": "^2.1058.0",
         "bluebird": "^3.7.2",
         "boxen": "^5.1.2",
         "cachedir": "^2.3.0",
@@ -7373,7 +7372,6 @@
         "graceful-fs": "^4.2.9",
         "https-proxy-agent": "^5.0.0",
         "is-docker": "^2.2.1",
-        "is-wsl": "^2.2.0",
         "js-yaml": "^4.1.0",
         "json-cycle": "^1.3.0",
         "json-refs": "^3.0.15",
@@ -7381,8 +7379,7 @@
         "memoizee": "^0.4.15",
         "micromatch": "^4.0.4",
         "ncjsm": "^4.2.0",
-        "node-fetch": "^2.6.6",
-        "object-hash": "^2.2.0",
+        "node-fetch": "^2.6.7",
         "open": "^7.4.2",
         "path2": "^0.1.0",
         "process-utils": "^4.0.0",
@@ -10763,9 +10760,9 @@
       "dev": true
     },
     "@types/node": {
-      "version": "17.0.8",
-      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.8.tgz",
-      "integrity": "sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==",
+      "version": "17.0.10",
+      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.10.tgz",
+      "integrity": "sha512-S/3xB4KzyFxYGCppyDt68yzBU9ysL88lSdIah4D6cptdcltc4NCPCAMc0+PCpg/lLIyC7IPvj2Z52OJWeIUkog==",
       "dev": true
     },
     "@types/request": {
@@ -11174,9 +11171,9 @@
       "dev": true
     },
     "aws-sdk": {
-      "version": "2.1057.0",
-      "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1057.0.tgz",
-      "integrity": "sha512-vRplJBXff0+KBJLx7PJQSz2mr6TOZZl+tPD9kNx0XIKUsdMxesm8FVL6VtAI7NG1XQ7UMGcPu6Mal3+j+mrveQ==",
+      "version": "2.1058.0",
+      "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1058.0.tgz",
+      "integrity": "sha512-q6bTq1DBBeBaU6GKKoTHmJj16WOQHhOoK7jwV93IT8pO0P1XH99gesFofhew3eT0h8Ev7quVKutk4B1kfnIXPQ==",
       "requires": {
         "buffer": "4.9.2",
         "events": "1.1.1",
@@ -14298,9 +14295,9 @@
       }
     },
     "mocha": {
-      "version": "9.1.3",
-      "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.3.tgz",
-      "integrity": "sha512-Xcpl9FqXOAYqI3j79pEtHBBnQgVXIhpULjGQa7DVb0Po+VzmSIK9kanAiWLHoRR/dbZ2qpdPshuXr8l1VaHCzw==",
+      "version": "9.1.4",
+      "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.4.tgz",
+      "integrity": "sha512-+q2aV5VlJZuLgCWoBvGI5zEwPF9eEI0kr/sAA9Jm4xMND7RfIEyF8JE7C0JIg8WXRG+P1sdIAb5ccoHPlXLzcw==",
       "dev": true,
       "requires": {
         "@ungap/promise-all-settled": "1.1.2",
@@ -14560,9 +14557,9 @@
       }
     },
     "node-fetch": {
-      "version": "2.6.6",
-      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz",
-      "integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==",
+      "version": "2.6.7",
+      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
+      "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
       "dev": true,
       "requires": {
         "whatwg-url": "^5.0.0"
@@ -14707,12 +14704,6 @@
       "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
       "dev": true
     },
-    "object-hash": {
-      "version": "2.2.0",
-      "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz",
-      "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==",
-      "dev": true
-    },
     "once": {
       "version": "1.4.0",
       "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -15605,9 +15596,9 @@
       }
     },
     "serverless": {
-      "version": "2.71.0",
-      "resolved": "https://registry.npmjs.org/serverless/-/serverless-2.71.0.tgz",
-      "integrity": "sha512-2iKZqeEi0AcYo+jPxMRCGmWNZ56An+S0rrW8s9rmdSP8typ8cwGMWHQSwPxMVAP/UWASh9E8d8q6Uzoq8sJcnA==",
+      "version": "2.72.0",
+      "resolved": "https://registry.npmjs.org/serverless/-/serverless-2.72.0.tgz",
+      "integrity": "sha512-pK0QAtCnSy3haZ3mqJX50Yw+FXvx++JeEfX/D00ODpSSKPV7Z6C1N4/JZQw/kXkfYVK66VO3bzgKibHu2b0/qg==",
       "dev": true,
       "requires": {
         "@serverless/cli": "^1.6.0",
@@ -15618,7 +15609,7 @@
         "ajv": "^6.12.6",
         "ajv-keywords": "^3.5.2",
         "archiver": "^5.3.0",
-        "aws-sdk": "^2.1053.0",
+        "aws-sdk": "^2.1058.0",
         "bluebird": "^3.7.2",
         "boxen": "^5.1.2",
         "cachedir": "^2.3.0",
@@ -15642,7 +15633,6 @@
         "graceful-fs": "^4.2.9",
         "https-proxy-agent": "^5.0.0",
         "is-docker": "^2.2.1",
-        "is-wsl": "^2.2.0",
         "js-yaml": "^4.1.0",
         "json-cycle": "^1.3.0",
         "json-refs": "^3.0.15",
@@ -15650,8 +15640,7 @@
         "memoizee": "^0.4.15",
         "micromatch": "^4.0.4",
         "ncjsm": "^4.2.0",
-        "node-fetch": "^2.6.6",
-        "object-hash": "^2.2.0",
+        "node-fetch": "^2.6.7",
         "open": "^7.4.2",
         "path2": "^0.1.0",
         "process-utils": "^4.0.0",
diff --git a/package.json b/package.json
index e145839..0e0ddd1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "serverless-domain-manager",
-  "version": "5.3.1",
+  "version": "5.3.2",
   "engines": {
     "node": ">=12"
   },
@@ -47,17 +47,17 @@
   },
   "devDependencies": {
     "@types/mocha": "^9.0.0",
-    "@types/node": "^17.0.8",
+    "@types/node": "^17.0.10",
     "aws-sdk-mock": "^5.5.1",
     "chai": "^4.3.4",
     "chai-spies": "^1.0.0",
-    "mocha": "^9.1.3",
+    "mocha": "^9.1.4",
     "mocha-param": "^2.0.1",
     "nyc": "^15.1.0",
     "randomstring": "^1.2.1",
     "request": "^2.88.2",
     "request-promise-native": "^1.0.9",
-    "serverless": "^2.69.1",
+    "serverless": "^2.72.0",
     "serverless-plugin-split-stacks": "^1.11.3",
     "shelljs": "^0.8.5",
     "ts-node": "^10.4.0",
@@ -65,7 +65,7 @@
     "typescript": "^4.5.4"
   },
   "dependencies": {
-    "aws-sdk": "^2.1046.0",
+    "aws-sdk": "^2.1058.0",
     "chalk": "^4.1.2"
   },
   "peerDependencies": {
diff --git a/src/aws/api-gateway-wrapper.ts b/src/aws/api-gateway-wrapper.ts
index 77b7084..a0ed66f 100644
--- a/src/aws/api-gateway-wrapper.ts
+++ b/src/aws/api-gateway-wrapper.ts
@@ -49,9 +49,7 @@ class APIGatewayWrapper {
                 createdDomain = await throttledCall(this.apiGateway, "createDomainName", params);
                 domain.domainInfo = new DomainInfo(createdDomain);
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`Failed to create custom domain ${domain.givenDomainName}\n`);
             }
 
@@ -71,9 +69,7 @@ class APIGatewayWrapper {
                 createdDomain = await throttledCall(this.apiGatewayV2, "createDomainName", params);
                 domain.domainInfo = new DomainInfo(createdDomain);
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`Failed to create custom domain ${domain.givenDomainName}\n`);
             }
         }
@@ -89,9 +85,7 @@ class APIGatewayWrapper {
                 DomainName: domain.givenDomainName,
             });
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Failed to delete custom domain ${domain.givenDomainName}\n`);
         }
     }
@@ -108,16 +102,10 @@ class APIGatewayWrapper {
             return new DomainInfo(domainInfo);
         } catch (err) {
             if (err.code !== "NotFoundException") {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
-                throw new Error(`Unable to fetch information about ${domain.givenDomainName}`);
-            }
-            if (Globals.log) {
-                Globals.log.verbose(`${domain.givenDomainName} does not exist`);
-            } else {
-                Globals.logError(`${domain.givenDomainName} does not exist`);
+                Globals.logError(err, domain.givenDomainName);
+                throw new Error(`Unable to fetch information about ${domain.givenDomainName}\n`);
             }
+            Globals.logInfo(`${domain.givenDomainName} does not exist`);
         }
     }
 
@@ -136,15 +124,9 @@ class APIGatewayWrapper {
             // Make API call
             try {
                 await throttledCall(this.apiGateway, "createBasePathMapping", params);
-                if (Globals.log) {
-                    Globals.log(`Created API mapping '${domain.basePath}' for ${domain.givenDomainName}`);
-                } else {
-                    Globals.logInfo(`Created API mapping '${domain.basePath}' for ${domain.givenDomainName}`);
-                }
+                Globals.logInfo(`Created API mapping '${domain.basePath}' for ${domain.givenDomainName}`);
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`${domain.givenDomainName}: Unable to create basepath mapping.\n`);
             }
 
@@ -158,15 +140,9 @@ class APIGatewayWrapper {
             // Make API call
             try {
                 await throttledCall(this.apiGatewayV2, "createApiMapping", params);
-                if (Globals.log) {
-                    Globals.log(`Created API mapping '${domain.basePath}' for ${domain.givenDomainName}`);
-                } else {
-                    Globals.logInfo(`Created API mapping '${domain.basePath}' for ${domain.givenDomainName}`);
-                }
+                Globals.logInfo(`Created API mapping '${domain.basePath}' for ${domain.givenDomainName}`);
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`${domain.givenDomainName}: Unable to create basepath mapping.\n`);
             }
         }
@@ -192,9 +168,7 @@ class APIGatewayWrapper {
                 }
             }
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Unable to get API Mappings for ${domain.givenDomainName}`);
         }
     }
@@ -223,17 +197,10 @@ class APIGatewayWrapper {
             // Make API call
             try {
                 await throttledCall(this.apiGateway, "updateBasePathMapping", params);
-
-                if (Globals.log) {
-                    Globals.log.verbose(`Updated API mapping from '${domain.apiMapping.ApiMappingKey}' to '${domain.basePath}' for ${domain.givenDomainName}`);
-                } else {
-                    Globals.logInfo(`Updated API mapping from '${domain.apiMapping.ApiMappingKey}'
+                Globals.logInfo(`Updated API mapping from '${domain.apiMapping.ApiMappingKey}'
                     to '${domain.basePath}' for ${domain.givenDomainName}`);
-                }
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`${domain.givenDomainName}: Unable to update basepath mapping.\n`);
             }
 
@@ -250,15 +217,9 @@ class APIGatewayWrapper {
             // Make API call
             try {
                 await throttledCall(this.apiGatewayV2, "updateApiMapping", params);
-                if (Globals.log) {
-                    Globals.log.verbose(`Updated API mapping to '${domain.basePath}' for ${domain.givenDomainName}`);
-                } else {
-                    Globals.logInfo(`Updated API mapping to '${domain.basePath}' for ${domain.givenDomainName}`);
-                }
+                Globals.logInfo(`Updated API mapping to '${domain.basePath}' for ${domain.givenDomainName}`);
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`${domain.givenDomainName}: Unable to update basepath mapping.\n`);
             }
         }
@@ -276,18 +237,10 @@ class APIGatewayWrapper {
         // Make API call
         try {
             await throttledCall(this.apiGatewayV2, "deleteApiMapping", params);
-            if (Globals.log) {
-                Globals.log("Removed basepath mapping.");
-            } else {
-                Globals.logInfo("Removed basepath mapping.");
-            }
+            Globals.logInfo("Removed basepath mapping.");
         } catch (err) {
-            if (Globals.log) {
-                Globals.log.verbose(`${domain.givenDomainName}: Unable to remove basepath mapping: ${err}`);
-            } else {
-                Globals.logError(err, domain.givenDomainName);
-                Globals.logInfo(`Unable to remove basepath mapping for ${domain.givenDomainName}`);
-            }
+            Globals.logError(err, domain.givenDomainName);
+            Globals.logInfo(`Unable to remove basepath mapping for ${domain.givenDomainName}`);
         }
     }
 }
diff --git a/src/aws/cloud-formation-wrapper.ts b/src/aws/cloud-formation-wrapper.ts
index 99583a4..de78dc6 100644
--- a/src/aws/cloud-formation-wrapper.ts
+++ b/src/aws/cloud-formation-wrapper.ts
@@ -37,11 +37,7 @@ class CloudFormationWrapper {
             throw new Error(`No ApiId associated with CloudFormation stack ${stackName}`);
         }
 
-        if (Globals.log) {
-            Globals.log.verbose(`Found apiId: ${apiId} for ${domain.givenDomainName}`);
-        } else {
-            Globals.logInfo(`Found apiId: ${apiId} for ${domain.givenDomainName}`);
-        }
+        Globals.logInfo(`Found apiId: ${apiId} for ${domain.givenDomainName}`);
 
         return apiId;
     }
@@ -114,11 +110,7 @@ class CloudFormationWrapper {
                 response = await this.getStack(logicalResourceId, name);
                 break;
             } catch (err) {
-                if (Globals.log) {
-                    Globals.log.verbose(err);
-                } else {
-                    Globals.logError(err);
-                }
+                Globals.logWarning(err);
             }
         }
         return response;
diff --git a/src/globals.ts b/src/globals.ts
index 52468c9..0ede2cf 100644
--- a/src/globals.ts
+++ b/src/globals.ts
@@ -68,8 +68,12 @@ export default class Globals {
         }
         const canLog = debug && process.env.SLS_DEBUG || !debug;
         if (canLog) {
-            const error = chalk.bold.red;
-            Globals.cliLog(error("Error:"), `${domain ? domain + ": " : ""} ${message}`);
+            if (Globals.log) {
+                Globals.log.error(message);
+            } else {
+                const error = chalk.bold.red;
+                Globals.cliLog(error("Error:"), `${domain ? domain + ": " : ""} ${message}`);
+            }
         }
     }
 
@@ -82,7 +86,11 @@ export default class Globals {
     public static logInfo(message: any, debug = false): void {
         const canLog = debug && process.env.SLS_DEBUG || !debug;
         if (canLog) {
-            Globals.cliLog(chalk.blue("Info:"), message);
+            if (Globals.log) {
+                Globals.log.verbose(message);
+            } else {
+                Globals.cliLog(chalk.blue("Info:"), message);
+            }
         }
     }
 
@@ -95,8 +103,12 @@ export default class Globals {
     public static logWarning(message: any, debug = false): void {
         const canLog = debug && process.env.SLS_DEBUG || !debug;
         if (canLog) {
-            const warning = chalk.keyword("orange");
-            Globals.cliLog(warning("WARNING:"), message);
+            if (Globals.log) {
+                Globals.log.warning(message);
+            } else {
+                const warning = chalk.keyword("orange");
+                Globals.cliLog(warning("WARNING:"), message);
+            }
         }
     }
 
@@ -106,13 +118,13 @@ export default class Globals {
 
     public static printDomainSummary(domain: DomainConfig): void {
         if (Globals.log) {
-            Globals.serverless.addServiceOutputSection('domain manager', [
+            Globals.serverless.addServiceOutputSection(Globals.pluginName, [
                 `domain name: ${domain.givenDomainName}`,
                 `target domain: ${domain.domainInfo.domainName}`,
                 `hosted zone id: ${domain.domainInfo.hostedZoneId}`
             ]);
         } else {
-            Globals.cliLog( chalk.yellow.underline("Summary:"), chalk.yellow("Distribution Domain Name"));
+            Globals.cliLog(chalk.yellow.underline("Summary:"), chalk.yellow("Distribution Domain Name"));
             Globals.cliLog("", `  Domain Name: ${domain.givenDomainName}`);
             Globals.cliLog("", `  Target Domain: ${domain.domainInfo.domainName}`);
             Globals.cliLog("", `  Hosted Zone Id: ${domain.domainInfo.hostedZoneId}`);
diff --git a/src/index.ts b/src/index.ts
index 51fa13c..09f86f4 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -139,12 +139,8 @@ class ServerlessCustomDomain {
 
             // Show warning if allowPathMatching is set to true
             if (domain.allowPathMatching) {
-                if (Globals.log) {
-                    Globals.log.warning(`"allowPathMatching" is set for ${domain.givenDomainName}. This should only be used when migrating a path to a different API type. e.g. REST to HTTP.`);
-                } else {
-                    Globals.logWarning(`"allowPathMatching" is set for ${domain.givenDomainName}.
-                        This should only be used when migrating a path to a different API type. e.g. REST to HTTP.`);
-                }
+                Globals.logWarning(`"allowPathMatching" is set for ${domain.givenDomainName}.
+                    This should only be used when migrating a path to a different API type. e.g. REST to HTTP.`);
             }
 
             if (domain.apiType === Globals.apiTypes.rest) {
@@ -199,24 +195,15 @@ class ServerlessCustomDomain {
                 domain.certificateArn = await this.getCertArn(domain);
                 await this.apiGatewayWrapper.createCustomDomain(domain);
             } else {
-                if (Globals.log) {
-                    Globals.log(`Custom domain ${domain.givenDomainName} already exists.`);
-                } else {
-                    Globals.logInfo(`Custom domain ${domain.givenDomainName} already exists.`);
-                }
+                Globals.logInfo(`Custom domain ${domain.givenDomainName} already exists.`);
             }
             await this.changeResourceRecordSet("UPSERT", domain);
-            if (Globals.log) {
-                Globals.log(`Custom domain ${domain.givenDomainName} was created. New domains may take up to 40 minutes to be initialized.`);
-            } else {
-                Globals.logInfo(
-                    `Custom domain ${domain.givenDomainName} was created. New domains may take up to 40 minutes to be initialized.`,
-                );
-            }
+            Globals.logInfo(
+                `Custom domain ${domain.givenDomainName} was created.
+                 New domains may take up to 40 minutes to be initialized.`
+            );
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Unable to create domain ${domain.givenDomainName}: ${err.message}`);
         } finally {
             if (creationProgress) {
@@ -246,22 +233,12 @@ class ServerlessCustomDomain {
                 await this.apiGatewayWrapper.deleteCustomDomain(domain);
                 await this.changeResourceRecordSet("DELETE", domain);
                 domain.domainInfo = undefined;
-                if (Globals.log) {
-                    Globals.log(`Custom domain ${domain.givenDomainName} was deleted.`);
-                } else {
-                    Globals.logInfo(`Custom domain ${domain.givenDomainName} was deleted.`);
-                }
+                Globals.logInfo(`Custom domain ${domain.givenDomainName} was deleted.`);
             } else {
-                if (Globals.log) {
-                    Globals.log(`Custom domain ${domain.givenDomainName} does not exist.`);
-                } else {
-                    Globals.logInfo(`Custom domain ${domain.givenDomainName} does not exist.`);
-                }
+                Globals.logInfo(`Custom domain ${domain.givenDomainName} does not exist.`);
             }
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Unable to delete domain ${domain.givenDomainName}`);
         }
     }
@@ -273,11 +250,7 @@ class ServerlessCustomDomain {
         await Promise.all(this.domains.map(async (domain) => {
             const autoDomain = domain.autoDomain;
             if (autoDomain === true) {
-                if (Globals.log) {
-                    Globals.log("Creating domain name before deploy.");
-                } else {
-                    Globals.logInfo("Creating domain name before deploy.");
-                }
+                Globals.logInfo("Creating domain name before deploy.");
                 await this.createDomain(domain);
             }
 
@@ -288,15 +261,11 @@ class ServerlessCustomDomain {
                 const maxWaitFor = parseInt(domain.autoDomainWaitFor, 10) || 120;
                 const pollInterval = 3;
                 for (let i = 0; i * pollInterval < maxWaitFor && atLeastOneDoesNotExist() === true; i++) {
-                    if (Globals.log) {
-                        Globals.log(`Poll #${i + 1}: polling every ${pollInterval} seconds for domain to exist or until ${maxWaitFor} seconds have elapsed before starting deployment`);
-                    } else {
-                        Globals.logInfo(`
-                            Poll #${i + 1}: polling every ${pollInterval} seconds
-                            for domain to exist or until ${maxWaitFor} seconds
-                            have elapsed before starting deployment
-                        `);
-                    }
+                    Globals.logInfo(`
+                        Poll #${i + 1}: polling every ${pollInterval} seconds
+                        for domain to exist or until ${maxWaitFor} seconds
+                        have elapsed before starting deployment
+                    `);
                     await sleep(pollInterval);
                     domain.domainInfo = await this.apiGatewayWrapper.getCustomDomainInfo(domain);
                 }
@@ -323,9 +292,7 @@ class ServerlessCustomDomain {
                 }
 
             } catch (err) {
-                if (!Globals.log) {
-                    Globals.logError(err, domain.givenDomainName);
-                }
+                Globals.logError(err, domain.givenDomainName);
                 throw new Error(`Unable to setup base domain mappings for ${domain.givenDomainName}`);
             }
         })).then(() => {
@@ -347,43 +314,27 @@ class ServerlessCustomDomain {
 
                 // Unable to find the corresponding API, manual clean up will be required
                 if (!domain.apiId) {
-                    if (Globals.log) {
-                        Globals.log(`Unable to find corresponding API for ${domain.givenDomainName}, API Mappings may need to be manually removed.`);
-                    } else {
-                        Globals.logInfo(`Unable to find corresponding API for ${domain.givenDomainName},
-                            API Mappings may need to be manually removed.`);
-                    }
+                    Globals.logInfo(`Unable to find corresponding API for ${domain.givenDomainName},
+                        API Mappings may need to be manually removed.`);
                 } else {
                     domain.apiMapping = await this.apiGatewayWrapper.getBasePathMapping(domain);
                     await this.apiGatewayWrapper.deleteBasePathMapping(domain);
                 }
             } catch (err) {
                 if (err.message.indexOf("Failed to find CloudFormation") > -1) {
-                    if (Globals.log) {
-                        Globals.log(`Unable to find Cloudformation Stack for ${domain.givenDomainName}, API Mappings may need to be manually removed.`);
-                    } else {
-                        Globals.logInfo(`Unable to find Cloudformation Stack for ${domain.givenDomainName},
-                            API Mappings may need to be manually removed.`);
-                    }
+                    Globals.logInfo(`Unable to find Cloudformation Stack for ${domain.givenDomainName},
+                        API Mappings may need to be manually removed.`);
                 } else {
-                    if (Globals.log) {
-                        Globals.log.error(`${domain.givenDomainName}: Unable to remove base path mappings: ${err}`);
-                    } else {
-                        Globals.logError(err, domain.givenDomainName);
-                        Globals.logError(
-                            `Unable to remove base path mappings`, domain.givenDomainName, false,
-                        );
-                    }
+                    Globals.logError(err, domain.givenDomainName);
+                    Globals.logError(
+                        `Unable to remove base path mappings`, domain.givenDomainName, false,
+                    );
                 }
             }
 
             const autoDomain = domain.autoDomain;
             if (autoDomain === true) {
-                if (Globals.log) {
-                    Globals.log("Deleting domain name after removing base path mapping.");
-                } else {
-                    Globals.logInfo("Deleting domain name after removing base path mapping.");
-                }
+                Globals.logInfo("Deleting domain name after removing base path mapping.");
                 await this.deleteDomain(domain);
             }
         }));
@@ -399,15 +350,9 @@ class ServerlessCustomDomain {
             if (domain.domainInfo) {
                 Globals.printDomainSummary(domain);
             } else {
-                if (Globals.log) {
-                    Globals.log(
-                        `Unable to print Serverless Domain Manager Summary for ${domain.givenDomainName}`,
-                    );
-                } else {
-                    Globals.logInfo(
-                        `Unable to print Serverless Domain Manager Summary for ${domain.givenDomainName}`,
-                    );
-                }
+                Globals.logInfo(
+                    `Unable to print ${Globals.pluginName} Summary for ${domain.givenDomainName}`,
+                );
             }
         }
     }
@@ -417,11 +362,7 @@ class ServerlessCustomDomain {
      */
     public async getCertArn(domain: DomainConfig): Promise<string> {
         if (domain.certificateArn) {
-            if (Globals.log) {
-                Globals.log(`Selected specific certificateArn ${domain.certificateArn}`);
-            } else {
-                Globals.logInfo(`Selected specific certificateArn ${domain.certificateArn}`);
-            }
+            Globals.logInfo(`Selected specific certificateArn ${domain.certificateArn}`);
             return domain.certificateArn;
         }
 
@@ -467,9 +408,7 @@ class ServerlessCustomDomain {
                 });
             }
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw Error(`Could not list certificates in Certificate Manager.\n${err}`);
         }
         if (certificateArn == null) {
@@ -490,11 +429,7 @@ class ServerlessCustomDomain {
         }
 
         if (domain.createRoute53Record === false) {
-            if (Globals.log) {
-                Globals.log(`Skipping ${action === "DELETE" ? "removal" : "creation"} of Route53 record.`);
-            } else {
-                Globals.logInfo(`Skipping ${action === "DELETE" ? "removal" : "creation"} of Route53 record.`);
-            }
+            Globals.logInfo(`Skipping ${action === "DELETE" ? "removal" : "creation"} of Route53 record.`);
             return;
         }
 
@@ -549,9 +484,7 @@ class ServerlessCustomDomain {
         try {
             await throttledCall(this.route53, "changeResourceRecordSets", params);
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Failed to ${action} A Alias for ${domain.givenDomainName}\n`);
         }
     }
@@ -561,27 +494,15 @@ class ServerlessCustomDomain {
      */
     public async getRoute53HostedZoneId(domain: DomainConfig): Promise<string> {
         if (domain.hostedZoneId) {
-            if (Globals.log) {
-                Globals.log(`Selected specific hostedZoneId ${domain.hostedZoneId}`);
-            } else {
-                Globals.logInfo(`Selected specific hostedZoneId ${domain.hostedZoneId}`);
-            }
+            Globals.logInfo(`Selected specific hostedZoneId ${domain.hostedZoneId}`);
             return domain.hostedZoneId;
         }
 
         const filterZone = domain.hostedZonePrivate !== undefined;
         if (filterZone && domain.hostedZonePrivate) {
-            if (Globals.log) {
-                Globals.log("Filtering to only private zones.");
-            } else {
-                Globals.logInfo("Filtering to only private zones.");
-            }
+            Globals.logInfo("Filtering to only private zones.");
         } else if (filterZone && !domain.hostedZonePrivate) {
-            if (Globals.log) {
-                Globals.log("Filtering to only public zones.");
-            } else {
-                Globals.logInfo("Filtering to only public zones.");
-            }
+            Globals.logInfo("Filtering to only public zones.");
         }
 
         let hostedZoneData;
@@ -623,9 +544,7 @@ class ServerlessCustomDomain {
                 return hostedZoneId.substring(startPos, endPos);
             }
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Unable to list hosted zones in Route53.\n${err}`);
         }
         throw new Error(`Could not find hosted zone "${domain.givenDomainName}"`);
@@ -641,11 +560,7 @@ class ServerlessCustomDomain {
         if (apiId) {
             // if string value exists return the value
             if (typeof apiId === "string") {
-                if (Globals.log) {
-                    Globals.log(`Mapping custom domain to existing API  ${apiId}.`);
-                } else {
-                    Globals.logInfo(`Mapping custom domain to existing API  ${apiId}.`);
-                }
+                Globals.logInfo(`Mapping custom domain to existing API  ${apiId}.`);
                 return apiId;
             }
             // in case object and Fn::ImportValue try to get restApiId from the CloudFormation exports
@@ -655,9 +570,7 @@ class ServerlessCustomDomain {
                 try {
                     importValues = await this.cloudFormationWrapper.getImportValues([importName]);
                 } catch (err) {
-                    if (!Globals.log) {
-                        Globals.logError(err, domain.givenDomainName);
-                    }
+                    Globals.logError(err, domain.givenDomainName);
                     throw new Error(`Failed to find CloudFormation ImportValue by ${importName}\n`);
                 }
                 if (!importValues[importName]) {
@@ -675,9 +588,7 @@ class ServerlessCustomDomain {
         try {
             return await this.cloudFormationWrapper.getApiId(domain, stackName);
         } catch (err) {
-            if (!Globals.log) {
-                Globals.logError(err, domain.givenDomainName);
-            }
+            Globals.logError(err, domain.givenDomainName);
             throw new Error(`Failed to find CloudFormation resources for ${domain.givenDomainName}\n`);
         }
     }


Test patch:
diff --git a/test/unit-tests/index.test.ts b/test/unit-tests/index.test.ts
index d9debbb..2442d09 100644
--- a/test/unit-tests/index.test.ts
+++ b/test/unit-tests/index.test.ts
@@ -1170,8 +1170,10 @@ describe("Custom Domain Plugin", () => {
             plugin.initAWSResources();
 
             await plugin.createDomains();
-            expect(consoleOutput[0]).to.contain(`Custom domain ${plugin.domains[0].givenDomainName} was created.
-                            New domains may take up to 40 minutes to be initialized.`);
+            expect(consoleOutput[0]).to.contains("test_domain does not exist")
+            expect(consoleOutput[1]).to.contains(
+                `Custom domain ${plugin.domains[0].givenDomainName} was created.`
+            );
         });
 
         it("Does not create domain if one existed before", async () => {
@@ -1456,7 +1458,7 @@ describe("Custom Domain Plugin", () => {
                 // check if distribution domain name is printed
             }).catch((err) => {
                 const expectedErrorMessage = `Unable to fetch information about test_domain`;
-                expect(err.message).to.equal(expectedErrorMessage);
+                expect(err.message).to.contains(expectedErrorMessage);
             });
         });