docta-package 1.2.115 → 1.2.116
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/build/utils/winston.js +86 -28
- package/package.json +1 -1
package/build/utils/winston.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import winston from "winston";
|
|
3
|
+
// import "winston-daily-rotate-file";
|
|
4
|
+
// import path from "path";
|
|
5
|
+
// import fs from "fs";
|
|
2
6
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
7
|
var t = {};
|
|
4
8
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -15,14 +19,73 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
19
|
};
|
|
16
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
21
|
exports.logger = void 0;
|
|
22
|
+
// const errorLogDir = path.join(process.cwd(), "logs/error");
|
|
23
|
+
// // ensure logs directory exists
|
|
24
|
+
// if (!fs.existsSync(errorLogDir)) {
|
|
25
|
+
// fs.mkdirSync(errorLogDir, { recursive: true });
|
|
26
|
+
// }
|
|
27
|
+
// /**
|
|
28
|
+
// * ERROR → file
|
|
29
|
+
// */
|
|
30
|
+
// const errorTransport = new winston.transports.DailyRotateFile({
|
|
31
|
+
// level: "error",
|
|
32
|
+
// dirname: errorLogDir,
|
|
33
|
+
// filename: "%DATE%.log",
|
|
34
|
+
// datePattern: "YYYY-MM-DD",
|
|
35
|
+
// maxSize: "20m",
|
|
36
|
+
// maxFiles: "14d",
|
|
37
|
+
// });
|
|
38
|
+
// /**
|
|
39
|
+
// * INFO → console with request information
|
|
40
|
+
// */
|
|
41
|
+
// const infoTransport = new winston.transports.Console({
|
|
42
|
+
// level: "info",
|
|
43
|
+
// format: winston.format.combine(
|
|
44
|
+
// winston.format.colorize(),
|
|
45
|
+
// winston.format.timestamp(),
|
|
46
|
+
// winston.format.printf(
|
|
47
|
+
// ({ timestamp, level, message, method, path, request_id, ...meta }) => {
|
|
48
|
+
// let logMessage = `[${timestamp}] ${level}: ${message}`;
|
|
49
|
+
// // Add request information if available
|
|
50
|
+
// const requestInfo: string[] = [];
|
|
51
|
+
// if (method) requestInfo.push(`method=${method}`);
|
|
52
|
+
// if (path) requestInfo.push(`path=${path}`);
|
|
53
|
+
// if (request_id) requestInfo.push(`request_id=${request_id}`);
|
|
54
|
+
// if (requestInfo.length > 0) {
|
|
55
|
+
// logMessage += ` | ${requestInfo.join(", ")}`;
|
|
56
|
+
// }
|
|
57
|
+
// // Add any remaining metadata
|
|
58
|
+
// const remainingMeta = Object.keys(meta).filter(
|
|
59
|
+
// (key) => key !== "timestamp"
|
|
60
|
+
// );
|
|
61
|
+
// if (remainingMeta.length > 0) {
|
|
62
|
+
// const metaObj = remainingMeta.reduce(
|
|
63
|
+
// (acc, key) => ({ ...acc, [key]: meta[key] }),
|
|
64
|
+
// {}
|
|
65
|
+
// );
|
|
66
|
+
// logMessage += ` | meta=${JSON.stringify(metaObj)}`;
|
|
67
|
+
// }
|
|
68
|
+
// return logMessage;
|
|
69
|
+
// }
|
|
70
|
+
// )
|
|
71
|
+
// ),
|
|
72
|
+
// });
|
|
73
|
+
// export const logger = winston.createLogger({
|
|
74
|
+
// level: "info",
|
|
75
|
+
// transports: [infoTransport, errorTransport],
|
|
76
|
+
// });
|
|
77
|
+
///////YOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
|
|
18
78
|
const winston_1 = __importDefault(require("winston"));
|
|
19
79
|
require("winston-daily-rotate-file");
|
|
20
80
|
const path_1 = __importDefault(require("path"));
|
|
21
81
|
const fs_1 = __importDefault(require("fs"));
|
|
22
82
|
const errorLogDir = path_1.default.join(process.cwd(), "logs/error");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
83
|
+
const debugLogDir = path_1.default.join(process.cwd(), "logs/debug");
|
|
84
|
+
// ensure logs directories exist
|
|
85
|
+
for (const dir of [errorLogDir, debugLogDir]) {
|
|
86
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
87
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
88
|
+
}
|
|
26
89
|
}
|
|
27
90
|
/**
|
|
28
91
|
* ERROR → file
|
|
@@ -34,36 +97,31 @@ const errorTransport = new winston_1.default.transports.DailyRotateFile({
|
|
|
34
97
|
datePattern: "YYYY-MM-DD",
|
|
35
98
|
maxSize: "20m",
|
|
36
99
|
maxFiles: "14d",
|
|
100
|
+
format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.timestamp()),
|
|
37
101
|
});
|
|
38
102
|
/**
|
|
39
|
-
*
|
|
103
|
+
* DEBUG ONLY → file
|
|
40
104
|
*/
|
|
41
|
-
const
|
|
42
|
-
level: "
|
|
105
|
+
const debugTransport = new winston_1.default.transports.DailyRotateFile({
|
|
106
|
+
level: "debug",
|
|
107
|
+
dirname: debugLogDir,
|
|
108
|
+
filename: "%DATE%.log",
|
|
109
|
+
datePattern: "YYYY-MM-DD",
|
|
110
|
+
maxSize: "20m",
|
|
111
|
+
maxFiles: "7d",
|
|
112
|
+
format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.timestamp(), winston_1.default.format((info) => (info.level === "debug" ? info : false))()),
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* CONSOLE → everything (CloudWatch)
|
|
116
|
+
*/
|
|
117
|
+
const consoleTransport = new winston_1.default.transports.Console({
|
|
118
|
+
level: "debug",
|
|
43
119
|
format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.timestamp(), winston_1.default.format.printf((_a) => {
|
|
44
|
-
var { timestamp, level, message
|
|
45
|
-
|
|
46
|
-
// Add request information if available
|
|
47
|
-
const requestInfo = [];
|
|
48
|
-
if (method)
|
|
49
|
-
requestInfo.push(`method=${method}`);
|
|
50
|
-
if (path)
|
|
51
|
-
requestInfo.push(`path=${path}`);
|
|
52
|
-
if (request_id)
|
|
53
|
-
requestInfo.push(`request_id=${request_id}`);
|
|
54
|
-
if (requestInfo.length > 0) {
|
|
55
|
-
logMessage += ` | ${requestInfo.join(", ")}`;
|
|
56
|
-
}
|
|
57
|
-
// Add any remaining metadata
|
|
58
|
-
const remainingMeta = Object.keys(meta).filter((key) => key !== "timestamp");
|
|
59
|
-
if (remainingMeta.length > 0) {
|
|
60
|
-
const metaObj = remainingMeta.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: meta[key] })), {});
|
|
61
|
-
logMessage += ` | meta=${JSON.stringify(metaObj)}`;
|
|
62
|
-
}
|
|
63
|
-
return logMessage;
|
|
120
|
+
var { timestamp, level, message } = _a, meta = __rest(_a, ["timestamp", "level", "message"]);
|
|
121
|
+
return `[${timestamp}] ${level}: ${message}${Object.keys(meta).length ? " " + JSON.stringify(meta) : ""}`;
|
|
64
122
|
})),
|
|
65
123
|
});
|
|
66
124
|
exports.logger = winston_1.default.createLogger({
|
|
67
|
-
level: "
|
|
68
|
-
transports: [
|
|
125
|
+
level: "debug",
|
|
126
|
+
transports: [consoleTransport, errorTransport, debugTransport],
|
|
69
127
|
});
|
package/package.json
CHANGED