http-system-logger 1.0.13 → 1.0.15
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 +1 -0
- package/dist/morgan.config.d.ts +1 -1
- package/dist/morgan.config.js +18 -18
- package/dist/winston.config.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -92,5 +92,6 @@ You can configure the logger using the following environment variables:
|
|
|
92
92
|
| `LOG_FILE_NAME` | `application` | Base name for log files. |
|
|
93
93
|
| `SERVICE_NAME` | `logger` | Default service name included in log metadata. |
|
|
94
94
|
| `IGNORED_ROUTES` | `/api/health` | Comma-separated list of routes to ignore. |
|
|
95
|
+
| `LOG_LEVEL` | `http` | Log level for the logger. |
|
|
95
96
|
|
|
96
97
|
|
package/dist/morgan.config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
|
-
import { Request, Response } from
|
|
2
|
+
import { Request, Response } from "express";
|
|
3
3
|
declare const morganMiddleware: (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, callback: (err?: Error | undefined) => void) => void;
|
|
4
4
|
export default morganMiddleware;
|
package/dist/morgan.config.js
CHANGED
|
@@ -29,19 +29,19 @@ 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 ignoredRoutesRaw = (process.env.IGNORED_ROUTES || '/api/health')
|
|
33
|
-
.split(',')
|
|
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
|
-
}
|
|
44
32
|
const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
|
|
33
|
+
const ignoredRoutesRaw = (process.env.IGNORED_ROUTES || "/api/health")
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((route) => route.trim());
|
|
36
|
+
const ignoredRoutesExact = ignoredRoutesRaw.filter((route) => !route.includes("*"));
|
|
37
|
+
const ignoredRoutesRegex = ignoredRoutesRaw
|
|
38
|
+
.filter((route) => route.includes("*"))
|
|
39
|
+
.map((route) => new RegExp("^" + route.replace(/\*/g, ".*") + "$"));
|
|
40
|
+
function isIgnoredRoute(path) {
|
|
41
|
+
if (ignoredRoutesExact.includes(path))
|
|
42
|
+
return true;
|
|
43
|
+
return ignoredRoutesRegex.some((regex) => regex.test(path));
|
|
44
|
+
}
|
|
45
45
|
if (isIgnoredRoute(req.path)) {
|
|
46
46
|
return null; // Skip logging for ignored routes
|
|
47
47
|
}
|
|
@@ -49,19 +49,19 @@ const morganMiddleware = (0, morgan_1.default)(function (tokens, req, res) {
|
|
|
49
49
|
method: tokens.method(req, res),
|
|
50
50
|
url: tokens.url(req, res),
|
|
51
51
|
status: Number.parseFloat(tokens.status(req, res)),
|
|
52
|
-
content_length: tokens.res(req, res,
|
|
53
|
-
response_time: Number.parseFloat(tokens[
|
|
54
|
-
http_version: tokens[
|
|
55
|
-
user_agent: tokens[
|
|
52
|
+
content_length: tokens.res(req, res, "content-length"),
|
|
53
|
+
response_time: Number.parseFloat(tokens["response-time"](req, res)),
|
|
54
|
+
http_version: tokens["http-version"](req, res),
|
|
55
|
+
user_agent: tokens["user-agent"](req, res),
|
|
56
56
|
request_body: req.body,
|
|
57
|
-
id: tokens.req(req, res,
|
|
57
|
+
id: tokens.req(req, res, "x-request-id") || uuid.v4(),
|
|
58
58
|
});
|
|
59
59
|
}, {
|
|
60
60
|
stream: {
|
|
61
61
|
// Configure Morgan to use our custom logger with the http severity
|
|
62
62
|
write: (message) => {
|
|
63
63
|
if (message) {
|
|
64
|
-
(0, winston_config_1.getLogger)().http(message, { context:
|
|
64
|
+
(0, winston_config_1.getLogger)().http(message, { context: "HttpContext" });
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
},
|
package/dist/winston.config.js
CHANGED
|
@@ -32,9 +32,10 @@ const createLoggerInstance = () => {
|
|
|
32
32
|
const maxSize = process.env.LOG_MAX_SIZE || '4m';
|
|
33
33
|
const maxFiles = process.env.LOG_MAX_FILES || '7d';
|
|
34
34
|
const fileName = process.env.LOG_FILE_NAME || 'application';
|
|
35
|
+
const logLevel = process.env.LOG_LEVEL || 'http';
|
|
35
36
|
const transports = [
|
|
36
37
|
new winston.transports.Console({
|
|
37
|
-
level:
|
|
38
|
+
level: logLevel,
|
|
38
39
|
format: winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD hh:mm:ss A' }), winston.format.colorize(), winston.format.printf(({ timestamp, level, message, context, trace, service, stack }) => {
|
|
39
40
|
return `[\x1b[34m${timestamp}\x1b[0m] [\x1b[36m${service}\x1b[0m] [\x1b[33m${context}\x1b[0m] [${level}]: ${message}${stack ? `\n${stack}` : ''}${trace ? `\n${trace}` : ''}`;
|
|
40
41
|
})),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-system-logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
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",
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"winston-daily-rotate-file": "^5.0.0",
|
|
48
48
|
"winston-transport": "^4.7.0"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|