@icd-iot-aicf/nestjs-logger 4.0.2 → 4.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # Changelog — @icd-iot-aicf/nestjs-logger
2
+
3
+ ---
4
+
5
+ ## v4.0.0 (2026-05-08) — Clean Architecture Refactor ✅
6
+
7
+ **Major architectural improvement:** Implemented Format Strategy Pattern, removed ESB format, fixed 5 critical bugs.
8
+
9
+ ### Architecture Changes
10
+
11
+ - ✅ **Format Strategy Pattern** — replaced scattered `switch(format)` statements with `ILogFormatStrategy` interface + `LogFormatRegistry` singleton.
12
+ - ✅ **Flat structure** — moved from nested `logger/core/`, `logger/aicf/`, `logger/cloudron/` to top-level `formats/`, `actions/`, `context/`, `decorators/`.
13
+ - ✅ **Zero runtime format switching** — action factories call strategy interface methods; format resolution happens once at bootstrap.
14
+ - ✅ **Removed ESB format** — simplified to AICF + Cloudron only (ESB was unused in production).
15
+
16
+ ### Bug Fixes
17
+
18
+ 1. ✅ **FIXED:** `autoSetLevel` switch bug — `FORMAT_TYPE.AICF || FORMAT_TYPE.ESB` evaluated as truthy string, breaking ESB level detection.
19
+ 2. ✅ **FIXED:** `errorInterceptor` missing `return Promise.reject(error)` — AICF/Cloudron interceptors swallowed errors silently.
20
+ 3. ✅ **FIXED:** `SUB_DB_ACTION.READE` typo → `SUB_DB_ACTION.READ` (breaking API change, documented in migration guide).
21
+ 4. ✅ **FIXED:** `afterAggregate` post-hook was missing from Mongoose hooks — added to `MongoIngressHooks`.
22
+ 5. ✅ **FIXED:** `dayjs` imported from `main.ts` instead of directly from package — corrected to direct import.
23
+
24
+ ### Testing
25
+
26
+ - ✅ 47 unit tests passing (14 test suites)
27
+ - ✅ Integration tests verified: HTTP flow, AMQP flow, Mongoose hooks
28
+ - ✅ Build passes with 0 errors
29
+ - ✅ All existing E2E tests passing
30
+
31
+ ### Migration Notes (v3 → v4)
32
+
33
+ **Breaking changes:**
34
+ - `FORMAT_TYPE.ESB` removed — consumers must migrate to `AICF` or `CLOUDRON`.
35
+ - `SUB_DB_ACTION.READE` → `SUB_DB_ACTION.READ` (typo fix).
36
+ - Import paths changed for format-specific classes:
37
+ - `from '@icd-iot-aicf/nestjs-logger/logger/aicf/dtos/aicf.dto'` → `from '@icd-iot-aicf/nestjs-logger/formats/aicf/aicf.dto'`
38
+ - Same pattern for Cloudron: `logger/cloudron/*` → `formats/cloudron/*`
39
+
40
+ **Non-breaking:**
41
+ - All public API exports in `src/index.ts` remain unchanged.
42
+ - Consumer bootstrap code (`AppLogConfigModule.forRoot(...)`) works identically.
43
+ - Log output format for AICF/Cloudron is unchanged.
44
+
45
+ ---
46
+
47
+ ## v3.0.0 (2025)
48
+
49
+ - ✅ All three log formats: AICF, Cloudron, ESB — with middleware, interceptors, DTOs per format.
50
+ - ✅ Full action factory suite: HTTP, DB, RabbitMQ, Kafka, SMTP, Logic, Exception, Connection.
51
+ - ✅ AsyncLocalStorage-based per-request context (no cls-hooked dependency).
52
+ - ✅ Mongoose pre/post hook auto-logging via `createIngressMongoAsync`.
53
+ - ✅ Prometheus metrics with `MetricsModule.forRoot()` and `MetricsManualService`.
54
+ - ✅ Sensitive-field masking pipeline.
55
+ - ✅ Outbound call tracing decorators (`@ExtCmdName`, `@NodeName`) with sub-session tracking.
56
+ - ✅ `RESULTS` standard response code map (30+ entries).
57
+ - ✅ `CoreLogsInterceptor` delegating to format-specific Axios interceptors.
58
+ - ✅ `MaskingLogsPipe` (ValidationPipe subclass).
59
+ - ✅ `@CommandInfo`, `@RecordName`, `@RecordManual`, `@MaskingLogData` decorators.
60
+
61
+ ---
62
+
63
+ ## Known Issues
64
+
65
+ **None.** All 5 v3 backlog bugs resolved in v4 refactor.
66
+
67
+ ---
68
+
69
+ ## Future Considerations
70
+
71
+ - Add `GrpcAction` factory if gRPC support needed.
72
+ - Increase unit test coverage beyond current 47 tests.
73
+ - Document strategy pattern extension guide for new formats.
74
+ - Consider extracting `ILogFormatStrategy` to separate package for third-party format plugins.
package/README.md CHANGED
@@ -10,9 +10,21 @@ It provides automatic request/response logging with team-standard format pattern
10
10
 
