@nm-logger/logger 1.1.2 → 1.1.4
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 +1 -1
- package/src/DailyWatcher.js +21 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nm-logger/logger",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Daily JSON logger with S3 upload queue, correlation IDs, external API logging, and sensitive field masking for Express-based APIs.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
package/src/DailyWatcher.js
CHANGED
|
@@ -7,45 +7,37 @@ class DailyWatcher {
|
|
|
7
7
|
this.baseDir = baseDir;
|
|
8
8
|
this.queue = queue;
|
|
9
9
|
this.s3Uploader = s3Uploader;
|
|
10
|
-
this.intervalMs = options.watchIntervalMs || 60_000; // default: 1 minute
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
this.
|
|
11
|
+
// default upload every 15 minutes
|
|
12
|
+
this.intervalMs = options.uploadIntervalMs || 15 * 60 * 1000;
|
|
13
|
+
|
|
14
|
+
console.log("🕒 S3 Periodic Upload Enabled. Interval:", this.intervalMs);
|
|
15
|
+
|
|
16
|
+
this.startPeriodicUpload();
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
startPeriodicUpload() {
|
|
17
20
|
setInterval(() => {
|
|
18
21
|
const { Y, M, D } = getDatePath();
|
|
19
|
-
const currentDay = `${Y}-${M}-${D}`;
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const logFile = path.join(
|
|
24
|
+
this.baseDir,
|
|
25
|
+
`${Y}/${M}/${D}`,
|
|
26
|
+
"daily_logs.json"
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (!fs.existsSync(logFile)) {
|
|
30
|
+
console.log("⚠️ No log file found yet:", logFile);
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
// Day changed → upload previous day's log
|
|
29
|
-
const lastDayPath = this.lastDay.replace(/-/g, "/");
|
|
30
|
-
|
|
31
|
-
const logFile = path.join(
|
|
32
|
-
this.baseDir,
|
|
33
|
-
lastDayPath,
|
|
34
|
-
"daily_logs.json"
|
|
35
|
-
);
|
|
34
|
+
const s3Key = `${Y}/${M}/${D}/daily_logs.json`;
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await this.s3Uploader.upload(logFile, s3Key);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// update lastDay to current
|
|
47
|
-
this.lastDay = currentDay;
|
|
48
|
-
}
|
|
36
|
+
this.queue.add(async () => {
|
|
37
|
+
console.log(`📤 Periodic Upload → ${s3Key}`);
|
|
38
|
+
await this.s3Uploader.upload(logFile, s3Key);
|
|
39
|
+
console.log("✅ Uploaded");
|
|
40
|
+
});
|
|
49
41
|
}, this.intervalMs);
|
|
50
42
|
}
|
|
51
43
|
}
|