http-system-logger 1.0.8 → 1.0.10
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/dist/morgan.config.js +13 -4
- package/package.json +4 -3
package/dist/morgan.config.js
CHANGED
|
@@ -29,11 +29,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const morgan_1 = __importDefault(require("morgan"));
|
|
30
30
|
const winston_config_1 = require("./winston.config");
|
|
31
31
|
const uuid = __importStar(require("uuid"));
|
|
32
|
-
const
|
|
32
|
+
const ignoredRoutesRaw = (process.env.IGNORED_ROUTES || '/api/health')
|
|
33
33
|
.split(',')
|
|
34
|
-
.map((route) => route.trim());
|
|
34
|
+
.map((route) => route.trim());
|
|
35
|
+
const ignoredRoutesExact = ignoredRoutesRaw.filter(route => !route.includes('*'));
|
|
36
|
+
const ignoredRoutesRegex = ignoredRoutesRaw
|
|
37
|
+
.filter(route => route.includes('*'))
|
|
38
|
+
.map(route => new RegExp('^' + route.replace(/\*/g, '.*') + '$'));
|
|
39
|
+
function isIgnoredRoute(path) {
|
|
40
|
+
if (ignoredRoutesExact.includes(path))
|
|
41
|
+
return true;
|
|
42
|
+
return ignoredRoutesRegex.some(regex => regex.test(path));
|
|
43
|
+
}
|
|
35
44
|
const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
|
|
36
|
-
if (
|
|
45
|
+
if (isIgnoredRoute(req.path)) {
|
|
37
46
|
return null; // Skip logging for ignored routes
|
|
38
47
|
}
|
|
39
48
|
return JSON.stringify({
|
|
@@ -43,7 +52,7 @@ const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
|
|
|
43
52
|
content_length: tokens.res(req, res, 'content-length'),
|
|
44
53
|
response_time: Number.parseFloat(tokens['response-time'](req, res)),
|
|
45
54
|
http_version: tokens['http-version'](req, res),
|
|
46
|
-
|
|
55
|
+
user_agent: tokens['user-agent'](req, res),
|
|
47
56
|
request_body: req.body,
|
|
48
57
|
id: tokens.req(req, res, 'x-request-id') || uuid.v4(),
|
|
49
58
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-system-logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A lightweight and configurable logging library for Node.js applications, built with winston and morgan.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,11 +35,12 @@
|
|
|
35
35
|
"@types/morgan": "^1.9.9",
|
|
36
36
|
"@types/node": "^20.12.5",
|
|
37
37
|
"@types/uuid": "^9.0.8",
|
|
38
|
+
"express": "^4.18.2",
|
|
38
39
|
"ts-node": "^10.9.2",
|
|
39
|
-
"typescript": "^5.4.4"
|
|
40
|
-
"express": "^4.18.2"
|
|
40
|
+
"typescript": "^5.4.4"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"dotenv": "^16.5.0",
|
|
43
44
|
"morgan": "^1.10.0",
|
|
44
45
|
"uuid": "^9.0.1",
|
|
45
46
|
"winston": "^3.13.0",
|