wiremock-rest-client
Advanced tools
Comparing version 1.0.2 to 1.1.0
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const loglevel_1 = __importDefault(require("loglevel")); | ||
const url_1 = require("url"); | ||
@@ -11,2 +15,4 @@ const MappingService_1 = require("../service/MappingService"); | ||
constructor(baseUri) { | ||
loglevel_1.default.getLogger('wiremock-rest-client') | ||
.setLevel(process.env.WRC_LOG_LEVEL || loglevel_1.default.levels.INFO); | ||
this.baseUri = url_1.resolve(baseUri, '__admin/'); | ||
@@ -13,0 +19,0 @@ } |
@@ -13,7 +13,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const log4js_api_1 = __importDefault(require("@log4js-node/log4js-api")); | ||
const loglevel_1 = __importDefault(require("loglevel")); | ||
const fs = __importStar(require("fs")); | ||
const path = __importStar(require("path")); | ||
const logger = log4js_api_1.default.getLogger('wiremock-rest-client'); | ||
logger.level = 'info'; | ||
const logger = loglevel_1.default.getLogger('wiremock-rest-client'); | ||
class FileUtil { | ||
@@ -25,3 +24,3 @@ static getFileContent(fileName) { | ||
catch (error) { | ||
logger.error(`Error: ${error}`); | ||
logger.error(`[ERROR] ${error}`); | ||
return process.exit(1); | ||
@@ -44,3 +43,3 @@ } | ||
catch (error) { | ||
logger.error(`Error: ${error}`); | ||
logger.error(`[ERROR] ${error}`); | ||
return process.exit(1); | ||
@@ -47,0 +46,0 @@ } |
@@ -15,7 +15,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const log4js_api_1 = __importDefault(require("@log4js-node/log4js-api")); | ||
const loglevel_1 = __importDefault(require("loglevel")); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const v4_1 = __importDefault(require("uuid/v4")); | ||
const logger = log4js_api_1.default.getLogger('wiremock-rest-client'); | ||
logger.level = 'info'; | ||
const logger = loglevel_1.default.getLogger('wiremock-rest-client'); | ||
class HttpUtil { | ||
@@ -27,5 +26,5 @@ static fetch(uri, options) { | ||
try { | ||
logger.info(`[${id}] Request: [${allOptions.method}] ${uri}`); | ||
logger.info(`[${id}] [INFO] Request: [${allOptions.method}] ${uri}`); | ||
if (allOptions.body !== undefined) { | ||
logger.debug(`[${id}] Request body: ${allOptions.body}`); | ||
logger.debug(`[${id}] [DEBUG] Request body: ${allOptions.body}`); | ||
} | ||
@@ -36,3 +35,3 @@ const response = yield node_fetch_1.default(uri, allOptions); | ||
catch (error) { | ||
logger.error(`[${id}] Error: ${error.message}`); | ||
logger.error(`[${id}] [ERROR] Error: ${error.message}`); | ||
return process.exit(1); | ||
@@ -46,6 +45,6 @@ } | ||
if (!response.ok) { | ||
logger.error(`[${id}] ${responseLog}`); | ||
logger.error(`[${id}] [ERROR] ${responseLog}`); | ||
return process.exit(1); | ||
} | ||
logger.info(`[${id}] ${responseLog}`); | ||
logger.info(`[${id}] [INFO] ${responseLog}`); | ||
const responseText = yield response.text(); | ||
@@ -52,0 +51,0 @@ try { |
{ | ||
"name": "wiremock-rest-client", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Lightweight REST client to interact with a running WireMock server", | ||
@@ -28,4 +28,11 @@ "main": "dist/index.js", | ||
"homepage": "https://github.com/kwoding/wiremock-rest-client#readme", | ||
"keywords": [ | ||
"wiremock", | ||
"mock", | ||
"stub", | ||
"automation", | ||
"test" | ||
], | ||
"dependencies": { | ||
"@log4js-node/log4js-api": "^1.0.2", | ||
"loglevel": "1.6.6", | ||
"node-fetch": "2.6.0", | ||
@@ -32,0 +39,0 @@ "uuid": "^3.3.3" |
@@ -137,3 +137,2 @@ # WireMock REST Client | ||
## Logging | ||
- Logging is based on `log4js` | ||
- Default log level is `info` | ||
@@ -143,21 +142,11 @@ - Each log line contains a unique id to trace logs for a single request | ||
To enable logging, install [log4js](https://www.npmjs.com/package/log4js) in your project. | ||
A different log level can be configured by setting the environment variable `WRC_LOG_LEVEL` to specific a log level (`trace`/`debug`/`info`/`warn`/`error`/`silent`) | ||
A different log level can be configured as follows. | ||
```js | ||
import log4js from 'log4js'; | ||
const logger log4js.getLogger('wiremock-rest-client'); | ||
logger.level = 'debug'; | ||
``` | ||
**Example:** | ||
```shell | ||
[2019-11-01T15:57:11.285] [INFO] wiremock-rest-client - [c47e4ee8-6e24-43a8-8fe0-bb0c60c847b7] Request: [POST] http://localhost:8080/__admin/mappings | ||
[2019-11-01T15:57:11.285] [DEBUG] wiremock-rest-client - [c47e4ee8-6e24-43a8-8fe0-bb0c60c847b7] Request body: {"request":{"method":"GET","urlPathPattern":"/api/helloworld"},"response":{"status":200,"jsonBody":{"hello":"world"},"headers":{"Content-Type":"application/json"}}} | ||
[2019-11-01T15:57:11.301] [INFO] wiremock-rest-client - [c47e4ee8-6e24-43a8-8fe0-bb0c60c847b7] Response: [201] Created | ||
[2019-11-01T15:57:11.292] [INFO] wiremock-rest-client - [c3690603-c055-4412-a5b0-497704c09dd0] Request: [POST] http://localhost:8080/__admin/shutdown | ||
[2019-11-01T15:57:11.299] [INFO] wiremock-rest-client - [c3690603-c055-4412-a5b0-497704c09dd0] Response: [200] OK | ||
[10f7dcb9-b8a3-4598-8751-40edb0bd5d2e] [INFO] Request: [POST] http://localhost:8080/__admin/mappings | ||
[10f7dcb9-b8a3-4598-8751-40edb0bd5d2e] [DEBUG] Request body: {"request":{"method":"GET","urlPathPattern":"/api/helloworld"},"response":{"status":200,"jsonBody":{"hello":"world"},"headers":{"Content-Type":"application/json"}}} | ||
[10f7dcb9-b8a3-4598-8751-40edb0bd5d2e] [INFO] Response: [201] Created | ||
[c3690603-c055-4412-a5b0-497704c09dd0] [INFO] Request: [POST] http://localhost:8080/__admin/shutdown | ||
[c3690603-c055-4412-a5b0-497704c09dd0] [INFO] Response: [200] OK | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1291
51261
150
2
+ Addedloglevel@1.6.6
+ Addedloglevel@1.6.6(transitive)
- Removed@log4js-node/log4js-api@^1.0.2
- Removed@log4js-node/log4js-api@1.0.2(transitive)