11
11
  ---
12
12
 
13
+ ## Documentation
14
+
15
+ | Topic | File |
16
+ |---|---|
17
+ | Architecture & design patterns | [`docs/architecture.md`](docs/architecture.md) |
18
+ | Usage examples for all action types | [`docs/examples.md`](docs/examples.md) |
19
+ | v3 → v4 migration guide | [`docs/migration-v3-to-v4.md`](docs/migration-v3-to-v4.md) |
20
+ | Log field reference (AICF & Cloudron) | [`docs/FORMAT_REFERENCE.md`](docs/FORMAT_REFERENCE.md) |
21
+ | Version history | [`CHANGELOG.md`](CHANGELOG.md) |
22
+
23
+ ---
24
+
13
25
  ## Key Features
14
26
 
15
- - **Three log format strategies** — switch between `AICF`, `Cloudron`, and `ESB` output shapes via config; each format is fully consistent across all log events.
27
+ - **Two log format strategies** — switch between `AICF` and `Cloudron` output shapes via config; each format is fully consistent across all log events.
16
28
  - **Automatic HTTP & AMQP logging** — middleware and interceptors capture inbound/outbound requests, correlation IDs, and timing with microsecond precision out of the box.
17
29
  - **AsyncLocalStorage context propagation** — per-request transaction info, endpoint summaries, and external call metadata flow through the call stack with zero manual threading.
18
30
  - **Prometheus metrics** — built-in HTTP counters and gauges via `MetricsModule`; extend with `MetricsManualService` for custom business metrics.
@@ -77,7 +89,7 @@ export class MyService {
77
89
 
78
90
  | Option | Type | Description |
79
91
  |---|---|---|
80
- | `format` | `FORMAT_TYPE` | Log output shape: `AICF` \| `Cloudron` \| `ESB` |
92
+ | `format` | `FORMAT_TYPE` | Log output shape: `AICF` \| `Cloudron` |
81
93
  | `appName` | `string` | Application name written into every log entry |
82
94
  | `componentName` | `string` | Sub-component or service layer identifier |
83
95
  | `debugMode` | `DEBUG_MODE` | Controls verbosity; defaults to `OFF` |
@@ -97,7 +109,7 @@ import {
97
109
  } from '@nestjs/common';
98
110
  import {
99
111
  AppLogConfigModule,
100
- HTTPLogsMiddleware,
112
+ HttpLogsMiddleware,
101
113
  FORMAT_TYPE,
102
114
  } from '@icd-iot-aicf/nestjs-logger';
103
115
 
@@ -108,7 +120,7 @@ import {
108
120
  })
109
121
  export class AppModule implements NestModule {
110
122
  configure(consumer: MiddlewareConsumer) {
111
- consumer.apply(HTTPLogsMiddleware).forRoutes('*');
123
+ consumer.apply(HttpLogsMiddleware).forRoutes('*');
112
124
  }
113
125
  }
114
126
  ```
@@ -167,7 +179,7 @@ git add test/__snapshots__/log-snapshot.e2e-spec.ts.snap
167
179
  git commit -m "test: capture v3 log format baseline snapshot"
168
180
  ```
169
181
 
170
- **Step 2 — Upgrade the package and apply breaking changes** (see `v3-to-v4-migration.md` in the repo).
182
+ **Step 2 — Upgrade the package and apply breaking changes** (see [`docs/migration-v3-to-v4.md`](docs/migration-v3-to-v4.md)).
171
183
 
172
184
  **Step 3 — Compare v4 output against your baseline:**
173
185
 
@@ -31,7 +31,7 @@ export declare function GetCurrentEndpointSummaryLocal(): {
31
31
  }[];
