http-system-logger 1.0.9 → 1.0.11
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 +16 -10
- package/package.json +4 -3
package/dist/morgan.config.js
CHANGED
|
@@ -29,17 +29,23 @@ 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
|
+
console.log('Checking ignored routes for path:', path);
|
|
41
|
+
console.log('Exact matches:', ignoredRoutesExact);
|
|
42
|
+
console.log('Regex matches:', ignoredRoutesRegex);
|
|
43
|
+
if (ignoredRoutesExact.includes(path))
|
|
44
|
+
return true;
|
|
45
|
+
return ignoredRoutesRegex.some(regex => regex.test(path));
|
|
46
|
+
}
|
|
35
47
|
const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
|
|
36
|
-
if (
|
|
37
|
-
if (!route.includes('*')) {
|
|
38
|
-
return req.path === route; // Exact match for non-wildcard routes
|
|
39
|
-
}
|
|
40
|
-
const regex = new RegExp(route.replace('*', '.*'));
|
|
41
|
-
return regex.test(req.path);
|
|
42
|
-
})) {
|
|
48
|
+
if (isIgnoredRoute(req.path)) {
|
|
43
49
|
return null; // Skip logging for ignored routes
|
|
44
50
|
}
|
|
45
51
|
return JSON.stringify({
|
|
@@ -49,7 +55,7 @@ const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
|
|
|
49
55
|
content_length: tokens.res(req, res, 'content-length'),
|
|
50
56
|
response_time: Number.parseFloat(tokens['response-time'](req, res)),
|
|
51
57
|
http_version: tokens['http-version'](req, res),
|
|
52
|
-
|
|
58
|
+
user_agent: tokens['user-agent'](req, res),
|
|
53
59
|
request_body: req.body,
|
|
54
60
|
id: tokens.req(req, res, 'x-request-id') || uuid.v4(),
|
|
55
61
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-system-logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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",
|