@nm-logger/logger 1.1.5 → 1.1.6
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/package.json +2 -2
- package/src/Logger.js +24 -21
- package/src/S3Uploader.js +18 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nm-logger/logger",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Express JSON logger with S3 upload, correlation IDs, and separate success/error/external daily logs.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "nm-logger",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"aws-sdk": "^
|
|
24
|
+
"@aws-sdk/client-s3": "^3.600.0",
|
|
25
25
|
"fs-extra": "^11.1.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
package/src/Logger.js
CHANGED
|
@@ -140,31 +140,34 @@ class Logger {
|
|
|
140
140
|
return this.expressMiddleware();
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
requestLoggerMiddleware() {
|
|
144
|
+
return (req, res, next) => {
|
|
145
|
+
try {
|
|
146
|
+
// Prevent duplicate logging
|
|
147
|
+
if (req.__nm_logger_logged) {
|
|
148
|
+
return next();
|
|
149
|
+
}
|
|
150
|
+
req.__nm_logger_logged = true;
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
let correlationId =
|
|
153
|
+
req.headers["x-correlation-id"] ||
|
|
154
|
+
req.headers["X-Correlation-ID"] ||
|
|
155
|
+
req.correlationId ||
|
|
156
|
+
generateCorrelationId();
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
req.correlationId = correlationId;
|
|
159
|
+
res.setHeader("X-Correlation-ID", correlationId);
|
|
157
160
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
this.logRequest(req).catch((e) =>
|
|
162
|
+
console.error("Logger requestLoggerMiddleware error:", e)
|
|
163
|
+
);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.error("Logger requestLoggerMiddleware outer error:", e);
|
|
166
|
+
}
|
|
164
167
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
next();
|
|
169
|
+
};
|
|
170
|
+
}
|
|
168
171
|
|
|
169
172
|
attachAxiosLogger(axiosInstance) {
|
|
170
173
|
if (!axiosInstance || !axiosInstance.interceptors) {
|
package/src/S3Uploader.js
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
-
const
|
|
2
|
+
const {
|
|
3
|
+
S3Client,
|
|
4
|
+
PutObjectCommand
|
|
5
|
+
} = require("@aws-sdk/client-s3");
|
|
3
6
|
|
|
4
7
|
class S3Uploader {
|
|
5
8
|
constructor(config) {
|
|
6
|
-
this.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
this.client = new S3Client({
|
|
10
|
+
region: config.region,
|
|
11
|
+
credentials: {
|
|
12
|
+
accessKeyId: config.accessKeyId,
|
|
13
|
+
secretAccessKey: config.secretAccessKey
|
|
14
|
+
}
|
|
10
15
|
});
|
|
16
|
+
|
|
11
17
|
this.bucket = config.bucket;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
async upload(filePath, s3Key) {
|
|
15
21
|
const fileData = fs.readFileSync(filePath);
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const command = new PutObjectCommand({
|
|
24
|
+
Bucket: this.bucket,
|
|
25
|
+
Key: s3Key,
|
|
26
|
+
Body: fileData
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await this.client.send(command);
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
32
|
|