scharff 1.0.0 → 1.3.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/README.md +25 -5
- package/index.js +14 -1
- package/package.json +18 -3
package/README.md
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
# Scharff Logger
|
|
2
|
-
|
|
3
|
-
The project is using the fetch-intercept NPM package.
|
|
2
|
+
Scharff is a lightweight and versatile Node.js package designed to enhance your application's logging capabilities by seamlessly integrating a powerful outgoing request logger. With Scharff, you can effortlessly gain insights into the interactions your application has with external services, APIs, and resources.
|
|
4
3
|
|
|
5
4
|
## Installation
|
|
6
5
|
1) run `npm install scharff`.
|
|
7
6
|
2) fork the git repository `https://github.com/Minka1902/scharff.git`, and place it next to your project.
|
|
8
7
|
|
|
9
8
|
## Usage
|
|
10
|
-
1) in your entry point, import unregister from the package: `const { unregister } = require('
|
|
11
|
-
2) to stop the logger just run the unregister function: `unregister()`
|
|
9
|
+
1) in your entry point, import unregister from the package: `const { unregister } = require('scharff');`
|
|
10
|
+
2) to stop the logger just run the unregister function: `unregister()`, or `npm uninstall scharff`.
|
|
12
11
|
|
|
13
12
|
## What to expect
|
|
14
|
-
The package will create a outgoingRequest.log file and start logging the requests to the file.
|
|
13
|
+
1) The package will create a outgoingRequest.log file and start logging the requests to the file.
|
|
14
|
+
2) In there you can see the fetch requests you sent.
|
|
15
|
+
3) The request will be in the format below:</br>
|
|
16
|
+
{</br>
|
|
17
|
+
"url":"http://www.example.com/update/ad423kbr1om82hu3d58a73g4",</br>
|
|
18
|
+
"originUrl":"/update/ad423kbr1om82hu3d58a73g4",</br>
|
|
19
|
+
"method":"GET",</br>
|
|
20
|
+
"headers": </br>
|
|
21
|
+
{</br>
|
|
22
|
+
"Content-Type":"application/json",</br>
|
|
23
|
+
"Access-Control-Allow-Origin":"*"</br>
|
|
24
|
+
},</br>
|
|
25
|
+
"body": </br>
|
|
26
|
+
{</br>
|
|
27
|
+
"isActive":true,</br>
|
|
28
|
+
"status":200,</br>
|
|
29
|
+
"date":"2023-08-21T11:25:47.023Z"</br>
|
|
30
|
+
}</br>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
## Next release
|
|
34
|
+
1)
|
|
15
35
|
|
|
16
36
|
## Future additions
|
|
17
37
|
1) We will add a request error logger.
|
package/index.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
const fetchIntercept = require('fetch-intercept');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const { removeBaseUrl } = require('./constants/functions');
|
|
4
|
+
const os = require('os');
|
|
4
5
|
|
|
5
6
|
module.exports.unregister = fetchIntercept.register({
|
|
6
7
|
request: function (url, config) {
|
|
8
|
+
const interfaces = os.networkInterfaces();
|
|
9
|
+
let addresses = [];
|
|
7
10
|
let tempUrl = url;
|
|
11
|
+
for (let i in interfaces) {
|
|
12
|
+
for (var i2 in interfaces[i]) {
|
|
13
|
+
var address = interfaces[i][i2];
|
|
14
|
+
if (address.family === 'IPv4' && !address.internal) {
|
|
15
|
+
addresses.push(address.address);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let tempReq = { url, ip: addresses[0] };
|
|
20
|
+
let date = new Date().toLocaleString();
|
|
21
|
+
tempReq.date = date;
|
|
8
22
|
tempUrl = removeBaseUrl(tempUrl);
|
|
9
|
-
let tempReq = { url };
|
|
10
23
|
if (tempUrl !== url) {
|
|
11
24
|
tempReq.originUrl = tempUrl;
|
|
12
25
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scharff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Logger for outgoing requests",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"logger",
|
|
11
|
+
"outgoing",
|
|
12
|
+
"request",
|
|
13
|
+
"response",
|
|
14
|
+
"error",
|
|
15
|
+
"fetch",
|
|
16
|
+
"fetch-inspector",
|
|
17
|
+
"inspector",
|
|
18
|
+
"scharff",
|
|
19
|
+
"npm"
|
|
20
|
+
],
|
|
9
21
|
"repository": {
|
|
10
22
|
"type": "git",
|
|
11
23
|
"url": "https://github.com/Minka1902/scharff.git"
|
|
12
24
|
},
|
|
13
|
-
"author":
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Michael Scharff",
|
|
27
|
+
"email": "minka.scharff@gmail.com"
|
|
28
|
+
},
|
|
14
29
|
"license": "ISC",
|
|
15
30
|
"dependencies": {
|
|
16
31
|
"fetch-intercept": "^2.4.0"
|
|
17
32
|
}
|
|
18
|
-
}
|
|
33
|
+
}
|