http-system-logger 1.0.4 → 1.0.5

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 CHANGED
@@ -8,6 +8,7 @@ A lightweight and configurable logging library for Node.js applications, built w
8
8
  - HTTP request logging using `morgan`.
9
9
  - Customizable log levels and formats.
10
10
  - Supports structured JSON logs for better integration with log management systems.
11
+ - Ability to ignore logs from specific routes.
11
12
 
12
13
  ## Installation
13
14
 
@@ -67,6 +68,18 @@ app.listen(3000, () => {
67
68
  });
68
69
  ```
69
70
 
71
+ ### Ignoring Specific Routes
72
+
73
+ You can configure the logger to ignore specific routes by setting the `IGNORED_ROUTES` environment variable. Provide a comma-separated list of routes to ignore.
74
+
75
+ #### Example:
76
+
77
+ ```bash
78
+ export IGNORED_ROUTES=/api/health,/api/skip
79
+ ```
80
+
81
+ In this example, requests to `/api/health` and `/api/skip` will not be logged.
82
+
70
83
  ### Environment Variables
71
84
 
72
85
  You can configure the logger using the following environment variables:
@@ -78,5 +91,6 @@ You can configure the logger using the following environment variables:
78
91
  | `LOG_MAX_FILES` | `7d` | Maximum number of log files to retain. |
79
92
  | `LOG_FILE_NAME` | `application` | Base name for log files. |
80
93
  | `SERVICE_NAME` | `logger` | Default service name included in log metadata. |
94
+ | `IGNORED_ROUTES` | `/api/health` | Comma-separated list of routes to ignore. |
81
95
 
82
96
 
@@ -29,7 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const morgan_1 = __importDefault(require("morgan"));
30
30
  const winston_config_1 = __importDefault(require("./winston.config"));
31
31
  const uuid = __importStar(require("uuid"));
32
+ const ignoredRoutes = (process.env.IGNORED_ROUTES || '/api/health')
33
+ .split(',')
34
+ .map((route) => route.trim()); // Load ignored routes from environment variables
32
35
  const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
36
+ if (ignoredRoutes.includes(req.path)) {
37
+ return null; // Skip logging for ignored routes
38
+ }
33
39
  return JSON.stringify({
34
40
  method: tokens.method(req, res),
35
41
  url: tokens.url(req, res),
@@ -45,7 +51,9 @@ const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
45
51
  stream: {
46
52
  // Configure Morgan to use our custom logger with the http severity
47
53
  write: (message) => {
48
- winston_config_1.default.http(message, { context: 'HttpContext' });
54
+ if (message) {
55
+ winston_config_1.default.http(message, { context: 'HttpContext' });
56
+ }
49
57
  },
50
58
  },
51
59
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const express_1 = __importDefault(require("express"));
7
+ const src_1 = require("../src");
8
+ const app = (0, express_1.default)();
9
+ const logger = new src_1.Logger('TestApp');
10
+ // Middleware to parse JSON requests
11
+ app.use(express_1.default.json());
12
+ // Use the HTTP logger middleware
13
+ app.use(src_1.httpLogger);
14
+ // Test route
15
+ app.get('/api/test', (req, res) => {
16
+ logger.info('Test route accessed');
17
+ res.send('Test route is working!');
18
+ });
19
+ // Ignored route
20
+ app.get('/api/health', (req, res) => {
21
+ res.send('Health check route');
22
+ });
23
+ // Start the server
24
+ const PORT = 3000;
25
+ app.listen(PORT, () => {
26
+ logger.info(`Test server is running on http://localhost:${PORT}`);
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-system-logger",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
11
+ "test": "npx ts-node test/index.ts",
12
12
  "build": "npx tsc",
13
13
  "prepare": "npm run build"
14
14
  },
@@ -35,7 +35,9 @@
35
35
  "@types/morgan": "^1.9.9",
36
36
  "@types/node": "^20.12.5",
37
37
  "@types/uuid": "^9.0.8",
38
- "typescript": "^5.4.4"
38
+ "ts-node": "^10.9.2",
39
+ "typescript": "^5.4.4",
40
+ "express": "^4.18.2"
39
41
  },
40
42
  "dependencies": {
41
43
  "morgan": "^1.10.0",
File without changes
File without changes