ibm-cloud-sdk-core 3.0.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [3.2.0](https://github.com/IBM/node-sdk-core/compare/v3.1.0...v3.2.0) (2022-10-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * add method `getNewLogger` to public API ([#210](https://github.com/IBM/node-sdk-core/issues/210)) ([07b99de](https://github.com/IBM/node-sdk-core/commit/07b99def47a0eb5fcb1ab3d88b2eb3bd271b8819))
7
+
8
+ # [3.1.0](https://github.com/IBM/node-sdk-core/compare/v3.0.1...v3.1.0) (2022-07-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * add `setDefaultHeaders` method on base service class ([#207](https://github.com/IBM/node-sdk-core/issues/207)) ([29bec13](https://github.com/IBM/node-sdk-core/commit/29bec13b67ea08071be488af62b919899f21ec50))
14
+
1
15
  ## [3.0.1](https://github.com/IBM/node-sdk-core/compare/v3.0.0...v3.0.1) (2022-07-28)
2
16
 
3
17
 
@@ -38,6 +38,7 @@ export declare class BaseService
38
38
  | [enableRetries(retryOptions)](./ibm-cloud-sdk-core.baseservice.enableretries.md) | | Enable retries for unfulfilled requests. |
39
39
  | [getAuthenticator()](./ibm-cloud-sdk-core.baseservice.getauthenticator.md) | | Get the instance of the authenticator set on the service. |
40
40
  | [getHttpClient()](./ibm-cloud-sdk-core.baseservice.gethttpclient.md) | | Get the Axios instance set on the service. All requests will be made using this instance. |
41
+ | [setDefaultHeaders(headers)](./ibm-cloud-sdk-core.baseservice.setdefaultheaders.md) | | Set the HTTP headers to be sent in every request. |
41
42
  | [setEnableGzipCompression(setting)](./ibm-cloud-sdk-core.baseservice.setenablegzipcompression.md) | | Turn request body compression on or off. |
42
43
  | [setServiceUrl(url)](./ibm-cloud-sdk-core.baseservice.setserviceurl.md) | | Set the service URL to send requests to. |
43
44
 
@@ -0,0 +1,24 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [BaseService](./ibm-cloud-sdk-core.baseservice.md) &gt; [setDefaultHeaders](./ibm-cloud-sdk-core.baseservice.setdefaultheaders.md)
4
+
5
+ ## BaseService.setDefaultHeaders() method
6
+
7
+ Set the HTTP headers to be sent in every request.
8
+
9
+ <b>Signature:</b>
10
+
11
+ ```typescript
12
+ setDefaultHeaders(headers: OutgoingHttpHeaders): void;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | headers | OutgoingHttpHeaders | The map of headers to include in requests. |
20
+
21
+ <b>Returns:</b>
22
+
23
+ void
24
+
@@ -0,0 +1,30 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [getNewLogger](./ibm-cloud-sdk-core.getnewlogger.md)
4
+
5
+ ## getNewLogger() function
6
+
7
+ Return a new logger, formatted with a particular name. The logging functions, in order of increasing verbosity, are: `error`<!-- -->, `warn`<!-- -->, `info`<!-- -->, `verbose`<!-- -->, and `debug`<!-- -->.
8
+
9
+ The logger will be an instance of the `debug` package and utilizes its support for configuration with environment variables.
10
+
11
+ Additionally, the logger will be turned on automatically if the "NODE\_DEBUG" environment variable is set to "axios".
12
+
13
+ <b>Signature:</b>
14
+
15
+ ```typescript
16
+ export declare function getNewLogger(moduleName: string): SDKLogger;
17
+ ```
18
+
19
+ ## Parameters
20
+
21
+ | Parameter | Type | Description |
22
+ | --- | --- | --- |
23
+ | moduleName | string | the namespace for the logger. The name will appear in the logs and it will be the name used for configuring the log level. |
24
+
25
+ <b>Returns:</b>
26
+
27
+ [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md)
28
+
29
+ {<!-- -->SDKLogger<!-- -->} the new logger
30
+
@@ -44,6 +44,7 @@
44
44
  | [getCurrentTime()](./ibm-cloud-sdk-core.getcurrenttime.md) | Get the current time |
45
45
  | [getFormat(params, formats)](./ibm-cloud-sdk-core.getformat.md) | Returns the first match from formats that is key the params map otherwise null |
46
46
  | [getMissingParams(params, requires)](./ibm-cloud-sdk-core.getmissingparams.md) | Validates that all required params are provided |
47
+ | [getNewLogger(moduleName)](./ibm-cloud-sdk-core.getnewlogger.md) | Return a new logger, formatted with a particular name. The logging functions, in order of increasing verbosity, are: <code>error</code>, <code>warn</code>, <code>info</code>, <code>verbose</code>, and <code>debug</code>.<!-- -->The logger will be an instance of the <code>debug</code> package and utilizes its support for configuration with environment variables.<!-- -->Additionally, the logger will be turned on automatically if the "NODE\_DEBUG" environment variable is set to "axios". |
47
48
  | [getQueryParam(urlStr, param)](./ibm-cloud-sdk-core.getqueryparam.md) | Return a query parameter value from a URL |
48
49
  | [isEmptyObject(obj)](./ibm-cloud-sdk-core.isemptyobject.md) | |
49
50
  | [isFileData(obj)](./ibm-cloud-sdk-core.isfiledata.md) | |
@@ -70,6 +71,7 @@
70
71
  | [FileStream](./ibm-cloud-sdk-core.filestream.md) | |
71
72
  | [FileWithMetadata](./ibm-cloud-sdk-core.filewithmetadata.md) | |
72
73
  | [IamRequestOptions](./ibm-cloud-sdk-core.iamrequestoptions.md) | Configuration options for IAM token retrieval. |
74
+ | [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md) | |
73
75
  | [UserOptions](./ibm-cloud-sdk-core.useroptions.md) | Configuration values for a service. |
74
76
 
75
77
  ## Namespaces
@@ -0,0 +1,11 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md) &gt; [debug](./ibm-cloud-sdk-core.sdklogger.debug.md)
4
+
5
+ ## SDKLogger.debug property
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ debug: Debugger;
11
+ ```
@@ -0,0 +1,11 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md) &gt; [error](./ibm-cloud-sdk-core.sdklogger.error.md)
4
+
5
+ ## SDKLogger.error property
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ error: Debugger;
11
+ ```
@@ -0,0 +1,11 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md) &gt; [info](./ibm-cloud-sdk-core.sdklogger.info.md)
4
+
5
+ ## SDKLogger.info property
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ info: Debugger;
11
+ ```
@@ -0,0 +1,22 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md)
4
+
5
+ ## SDKLogger interface
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ export interface SDKLogger
11
+ ```
12
+
13
+ ## Properties
14
+
15
+ | Property | Type | Description |
16
+ | --- | --- | --- |
17
+ | [debug](./ibm-cloud-sdk-core.sdklogger.debug.md) | Debugger | |
18
+ | [error](./ibm-cloud-sdk-core.sdklogger.error.md) | Debugger | |
19
+ | [info](./ibm-cloud-sdk-core.sdklogger.info.md) | Debugger | |
20
+ | [verbose](./ibm-cloud-sdk-core.sdklogger.verbose.md) | Debugger | |
21
+ | [warn](./ibm-cloud-sdk-core.sdklogger.warn.md) | Debugger | |
22
+
@@ -0,0 +1,11 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md) &gt; [verbose](./ibm-cloud-sdk-core.sdklogger.verbose.md)
4
+
5
+ ## SDKLogger.verbose property
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ verbose: Debugger;
11
+ ```
@@ -0,0 +1,11 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [SDKLogger](./ibm-cloud-sdk-core.sdklogger.md) &gt; [warn](./ibm-cloud-sdk-core.sdklogger.warn.md)
4
+
5
+ ## SDKLogger.warn property
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ warn: Debugger;
11
+ ```
@@ -1088,6 +1088,53 @@
1088
1088
  "parameters": [],
1089
1089
  "name": "getHttpClient"
1090
1090
  },
1091
+ {
1092
+ "kind": "Method",
1093
+ "canonicalReference": "ibm-cloud-sdk-core!BaseService#setDefaultHeaders:member(1)",
1094
+ "docComment": "/**\n * Set the HTTP headers to be sent in every request.\n *\n * @param headers - The map of headers to include in requests.\n */\n",
1095
+ "excerptTokens": [
1096
+ {
1097
+ "kind": "Content",
1098
+ "text": "setDefaultHeaders(headers: "
1099
+ },
1100
+ {
1101
+ "kind": "Reference",
1102
+ "text": "OutgoingHttpHeaders",
1103
+ "canonicalReference": "!\"\\\"http\\\"\".OutgoingHttpHeaders:interface"
1104
+ },
1105
+ {
1106
+ "kind": "Content",
1107
+ "text": "): "
1108
+ },
1109
+ {
1110
+ "kind": "Content",
1111
+ "text": "void"
1112
+ },
1113
+ {
1114
+ "kind": "Content",
1115
+ "text": ";"
1116
+ }
1117
+ ],
1118
+ "isOptional": false,
1119
+ "isStatic": false,
1120
+ "returnTypeTokenRange": {
1121
+ "startIndex": 3,
1122
+ "endIndex": 4
1123
+ },
1124
+ "releaseTag": "Public",
1125
+ "overloadIndex": 1,
1126
+ "parameters": [
1127
+ {
1128
+ "parameterName": "headers",
1129
+ "parameterTypeTokenRange": {
1130
+ "startIndex": 1,
1131
+ "endIndex": 2
1132
+ },
1133
+ "isOptional": false
1134
+ }
1135
+ ],
1136
+ "name": "setDefaultHeaders"
1137
+ },
1091
1138
  {
1092
1139
  "kind": "Method",
1093
1140
  "canonicalReference": "ibm-cloud-sdk-core!BaseService#setEnableGzipCompression:member(1)",
@@ -3355,6 +3402,51 @@
3355
3402
  ],
3356
3403
  "name": "getMissingParams"
3357
3404
  },
3405
+ {
3406
+ "kind": "Function",
3407
+ "canonicalReference": "ibm-cloud-sdk-core!getNewLogger:function(1)",
3408
+ "docComment": "/**\n * Return a new logger, formatted with a particular name. The logging functions, in order of increasing verbosity, are: `error`, `warn`, `info`, `verbose`, and `debug`.\n *\n * The logger will be an instance of the `debug` package and utilizes its support for configuration with environment variables.\n *\n * Additionally, the logger will be turned on automatically if the \"NODE_DEBUG\" environment variable is set to \"axios\".\n *\n * @param moduleName - the namespace for the logger. The name will appear in the logs and it will be the name used for configuring the log level.\n *\n * @returns {SDKLogger} the new logger\n */\n",
3409
+ "excerptTokens": [
3410
+ {
3411
+ "kind": "Content",
3412
+ "text": "export declare function getNewLogger(moduleName: "
3413
+ },
3414
+ {
3415
+ "kind": "Content",
3416
+ "text": "string"
3417
+ },
3418
+ {
3419
+ "kind": "Content",
3420
+ "text": "): "
3421
+ },
3422
+ {
3423
+ "kind": "Reference",
3424
+ "text": "SDKLogger",
3425
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger:interface"
3426
+ },
3427
+ {
3428
+ "kind": "Content",
3429
+ "text": ";"
3430
+ }
3431
+ ],
3432
+ "returnTypeTokenRange": {
3433
+ "startIndex": 3,
3434
+ "endIndex": 4
3435
+ },
3436
+ "releaseTag": "Public",
3437
+ "overloadIndex": 1,
3438
+ "parameters": [
3439
+ {
3440
+ "parameterName": "moduleName",
3441
+ "parameterTypeTokenRange": {
3442
+ "startIndex": 1,
3443
+ "endIndex": 2
3444
+ },
3445
+ "isOptional": false
3446
+ }
3447
+ ],
3448
+ "name": "getNewLogger"
3449
+ },
3358
3450
  {
3359
3451
  "kind": "Function",
3360
3452
  "canonicalReference": "ibm-cloud-sdk-core!getQueryParam:function(1)",
@@ -5196,6 +5288,157 @@
5196
5288
  ],
5197
5289
  "name": "removeSuffix"
5198
5290
  },
5291
+ {
5292
+ "kind": "Interface",
5293
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger:interface",
5294
+ "docComment": "",
5295
+ "excerptTokens": [
5296
+ {
5297
+ "kind": "Content",
5298
+ "text": "export interface SDKLogger "
5299
+ }
5300
+ ],
5301
+ "releaseTag": "Public",
5302
+ "name": "SDKLogger",
5303
+ "members": [
5304
+ {
5305
+ "kind": "PropertySignature",
5306
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger#debug:member",
5307
+ "docComment": "",
5308
+ "excerptTokens": [
5309
+ {
5310
+ "kind": "Content",
5311
+ "text": "debug: "
5312
+ },
5313
+ {
5314
+ "kind": "Reference",
5315
+ "text": "Debugger",
5316
+ "canonicalReference": "@types/debug!~debug.Debugger:interface"
5317
+ },
5318
+ {
5319
+ "kind": "Content",
5320
+ "text": ";"
5321
+ }
5322
+ ],
5323
+ "isOptional": false,
5324
+ "releaseTag": "Public",
5325
+ "name": "debug",
5326
+ "propertyTypeTokenRange": {
5327
+ "startIndex": 1,
5328
+ "endIndex": 2
5329
+ }
5330
+ },
5331
+ {
5332
+ "kind": "PropertySignature",
5333
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger#error:member",
5334
+ "docComment": "",
5335
+ "excerptTokens": [
5336
+ {
5337
+ "kind": "Content",
5338
+ "text": "error: "
5339
+ },
5340
+ {
5341
+ "kind": "Reference",
5342
+ "text": "Debugger",
5343
+ "canonicalReference": "@types/debug!~debug.Debugger:interface"
5344
+ },
5345
+ {
5346
+ "kind": "Content",
5347
+ "text": ";"
5348
+ }
5349
+ ],
5350
+ "isOptional": false,
5351
+ "releaseTag": "Public",
5352
+ "name": "error",
5353
+ "propertyTypeTokenRange": {
5354
+ "startIndex": 1,
5355
+ "endIndex": 2
5356
+ }
5357
+ },
5358
+ {
5359
+ "kind": "PropertySignature",
5360
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger#info:member",
5361
+ "docComment": "",
5362
+ "excerptTokens": [
5363
+ {
5364
+ "kind": "Content",
5365
+ "text": "info: "
5366
+ },
5367
+ {
5368
+ "kind": "Reference",
5369
+ "text": "Debugger",
5370
+ "canonicalReference": "@types/debug!~debug.Debugger:interface"
5371
+ },
5372
+ {
5373
+ "kind": "Content",
5374
+ "text": ";"
5375
+ }
5376
+ ],
5377
+ "isOptional": false,
5378
+ "releaseTag": "Public",
5379
+ "name": "info",
5380
+ "propertyTypeTokenRange": {
5381
+ "startIndex": 1,
5382
+ "endIndex": 2
5383
+ }
5384
+ },
5385
+ {
5386
+ "kind": "PropertySignature",
5387
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger#verbose:member",
5388
+ "docComment": "",
5389
+ "excerptTokens": [
5390
+ {
5391
+ "kind": "Content",
5392
+ "text": "verbose: "
5393
+ },
5394
+ {
5395
+ "kind": "Reference",
5396
+ "text": "Debugger",
5397
+ "canonicalReference": "@types/debug!~debug.Debugger:interface"
5398
+ },
5399
+ {
5400
+ "kind": "Content",
5401
+ "text": ";"
5402
+ }
5403
+ ],
5404
+ "isOptional": false,
5405
+ "releaseTag": "Public",
5406
+ "name": "verbose",
5407
+ "propertyTypeTokenRange": {
5408
+ "startIndex": 1,
5409
+ "endIndex": 2
5410
+ }
5411
+ },
5412
+ {
5413
+ "kind": "PropertySignature",
5414
+ "canonicalReference": "ibm-cloud-sdk-core!SDKLogger#warn:member",
5415
+ "docComment": "",
5416
+ "excerptTokens": [
5417
+ {
5418
+ "kind": "Content",
5419
+ "text": "warn: "
5420
+ },
5421
+ {
5422
+ "kind": "Reference",
5423
+ "text": "Debugger",
5424
+ "canonicalReference": "@types/debug!~debug.Debugger:interface"
5425
+ },
5426
+ {
5427
+ "kind": "Content",
5428
+ "text": ";"
5429
+ }
5430
+ ],
5431
+ "isOptional": false,
5432
+ "releaseTag": "Public",
5433
+ "name": "warn",
5434
+ "propertyTypeTokenRange": {
5435
+ "startIndex": 1,
5436
+ "endIndex": 2
5437
+ }
5438
+ }
5439
+ ],
5440
+ "extendsTokenRanges": []
5441
+ },
5199
5442
  {
5200
5443
  "kind": "Function",
5201
5444
  "canonicalReference": "ibm-cloud-sdk-core!streamToPromise:function(1)",
package/es/index.d.ts CHANGED
@@ -24,3 +24,4 @@ export { default as qs } from './lib/querystring';
24
24
  export { default as contentType } from './lib/content-type';
25
25
  export * from './lib/stream-to-promise';
26
26
  export { unitTestUtils };
27
+ export { getNewLogger, SDKLogger } from './lib/get-new-logger';
package/es/index.js CHANGED
@@ -24,3 +24,4 @@ export { default as qs } from './lib/querystring';
24
24
  export { default as contentType } from './lib/content-type';
25
25
  export * from './lib/stream-to-promise';
26
26
  export { unitTestUtils };
27
+ export { getNewLogger } from './lib/get-new-logger';
@@ -87,6 +87,12 @@ export declare class BaseService {
87
87
  * @param {string} url The base URL for the service.
88
88
  */
89
89
  setServiceUrl(url: string): void;
90
+ /**
91
+ * Set the HTTP headers to be sent in every request.
92
+ *
93
+ * @param {OutgoingHttpHeaders} headers The map of headers to include in requests.
94
+ */
95
+ setDefaultHeaders(headers: OutgoingHttpHeaders): void;
90
96
  /**
91
97
  * Turn request body compression on or off.
92
98
  *
@@ -90,6 +90,18 @@ export class BaseService {
90
90
  this.baseOptions.serviceUrl = stripTrailingSlash(url);
91
91
  }
92
92
  }
93
+ /**
94
+ * Set the HTTP headers to be sent in every request.
95
+ *
96
+ * @param {OutgoingHttpHeaders} headers The map of headers to include in requests.
97
+ */
98
+ setDefaultHeaders(headers) {
99
+ if (typeof headers !== 'object') {
100
+ // do nothing, for now
101
+ return;
102
+ }
103
+ this.baseOptions.headers = headers;
104
+ }
93
105
  /**
94
106
  * Turn request body compression on or off.
95
107
  *
@@ -0,0 +1,39 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2022.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Debugger } from 'debug';
17
+ export interface SDKLogger {
18
+ error: Debugger;
19
+ warn: Debugger;
20
+ info: Debugger;
21
+ verbose: Debugger;
22
+ debug: Debugger;
23
+ }
24
+ /**
25
+ * Return a new logger, formatted with a particular name. The logging functions, in
26
+ * order of increasing verbosity, are: `error`, `warn`, `info`, `verbose`, and `debug`.
27
+ *
28
+ * The logger will be an instance of the `debug` package and utilizes its support for
29
+ * configuration with environment variables.
30
+ *
31
+ * Additionally, the logger will be turned on automatically if the "NODE_DEBUG"
32
+ * environment variable is set to "axios".
33
+ *
34
+ * @param {string} moduleName - the namespace for the logger. The name will appear in
35
+ * the logs and it will be the name used for configuring the log level.
36
+ *
37
+ * @returns {SDKLogger} the new logger
38
+ */
39
+ export declare function getNewLogger(moduleName: string): SDKLogger;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2022.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import logger from 'debug';
17
+ /**
18
+ * Return a new logger, formatted with a particular name. The logging functions, in
19
+ * order of increasing verbosity, are: `error`, `warn`, `info`, `verbose`, and `debug`.
20
+ *
21
+ * The logger will be an instance of the `debug` package and utilizes its support for
22
+ * configuration with environment variables.
23
+ *
24
+ * Additionally, the logger will be turned on automatically if the "NODE_DEBUG"
25
+ * environment variable is set to "axios".
26
+ *
27
+ * @param {string} moduleName - the namespace for the logger. The name will appear in
28
+ * the logs and it will be the name used for configuring the log level.
29
+ *
30
+ * @returns {SDKLogger} the new logger
31
+ */
32
+ export function getNewLogger(moduleName) {
33
+ const debug = logger(`${moduleName}:debug`);
34
+ const error = logger(`${moduleName}:error`);
35
+ const info = logger(`${moduleName}:info`);
36
+ const verbose = logger(`${moduleName}:verbose`);
37
+ const warn = logger(`${moduleName}:warning`);
38
+ // enable loggers if axios flag is set & mimic log levels severity
39
+ if (process.env.NODE_DEBUG === 'axios') {
40
+ debug.enabled = true;
41
+ }
42
+ if (debug.enabled) {
43
+ verbose.enabled = true;
44
+ }
45
+ if (verbose.enabled) {
46
+ info.enabled = true;
47
+ }
48
+ if (info.enabled) {
49
+ warn.enabled = true;
50
+ }
51
+ if (warn.enabled) {
52
+ error.enabled = true;
53
+ }
54
+ const newLogger = {
55
+ debug,
56
+ error,
57
+ info,
58
+ verbose,
59
+ warn,
60
+ };
61
+ return newLogger;
62
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2021.
2
+ * (C) Copyright IBM Corp. 2019, 2022.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,12 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import logger from 'debug';
17
- declare const _default: {
18
- debug: logger.Debugger;
19
- error: logger.Debugger;
20
- info: logger.Debugger;
21
- verbose: logger.Debugger;
22
- warn: logger.Debugger;
23
- };
16
+ declare const _default: import("./get-new-logger").SDKLogger;
24
17
  export default _default;
package/es/lib/logger.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2021.
2
+ * (C) Copyright IBM Corp. 2019, 2022.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,33 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import logger from 'debug';
17
- const debug = logger('ibm-cloud-sdk-core:debug');
18
- const error = logger('ibm-cloud-sdk-core:error');
19
- const info = logger('ibm-cloud-sdk-core:info');
20
- const verbose = logger('ibm-cloud-sdk-core:verbose');
21
- const warn = logger('ibm-cloud-sdk-core:warning');
22
- // enable loggers if axios flag is set & mimic log levels severity
23
- if (process.env.NODE_DEBUG === 'axios') {
24
- debug.enabled = true;
25
- }
26
- if (debug.enabled) {
27
- verbose.enabled = true;
28
- }
29
- if (verbose.enabled) {
30
- info.enabled = true;
31
- }
32
- if (info.enabled) {
33
- warn.enabled = true;
34
- }
35
- if (warn.enabled) {
36
- error.enabled = true;
37
- }
38
- // export loggers;
39
- export default {
40
- debug,
41
- error,
42
- info,
43
- verbose,
44
- warn,
45
- };
16
+ import { getNewLogger } from './get-new-logger';
17
+ export default getNewLogger('ibm-cloud-sdk-core');