@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. 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.2",
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",
@@ -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
- this.lastDay = null;
13
- this.startWatching();
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
- startWatching() {
19
+ startPeriodicUpload() {
17
20
  setInterval(() => {
18
21
  const { Y, M, D } = getDatePath();
19
- const currentDay = `${Y}-${M}-${D}`;
20
22
 
21
- if (!this.lastDay) {
22
- // First run, just set lastDay
23
- this.lastDay = currentDay;
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
- if (this.lastDay !== currentDay) {
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
- if (fs.existsSync(logFile)) {
38
- const s3Key = `${lastDayPath}/daily_logs.json`; // e.g. 2025/12/05/daily_logs.json
39
-
40
- this.queue.add(async () => {
41
- console.log("📤 Uploading previous day logs →", s3Key);
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
  }