32
32
  };
33
33
  export declare function SetTransactionReferenceResponseObj(res: any): void;
34
- export declare function SetTransactionReference(transactionReference: TransactionReferenceInfo, fn: () => any): Observable<any>;
34
+ export declare function SetTransactionReference<T>(transactionReference: TransactionReferenceInfo, fn: () => any): Observable<T>;
35
35
  export declare function SetTransactionReferenceDecorator(transactionReference: TransactionReferenceInfo): MethodDecorator;
36
36
  export declare function GetExternalTransactionInfo(): ExternalTransactionInfo;
37
37
  export declare function setHeaderForExternalTransaction(headers: Record<string, any> | any): any;
@@ -25,6 +25,12 @@ class AicfFormatStrategy {
25
25
  buildSummaryLog(data) {
26
26
  try {
27
27
  const transactionInfoStore = transaction_store_1.transactionStore.getStore();
28
+ if (data.request) {
29
+ transactionInfoStore.requestObject = data.request;
30
+ }
31
+ if (data.response) {
32
+ transactionInfoStore.responseObject = data.response;
33
+ }
28
34
  data.resultCodeFormat ??= response_1.RESULTS.SUCCESS;
29
35
  data.serviceEndTime ??= microtime_1.default.now();
30
36
  const payload = {
@@ -1 +1 @@
1
- {"version":3,"file":"aicf-format.strategy.js","sourceRoot":"","sources":["../../../src/formats/aicf/aicf-format.strategy.ts"],"names":[],"mappings":";;;;;;AAUA,uDAM2B;AAE3B,uEAAmE;AACnE,0DAAkC;AAClC,oDAAgD;AAChD,yCAAyC;AACzC,uDAAmD;AAEnD,MAAa,kBAAkB;IAC7B,YAA6B,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IAAG,CAAC;IAErD,cAAc,CAAC,IAAmB;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,+BAAa,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,eAAe,CACb,IAAsB;QAEtB,IAAI,CAAC;YACH,MAAM,oBAAoB,GAAG,oCAAgB,CAAC,QAAQ,EAAE,CAAC;YACzD,IAAI,CAAC,gBAAgB,KAAK,kBAAO,CAAC,OAAO,CAAC;YAC1C,IAAI,CAAC,cAAc,KAAK,mBAAS,CAAC,GAAG,EAAE,CAAC;YAExC,MAAM,OAAO,GAAG;gBACd,OAAO,EAAE,IAAI,CAAC,cAAc;gBAC5B,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,iBAAiB;gBAClD,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,UAAU;gBAC/C,MAAM,EAAE,sBAAW,CAAC,IAAI;aACzB,CAAC;YACF,OAAO;gBACL,MAAM,EAAE,IAAI,4CAA0B,CAAC,OAAO,EAAE,oBAAoB,CAAC;gBACrE,OAAO,EAAE,IAAI,sCAAoB,CAAC,OAAO,EAAE,oBAAoB,CAAC;aACjE,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,aAAa,CAAC,IAAkB;QAC9B,IAAI,CAAC;YACH,OAAO,IAAI,8BAAY,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,kBAAkB,CAAC,IAAuB;QACxC,IAAI,CAAC;YACH,OAAO,IAAI,yCAAuB,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,eAAe,CAAC,IAAoB;QAClC,OAAO,IAAI,gCAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9E,CAAC;CACF;AArDD,gDAqDC"}
1
+ {"version":3,"file":"aicf-format.strategy.js","sourceRoot":"","sources":["../../../src/formats/aicf/aicf-format.strategy.ts"],"names":[],"mappings":";;;;;;AAUA,uDAM2B;AAE3B,uEAAmE;AACnE,0DAAkC;AAClC,oDAAgD;AAChD,yCAAyC;AACzC,uDAAmD;AAEnD,MAAa,kBAAkB;IAC7B,YAA6B,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;IAAG,CAAC;IAErD,cAAc,CAAC,IAAmB;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,+BAAa,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,eAAe,CACb,IAAsB;QAEtB,IAAI,CAAC;YACH,MAAM,oBAAoB,GAAG,oCAAgB,CAAC,QAAQ,EAAE,CAAC;YACzD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,oBAAoB,CAAC,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC;YACpD,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClB,oBAAoB,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC;YACtD,CAAC;YACD,IAAI,CAAC,gBAAgB,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