@mcesystems/logging-g4 1.0.72 → 1.0.74

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 CHANGED
@@ -1,106 +1,106 @@
1
- # @mcesystems/logging-g4
2
-
3
- ## 1. Description
4
-
5
- **What it does:** Node-only logging client that sends events to the MCE logging service. Events are queued and sent in batches on a cron-style schedule (e.g. every 10 minutes at fixed clock boundaries). Failed sends (401, network errors) are persisted to disk and retried on the next run. If the service stays offline longer than `MAX_OFFLINE_TIME`, the client throws.
6
-
7
- **When it's used:** Use this package when your application needs to send structured log events to the MCE logging service with batching, persistence, and offline handling—for example device management tools or services that must not lose logs when the API is temporarily unavailable.
8
-
9
- ## 2. Install
10
-
11
- ```bash
12
- pnpm add @mcesystems/logging-g4
13
- ```
14
-
15
- **Requirements:** Node.js 18+. This package uses Node APIs (`fs`, `os`, `path`) and is not compatible with browsers or other non-Node runtimes.
16
-
17
- ## 3. Resources
18
-
19
- No binary resources are required. You need a credentials file (see Setup) and network access to the auth and logging APIs.
20
-
21
- ## 4. Examples
22
-
23
- **Single event**
24
-
25
- ```bash
26
- pnpm exec tsx src/example/sendLog.ts
27
- ```
28
-
29
- Uses `CREDENTIALS_PATH`, `LOGGING_API_URL`, `AUTH_API_URL` from `.env` or environment. Sends one event; returns `"delayed"` (event queued for next scheduled send).
30
-
31
- **Batch after 1 minute (with 15s gap between events)**
32
-
33
- ```bash
34
- pnpm exec tsx src/example/sendBatchAfterOneMinute.ts
35
- ```
36
-
37
- Queues three events with a 15-second gap between each; shows the time when the batch is sent at the next 1-minute boundary. Sets `TIME_BETWEEN_LOG=60000` and `CACHED_EVENTS_PATH` to a temp file if not set.
38
-
39
- For step-by-step explanations and scenarios, see [Example.md](./Example.md).
40
-
41
- ## 5. API
42
-
43
- ### LogClient
44
-
45
- **Constructor**
46
-
47
- - **Input:** none
48
- - **Output:** new `LogClient` instance. Call `logEvent()` after creation; `init()` runs on first `logEvent()` if needed.
49
-
50
- **logEvent(event)**
51
-
52
- - **Input:** `event` — object with `event_severity`, `event_type`, `event_info`, `context` (and optional fields). Omit `event_id`, `event_time`, `framework_id`, `event_source`; they are set by the client.
53
- - **Output:** `Promise<LogSendResult>` — always `"delayed"` (event queued for next scheduled send). No immediate send. The outcomes `"success"` and `"MAX_OFFLINE_TIME passed"` occur inside the cron job: when `MAX_OFFLINE_TIME` is exceeded, `sendBatch()` throws so the process receives the exception.
54
-
55
- ### LogSendResult
56
-
57
- Type: `"success" | "MAX_OFFLINE_TIME passed" | "delayed"`. Exported for typing; `logEvent()` returns `"delayed"` only.
58
-
59
- ## 6. Flow
60
-
61
- Example flow: create client, queue several events, let the cron send the batch at the next boundary.
62
-
63
- ```typescript
64
- import { LogSeverity } from "@mcesystems/logging-interfaces/lib/sdk";
65
- import { LogClient } from "@mcesystems/logging-g4";
66
-
67
- const logClient = new LogClient();
68
-
69
- await logClient.logEvent({
70
- event_severity: LogSeverity.Info,
71
- event_type: "device_connected",
72
- event_info: {
73
- message: "Device connected",
74
- source: "device-manager",
75
- timestamp: new Date().toISOString(),
76
- },
77
- context: { deviceId: "abc123" },
78
- });
79
- // result is "delayed" — batch will be sent at next TIME_BETWEEN_LOG boundary
80
-
81
- await logClient.logEvent({
82
- event_severity: LogSeverity.Info,
83
- event_type: "device_disconnected",
84
- event_info: { message: "Device disconnected", timestamp: new Date().toISOString() },
85
- context: { deviceId: "abc123" },
86
- });
87
- // both events are queued; cron sends the batch at the next boundary
88
- ```
89
-
90
- ## 7. Setup
91
-
92
- **Environment variables**
93
-
94
- - **TIME_BETWEEN_LOG** (ms): Interval between batch send attempts. Sends run at fixed clock boundaries (e.g. 10 min → 13:50, 14:00, 14:10). Default: 10 minutes.
95
- - **MAX_OFFLINE_TIME** (ms): After this many ms since the first send failure, the client throws. If the batch was successfully persisted and still within this window, no throw. Default: 1 hour.
96
- - **CACHED_EVENTS_PATH**: Path to a single JSON file for pending (delayed) events. **Required.** Delayed batches are written here on send failure and loaded on the next run; file is deleted after a successful send.
97
- - **CREDENTIALS_PATH**: Path to credentials file used by `@mcesystems/auth-g4`. Required for auth.
98
- - **LOGGING_API_URL**: Logging API base URL. Required.
99
- - **AUTH_API_URL**: Auth API URL for token. Required.
100
-
101
- **Resources location:** None. Credentials file path is given by `CREDENTIALS_PATH`. Pending events file path is given by `CACHED_EVENTS_PATH`.
102
-
103
- ## 8. TODO
104
-
105
- - [ ] Optional: Expand Example.md with more scenarios (e.g. offline handling, MAX_OFFLINE_TIME).
106
- - [ ] Optional: Token refresh on 401 before persisting and retrying.
1
+ # @mcesystems/logging-g4
2
+
3
+ ## 1. Description
4
+
5
+ **What it does:** Node-only logging client that sends events to the MCE logging service. Events are queued and sent in batches on a cron-style schedule (e.g. every 10 minutes at fixed clock boundaries). Failed sends (401, network errors) are persisted to disk and retried on the next run. If the service stays offline longer than `MAX_OFFLINE_TIME`, the client throws.
6
+
7
+ **When it's used:** Use this package when your application needs to send structured log events to the MCE logging service with batching, persistence, and offline handling—for example device management tools or services that must not lose logs when the API is temporarily unavailable.
8
+
9
+ ## 2. Install
10
+
11
+ ```bash
12
+ pnpm add @mcesystems/logging-g4
13
+ ```
14
+
15
+ **Requirements:** Node.js 18+. This package uses Node APIs (`fs`, `os`, `path`) and is not compatible with browsers or other non-Node runtimes.
16
+
17
+ ## 3. Resources
18
+
19
+ No binary resources are required. You need a credentials file (see Setup) and network access to the auth and logging APIs.
20
+
21
+ ## 4. Examples
22
+
23
+ **Single event**
24
+
25
+ ```bash
26
+ pnpm exec tsx src/example/sendLog.ts
27
+ ```
28
+
29
+ Uses `CREDENTIALS_PATH`, `LOGGING_API_URL`, `AUTH_API_URL` from `.env` or environment. Sends one event; returns `"delayed"` (event queued for next scheduled send).
30
+
31
+ **Batch after 1 minute (with 15s gap between events)**
32
+
33
+ ```bash
34
+ pnpm exec tsx src/example/sendBatchAfterOneMinute.ts
35
+ ```
36
+
37
+ Queues three events with a 15-second gap between each; shows the time when the batch is sent at the next 1-minute boundary. Sets `TIME_BETWEEN_LOG=60000` and `CACHED_EVENTS_PATH` to a temp file if not set.
38
+
39
+ For step-by-step explanations and scenarios, see [Example.md](./Example.md).
40
+
41
+ ## 5. API
42
+
43
+ ### LogClient
44
+
45
+ **Constructor**
46
+
47
+ - **Input:** none
48
+ - **Output:** new `LogClient` instance. Call `logEvent()` after creation; `init()` runs on first `logEvent()` if needed.
49
+
50
+ **logEvent(event)**
51
+
52
+ - **Input:** `event` — object with `event_severity`, `event_type`, `event_info`, `context` (and optional fields). Omit `event_id`, `event_time`, `framework_id`, `event_source`; they are set by the client.
53
+ - **Output:** `Promise<LogSendResult>` — always `"delayed"` (event queued for next scheduled send). No immediate send. The outcomes `"success"` and `"MAX_OFFLINE_TIME passed"` occur inside the cron job: when `MAX_OFFLINE_TIME` is exceeded, `sendBatch()` throws so the process receives the exception.
54
+
55
+ ### LogSendResult
56
+
57
+ Type: `"success" | "MAX_OFFLINE_TIME passed" | "delayed"`. Exported for typing; `logEvent()` returns `"delayed"` only.
58
+
59
+ ## 6. Flow
60
+
61
+ Example flow: create client, queue several events, let the cron send the batch at the next boundary.
62
+
63
+ ```typescript
64
+ import { LogSeverity } from "@mcesystems/logging-interfaces/lib/sdk";
65
+ import { LogClient } from "@mcesystems/logging-g4";
66
+
67
+ const logClient = new LogClient();
68
+
69
+ await logClient.logEvent({
70
+ event_severity: LogSeverity.Info,
71
+ event_type: "device_connected",
72
+ event_info: {
73
+ message: "Device connected",
74
+ source: "device-manager",
75
+ timestamp: new Date().toISOString(),
76
+ },
77
+ context: { deviceId: "abc123" },
78
+ });
79
+ // result is "delayed" — batch will be sent at next TIME_BETWEEN_LOG boundary
80
+
81
+ await logClient.logEvent({
82
+ event_severity: LogSeverity.Info,
83
+ event_type: "device_disconnected",
84
+ event_info: { message: "Device disconnected", timestamp: new Date().toISOString() },
85
+ context: { deviceId: "abc123" },
86
+ });
87
+ // both events are queued; cron sends the batch at the next boundary
88
+ ```
89
+
90
+ ## 7. Setup
91
+
92
+ **Environment variables**
93
+
94
+ - **TIME_BETWEEN_LOG** (ms): Interval between batch send attempts. Sends run at fixed clock boundaries (e.g. 10 min → 13:50, 14:00, 14:10). Default: 10 minutes.
95
+ - **MAX_OFFLINE_TIME** (ms): After this many ms since the first send failure, the client throws. If the batch was successfully persisted and still within this window, no throw. Default: 1 hour.
96
+ - **CACHED_EVENTS_PATH**: Path to a single JSON file for pending (delayed) events. **Required.** Delayed batches are written here on send failure and loaded on the next run; file is deleted after a successful send.
97
+ - **CREDENTIALS_PATH**: Path to credentials file used by `@mcesystems/auth-g4`. Required for auth.
98
+ - **LOGGING_API_URL**: Logging API base URL. Required.
99
+ - **AUTH_API_URL**: Auth API URL for token. Required.
100
+
101
+ **Resources location:** None. Credentials file path is given by `CREDENTIALS_PATH`. Pending events file path is given by `CACHED_EVENTS_PATH`.
102
+
103
+ ## 8. TODO
104
+
105
+ - [ ] Optional: Expand Example.md with more scenarios (e.g. offline handling, MAX_OFFLINE_TIME).
106
+ - [ ] Optional: Token refresh on 401 before persisting and retrying.
package/dist/index.js CHANGED
@@ -20381,7 +20381,7 @@ function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
20381
20381
  `;
20382
20382
  } else if (typeof value === "object") {
20383
20383
  result += `
20384
- ${logDataDetail(value, `${prefix} `)}
20384
+ ${logDataDetail(value, `${prefix} `)}
20385
20385
  `;
20386
20386
  } else {
20387
20387
  result += `${value}
@@ -21486,7 +21486,7 @@ function createLoggers2(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
21486
21486
  `;
21487
21487
  } else if (typeof value === "object") {
21488
21488
  result += `
21489
- ${logDataDetail(value, `${prefix} `)}
21489
+ ${logDataDetail(value, `${prefix} `)}
21490
21490
  `;
21491
21491
  } else {
21492
21492
  result += `${value}