http-system-logger 1.0.9 → 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.
@@ -29,17 +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 ignoredRoutes = (process.env.IGNORED_ROUTES || '/api/health')
32
+ const ignoredRoutesRaw = (process.env.IGNORED_ROUTES || '/api/health')
33
33
  .split(',')
34
- .map((route) => route.trim()); // Load ignored routes from environment variables
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 (ignoredRoutes.some(route => {
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
- })) {
45
+ if (isIgnoredRoute(req.path)) {
43
46
  return null; // Skip logging for ignored routes
44
47
  }
45
48
  return JSON.stringify({
@@ -49,7 +52,7 @@ const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
49
52
  content_length: tokens.res(req, res, 'content-length'),
50
53
  response_time: Number.parseFloat(tokens['response-time'](req, res)),
51
54
  http_version: tokens['http-version'](req, res),
52
- use_agent: tokens['user-agent'](req, res),
55
+ user_agent: tokens['user-agent'](req, res),
53
56
  request_body: req.body,
54
57
  id: tokens.req(req, res, 'x-request-id') || uuid.v4(),
55
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-system-logger",
3
- "version": "1.0.9",
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",