logixia 1.13.3 → 2.0.0
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 +72 -16
- package/dist/{azure-monitor.transport-BDFO4F-i.d.ts → azure-monitor.transport-Cn_3Usvu.d.ts} +2 -2
- package/dist/{azure-monitor.transport-BDFO4F-i.d.ts.map → azure-monitor.transport-Cn_3Usvu.d.ts.map} +1 -1
- package/dist/{azure-monitor.transport-D5wQEH04.d.mts → azure-monitor.transport-D7Da4RAb.d.mts} +2 -2
- package/dist/{azure-monitor.transport-D5wQEH04.d.mts.map → azure-monitor.transport-D7Da4RAb.d.mts.map} +1 -1
- package/dist/azure.d.mts +2 -2
- package/dist/azure.d.ts +2 -2
- package/dist/browser.d.mts +9 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +43 -12
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +43 -12
- package/dist/browser.mjs.map +1 -1
- package/dist/{nestjs-extras-ImbuDhs1.mjs → builder-0gEzRopq.mjs} +77 -871
- package/dist/builder-0gEzRopq.mjs.map +1 -0
- package/dist/{nestjs-extras-DnJ6vrIC.js → builder-D44QktIo.js} +81 -943
- package/dist/builder-D44QktIo.js.map +1 -0
- package/dist/cli/index.js +32 -13
- package/dist/cloudwatch.d.mts +2 -2
- package/dist/cloudwatch.d.ts +2 -2
- package/dist/{cloudwatch.transport-B00st6Xv.d.ts → cloudwatch.transport-DsEq633o.d.ts} +2 -2
- package/dist/{cloudwatch.transport-B00st6Xv.d.ts.map → cloudwatch.transport-DsEq633o.d.ts.map} +1 -1
- package/dist/{cloudwatch.transport-Blc7Gtxt.d.mts → cloudwatch.transport-UlyZFWMn.d.mts} +2 -2
- package/dist/{cloudwatch.transport-Blc7Gtxt.d.mts.map → cloudwatch.transport-UlyZFWMn.d.mts.map} +1 -1
- package/dist/gcp.d.mts +2 -2
- package/dist/gcp.d.ts +2 -2
- package/dist/{gcp.transport-m4fVw0b1.d.ts → gcp.transport-B7oc97sG.d.ts} +2 -2
- package/dist/{gcp.transport-m4fVw0b1.d.ts.map → gcp.transport-B7oc97sG.d.ts.map} +1 -1
- package/dist/{gcp.transport-zzNyIoih.d.mts → gcp.transport-GrJurKo8.d.mts} +2 -2
- package/dist/{gcp.transport-zzNyIoih.d.mts.map → gcp.transport-GrJurKo8.d.mts.map} +1 -1
- package/dist/{index-BPwEisy4.d.mts → index-3mw5gaCw.d.mts} +2 -2
- package/dist/{index-BPwEisy4.d.mts.map → index-3mw5gaCw.d.mts.map} +1 -1
- package/dist/{index-nZEeCr3X.d.ts → index-DhIoploR.d.ts} +2 -2
- package/dist/{index-nZEeCr3X.d.ts.map → index-DhIoploR.d.ts.map} +1 -1
- package/dist/index.d.mts +44 -47
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +44 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -58
- package/dist/index.mjs.map +1 -1
- package/dist/logitron-logger-BFDSO8Io.d.mts +257 -0
- package/dist/logitron-logger-BFDSO8Io.d.mts.map +1 -0
- package/dist/logitron-logger-UVeN-mQm.d.ts +257 -0
- package/dist/logitron-logger-UVeN-mQm.d.ts.map +1 -0
- package/dist/middleware.d.mts +2 -2
- package/dist/middleware.d.ts +2 -2
- package/dist/nest.d.mts +481 -6
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +481 -6
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +877 -15
- package/dist/nest.js.map +1 -0
- package/dist/nest.mjs +861 -6
- package/dist/nest.mjs.map +1 -0
- package/dist/{search-DjXSn6v5.mjs → search-BFbu_oVn.mjs} +13 -3
- package/dist/{search-DjXSn6v5.mjs.map → search-BFbu_oVn.mjs.map} +1 -1
- package/dist/{search-B0MH1SJJ.js → search-C4V0OMEn.js} +13 -3
- package/dist/{search-B0MH1SJJ.js.map → search-C4V0OMEn.js.map} +1 -1
- package/dist/{search-CHUZPl0h.d.ts → search-CNh9uVwR.d.ts} +2 -2
- package/dist/search-CNh9uVwR.d.ts.map +1 -0
- package/dist/{search-BfBzDIT9.d.mts → search-DXANsQ2n.d.mts} +2 -2
- package/dist/{search-CHUZPl0h.d.ts.map → search-DXANsQ2n.d.mts.map} +1 -1
- package/dist/search.d.mts +3 -3
- package/dist/search.d.ts +3 -3
- package/dist/search.js +1 -1
- package/dist/search.mjs +1 -1
- package/dist/slack.transport-BZzoXDPn.d.mts +112 -0
- package/dist/slack.transport-BZzoXDPn.d.mts.map +1 -0
- package/dist/slack.transport-BfJRouB2.js +654 -0
- package/dist/slack.transport-BfJRouB2.js.map +1 -0
- package/dist/slack.transport-Bzw7sucI.mjs +643 -0
- package/dist/slack.transport-Bzw7sucI.mjs.map +1 -0
- package/dist/slack.transport-CXjQYOes.d.ts +112 -0
- package/dist/slack.transport-CXjQYOes.d.ts.map +1 -0
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/{transport.manager-CpdVHEGP.mjs → transport.manager-BiuCAJd2.mjs} +171 -84
- package/dist/transport.manager-BiuCAJd2.mjs.map +1 -0
- package/dist/{transport.manager-Crau3Rle.js → transport.manager-CXbKKdVE.js} +176 -83
- package/dist/transport.manager-CXbKKdVE.js.map +1 -0
- package/dist/{transport.types-CtNr3D7S.d.mts → transport.types-BMnurPcc.d.mts} +5 -2
- package/dist/transport.types-BMnurPcc.d.mts.map +1 -0
- package/dist/{transport.types-DqVLZTyf.d.ts → transport.types-CGoHpWQR.d.ts} +5 -2
- package/dist/transport.types-CGoHpWQR.d.ts.map +1 -0
- package/dist/transports.d.mts +18 -13
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +18 -13
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +5 -2
- package/dist/transports.mjs +4 -3
- package/dist/worker.d.mts +2 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/dist/worker.mjs +1 -1
- package/dist/{worker.transport-JP8YHBuU.js → worker.transport-BdPxu3PN.js} +1 -1
- package/dist/{worker.transport-JP8YHBuU.js.map → worker.transport-BdPxu3PN.js.map} +1 -1
- package/dist/{worker.transport-Bj-i0P9V.d.ts → worker.transport-CdzSZJmw.d.ts} +2 -2
- package/dist/{worker.transport-Bj-i0P9V.d.ts.map → worker.transport-CdzSZJmw.d.ts.map} +1 -1
- package/dist/{worker.transport-Bgv9heDI.d.mts → worker.transport-JvGPog3C.d.mts} +2 -2
- package/dist/{worker.transport-Bgv9heDI.d.mts.map → worker.transport-JvGPog3C.d.mts.map} +1 -1
- package/dist/{worker.transport-otwhJ_Et.mjs → worker.transport-lPxO2MVL.mjs} +1 -1
- package/dist/{worker.transport-otwhJ_Et.mjs.map → worker.transport-lPxO2MVL.mjs.map} +1 -1
- package/package.json +18 -9
- package/dist/nestjs-extras-DnJ6vrIC.js.map +0 -1
- package/dist/nestjs-extras-ImbuDhs1.mjs.map +0 -1
- package/dist/nestjs-extras-OkC796py.d.mts +0 -725
- package/dist/nestjs-extras-OkC796py.d.mts.map +0 -1
- package/dist/nestjs-extras-mKrHE9S6.d.ts +0 -725
- package/dist/nestjs-extras-mKrHE9S6.d.ts.map +0 -1
- package/dist/search-BfBzDIT9.d.mts.map +0 -1
- package/dist/transport.manager-CpdVHEGP.mjs.map +0 -1
- package/dist/transport.manager-Crau3Rle.js.map +0 -1
- package/dist/transport.types-CtNr3D7S.d.mts.map +0 -1
- package/dist/transport.types-DqVLZTyf.d.ts.map +0 -1
|
@@ -1,15 +1,86 @@
|
|
|
1
1
|
import { t as __require } from "./chunk-DLSkYcPk.mjs";
|
|
2
2
|
import { n as internalLog, r as internalWarn, t as internalError } from "./internal-log-Cm8SOWSV.mjs";
|
|
3
3
|
import { i as stringifyForLog } from "./safe-stringify-DJ66tW5I.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { i as TraceContext } from "./trace.utils-CvXgaiQT.mjs";
|
|
5
5
|
import { t as LogixiaContext } from "./async-context-BzJrbfQs.mjs";
|
|
6
6
|
import { t as safeToString } from "./coerce.utils-Cu6IUTgX.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { d as stripControlChars, t as TransportManager } from "./transport.manager-BiuCAJd2.mjs";
|
|
8
8
|
import { constants } from "node:os";
|
|
9
9
|
import buildFastStringify from "fast-json-stringify";
|
|
10
|
-
import { Catch, Inject, Injectable, Module, Optional, RequestMethod, Scope } from "@nestjs/common";
|
|
11
|
-
import { EMPTY, Observable } from "rxjs";
|
|
12
10
|
|
|
11
|
+
//#region src/types/index.ts
|
|
12
|
+
const LogLevel = {
|
|
13
|
+
ERROR: "error",
|
|
14
|
+
WARN: "warn",
|
|
15
|
+
INFO: "info",
|
|
16
|
+
DEBUG: "debug",
|
|
17
|
+
TRACE: "trace",
|
|
18
|
+
VERBOSE: "verbose"
|
|
19
|
+
};
|
|
20
|
+
const DEFAULT_LOG_LEVELS = {
|
|
21
|
+
error: 0,
|
|
22
|
+
warn: 1,
|
|
23
|
+
info: 2,
|
|
24
|
+
debug: 3,
|
|
25
|
+
trace: 4,
|
|
26
|
+
verbose: 5
|
|
27
|
+
};
|
|
28
|
+
const DEFAULT_LOG_COLORS = {
|
|
29
|
+
error: "red",
|
|
30
|
+
warn: "yellow",
|
|
31
|
+
info: "green",
|
|
32
|
+
debug: "blue",
|
|
33
|
+
trace: "magenta",
|
|
34
|
+
verbose: "cyan"
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/core/default-config.ts
|
|
39
|
+
/**
|
|
40
|
+
* Default configuration for Logixia logger
|
|
41
|
+
*/
|
|
42
|
+
const DEFAULT_CONFIG = {
|
|
43
|
+
appName: "App",
|
|
44
|
+
environment: "development",
|
|
45
|
+
traceId: true,
|
|
46
|
+
format: {
|
|
47
|
+
timestamp: true,
|
|
48
|
+
colorize: true,
|
|
49
|
+
json: false
|
|
50
|
+
},
|
|
51
|
+
silent: false,
|
|
52
|
+
levelOptions: {
|
|
53
|
+
level: LogLevel.INFO,
|
|
54
|
+
levels: {
|
|
55
|
+
[LogLevel.ERROR]: 0,
|
|
56
|
+
[LogLevel.WARN]: 1,
|
|
57
|
+
[LogLevel.INFO]: 2,
|
|
58
|
+
[LogLevel.DEBUG]: 3,
|
|
59
|
+
[LogLevel.TRACE]: 4,
|
|
60
|
+
[LogLevel.VERBOSE]: 5
|
|
61
|
+
},
|
|
62
|
+
colors: {
|
|
63
|
+
[LogLevel.ERROR]: "red",
|
|
64
|
+
[LogLevel.WARN]: "yellow",
|
|
65
|
+
[LogLevel.INFO]: "blue",
|
|
66
|
+
[LogLevel.DEBUG]: "green",
|
|
67
|
+
[LogLevel.TRACE]: "gray",
|
|
68
|
+
[LogLevel.VERBOSE]: "cyan"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
fields: {
|
|
72
|
+
timestamp: true,
|
|
73
|
+
level: true,
|
|
74
|
+
appName: true,
|
|
75
|
+
traceId: true,
|
|
76
|
+
message: true,
|
|
77
|
+
payload: true,
|
|
78
|
+
timeTaken: true
|
|
79
|
+
},
|
|
80
|
+
outputs: ["console"]
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
13
84
|
//#region src/plugin.ts
|
|
14
85
|
/**
|
|
15
86
|
* Holds an ordered list of `LogixiaPlugin` instances and dispatches lifecycle
|
|
@@ -116,33 +187,6 @@ function usePlugin(plugin) {
|
|
|
116
187
|
globalPluginRegistry.register(plugin);
|
|
117
188
|
}
|
|
118
189
|
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/types/index.ts
|
|
121
|
-
const LogLevel = {
|
|
122
|
-
ERROR: "error",
|
|
123
|
-
WARN: "warn",
|
|
124
|
-
INFO: "info",
|
|
125
|
-
DEBUG: "debug",
|
|
126
|
-
TRACE: "trace",
|
|
127
|
-
VERBOSE: "verbose"
|
|
128
|
-
};
|
|
129
|
-
const DEFAULT_LOG_LEVELS = {
|
|
130
|
-
error: 0,
|
|
131
|
-
warn: 1,
|
|
132
|
-
info: 2,
|
|
133
|
-
debug: 3,
|
|
134
|
-
trace: 4,
|
|
135
|
-
verbose: 5
|
|
136
|
-
};
|
|
137
|
-
const DEFAULT_LOG_COLORS = {
|
|
138
|
-
error: "red",
|
|
139
|
-
warn: "yellow",
|
|
140
|
-
info: "green",
|
|
141
|
-
debug: "blue",
|
|
142
|
-
trace: "magenta",
|
|
143
|
-
verbose: "cyan"
|
|
144
|
-
};
|
|
145
|
-
|
|
146
190
|
//#endregion
|
|
147
191
|
//#region src/utils/error.utils.ts
|
|
148
192
|
const EXTRA_FIELDS = [
|
|
@@ -1722,683 +1766,6 @@ function createLogger(config, context) {
|
|
|
1722
1766
|
return logger;
|
|
1723
1767
|
}
|
|
1724
1768
|
|
|
1725
|
-
//#endregion
|
|
1726
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/decorateMetadata.js
|
|
1727
|
-
function __decorateMetadata(k, v) {
|
|
1728
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
//#endregion
|
|
1732
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/decorate.js
|
|
1733
|
-
function __decorate(decorators, target, key, desc) {
|
|
1734
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1735
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1736
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1737
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
//#endregion
|
|
1741
|
-
//#region src/core/logitron-nestjs.service.ts
|
|
1742
|
-
var _LogixiaLoggerService;
|
|
1743
|
-
let LogixiaLoggerService = _LogixiaLoggerService = class LogixiaLoggerService$1 {
|
|
1744
|
-
constructor(config) {
|
|
1745
|
-
this._mergedConfig = {
|
|
1746
|
-
appName: "NestJS-App",
|
|
1747
|
-
environment: "development",
|
|
1748
|
-
traceId: true,
|
|
1749
|
-
format: {
|
|
1750
|
-
timestamp: true,
|
|
1751
|
-
colorize: true,
|
|
1752
|
-
json: false
|
|
1753
|
-
},
|
|
1754
|
-
silent: false,
|
|
1755
|
-
levelOptions: {
|
|
1756
|
-
level: LogLevel.INFO,
|
|
1757
|
-
levels: {
|
|
1758
|
-
error: 0,
|
|
1759
|
-
warn: 1,
|
|
1760
|
-
log: 2,
|
|
1761
|
-
debug: 3,
|
|
1762
|
-
verbose: 4
|
|
1763
|
-
},
|
|
1764
|
-
colors: {
|
|
1765
|
-
error: "red",
|
|
1766
|
-
warn: "yellow",
|
|
1767
|
-
log: "green",
|
|
1768
|
-
debug: "blue",
|
|
1769
|
-
verbose: "cyan"
|
|
1770
|
-
}
|
|
1771
|
-
},
|
|
1772
|
-
fields: {
|
|
1773
|
-
timestamp: "[yyyy-mm-dd HH:MM:ss.MS]",
|
|
1774
|
-
level: "[log_level]",
|
|
1775
|
-
appName: "[app_name]",
|
|
1776
|
-
traceId: "[trace_id]",
|
|
1777
|
-
message: "[message]",
|
|
1778
|
-
payload: "[payload]",
|
|
1779
|
-
timeTaken: "[time_taken_MS]"
|
|
1780
|
-
},
|
|
1781
|
-
...config
|
|
1782
|
-
};
|
|
1783
|
-
this.logger = new LogixiaLogger(this._mergedConfig);
|
|
1784
|
-
this._createCustomLevelMethods();
|
|
1785
|
-
}
|
|
1786
|
-
_createCustomLevelMethods() {
|
|
1787
|
-
var _this$_mergedConfig$l;
|
|
1788
|
-
const levels = (_this$_mergedConfig$l = this._mergedConfig.levelOptions) === null || _this$_mergedConfig$l === void 0 ? void 0 : _this$_mergedConfig$l.levels;
|
|
1789
|
-
if (!levels) return;
|
|
1790
|
-
for (const levelName of Object.keys(levels)) {
|
|
1791
|
-
const lower = levelName.toLowerCase();
|
|
1792
|
-
if (typeof this[lower] !== "undefined") continue;
|
|
1793
|
-
this[lower] = async (message, data) => {
|
|
1794
|
-
return this.logger.logLevel(lower, message, data);
|
|
1795
|
-
};
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* NestJS `LoggerService.log` — void, string context.
|
|
1800
|
-
* Maps internally to `info`.
|
|
1801
|
-
*
|
|
1802
|
-
* @example `logger.log('User signed up', 'AuthService')`
|
|
1803
|
-
*/
|
|
1804
|
-
log(message, context) {
|
|
1805
|
-
this.setContextIfProvided(context);
|
|
1806
|
-
this.logger.info(this.formatMessage(message)).catch((err) => internalError("LogixiaLoggerService.log failed", err));
|
|
1807
|
-
}
|
|
1808
|
-
/**
|
|
1809
|
-
* Native async `info` — structured data, returns `Promise<void>`.
|
|
1810
|
-
*
|
|
1811
|
-
* @example `await logger.info('User signed up', { userId: 'u_abc' })`
|
|
1812
|
-
*/
|
|
1813
|
-
async info(message, data) {
|
|
1814
|
-
return this.logger.info(message, data);
|
|
1815
|
-
}
|
|
1816
|
-
error(message, dataOrTrace, context) {
|
|
1817
|
-
if (typeof dataOrTrace === "object" && dataOrTrace !== null) return message instanceof Error ? this.logger.error(message, dataOrTrace) : this.logger.error(this.formatMessage(message), dataOrTrace);
|
|
1818
|
-
this.setContextIfProvided(context);
|
|
1819
|
-
const errorData = {};
|
|
1820
|
-
if (typeof dataOrTrace === "string" && dataOrTrace) errorData.stack = dataOrTrace;
|
|
1821
|
-
(message instanceof Error ? this.logger.error(message, errorData) : this.logger.error(this.formatMessage(message), errorData)).catch((err) => internalError("LogixiaLoggerService.error failed", err));
|
|
1822
|
-
}
|
|
1823
|
-
warn(message, dataOrContext) {
|
|
1824
|
-
if (typeof dataOrContext === "object" && dataOrContext !== null) return this.logger.warn(this.formatMessage(message), dataOrContext);
|
|
1825
|
-
this.setContextIfProvided(typeof dataOrContext === "string" ? dataOrContext : void 0);
|
|
1826
|
-
this.logger.warn(this.formatMessage(message)).catch((err) => internalError("LogixiaLoggerService.warn failed", err));
|
|
1827
|
-
}
|
|
1828
|
-
debug(message, dataOrContext) {
|
|
1829
|
-
if (typeof dataOrContext === "object" && dataOrContext !== null) return this.logger.debug(this.formatMessage(message), dataOrContext);
|
|
1830
|
-
this.setContextIfProvided(typeof dataOrContext === "string" ? dataOrContext : void 0);
|
|
1831
|
-
this.logger.debug(this.formatMessage(message)).catch((err) => internalError("LogixiaLoggerService.debug failed", err));
|
|
1832
|
-
}
|
|
1833
|
-
verbose(message, dataOrContext) {
|
|
1834
|
-
if (typeof dataOrContext === "object" && dataOrContext !== null) return this.logger.trace(this.formatMessage(message), dataOrContext);
|
|
1835
|
-
this.setContextIfProvided(typeof dataOrContext === "string" ? dataOrContext : void 0);
|
|
1836
|
-
this.logger.trace(this.formatMessage(message)).catch((err) => internalError("LogixiaLoggerService.verbose failed", err));
|
|
1837
|
-
}
|
|
1838
|
-
/**
|
|
1839
|
-
* Native async `trace` — lowest verbosity level, structured data.
|
|
1840
|
-
*/
|
|
1841
|
-
async trace(message, data) {
|
|
1842
|
-
return this.logger.trace(message, data);
|
|
1843
|
-
}
|
|
1844
|
-
/**
|
|
1845
|
-
* Log at any named level with structured data.
|
|
1846
|
-
*/
|
|
1847
|
-
logLevel(level, message, data) {
|
|
1848
|
-
return this.logger.logLevel(level, message, data);
|
|
1849
|
-
}
|
|
1850
|
-
time(label) {
|
|
1851
|
-
this.logger.time(label);
|
|
1852
|
-
}
|
|
1853
|
-
async timeEnd(label) {
|
|
1854
|
-
return this.logger.timeEnd(label);
|
|
1855
|
-
}
|
|
1856
|
-
async timeAsync(label, fn) {
|
|
1857
|
-
return this.logger.timeAsync(label, fn);
|
|
1858
|
-
}
|
|
1859
|
-
setContext(context) {
|
|
1860
|
-
const coerced = typeof context === "string" ? context : safeToString(context);
|
|
1861
|
-
this.context = coerced;
|
|
1862
|
-
this.logger.setContext(coerced);
|
|
1863
|
-
}
|
|
1864
|
-
getContext() {
|
|
1865
|
-
return this.context;
|
|
1866
|
-
}
|
|
1867
|
-
setLevel(level) {
|
|
1868
|
-
this.logger.setLevel(level);
|
|
1869
|
-
}
|
|
1870
|
-
getLevel() {
|
|
1871
|
-
return this.logger.getLevel();
|
|
1872
|
-
}
|
|
1873
|
-
child(context, data) {
|
|
1874
|
-
const childService = new _LogixiaLoggerService(this._mergedConfig);
|
|
1875
|
-
childService.logger = this.logger.child(context, data);
|
|
1876
|
-
childService.context = context;
|
|
1877
|
-
return childService;
|
|
1878
|
-
}
|
|
1879
|
-
getCurrentTraceId() {
|
|
1880
|
-
return TraceContext.instance.getCurrentTraceId();
|
|
1881
|
-
}
|
|
1882
|
-
/** Returns the AsyncLocalStorage key currently used to store the trace ID. */
|
|
1883
|
-
get traceContextKey() {
|
|
1884
|
-
return getTraceContextKey();
|
|
1885
|
-
}
|
|
1886
|
-
async close() {
|
|
1887
|
-
return this.logger.close();
|
|
1888
|
-
}
|
|
1889
|
-
static create(config) {
|
|
1890
|
-
return new _LogixiaLoggerService(config);
|
|
1891
|
-
}
|
|
1892
|
-
getLogger() {
|
|
1893
|
-
return this.logger;
|
|
1894
|
-
}
|
|
1895
|
-
setContextIfProvided(context) {
|
|
1896
|
-
if (typeof context !== "string" || context.length === 0) return;
|
|
1897
|
-
if (context !== this.context) this.setContext(context);
|
|
1898
|
-
}
|
|
1899
|
-
formatMessage(message) {
|
|
1900
|
-
if (typeof message === "string") return message;
|
|
1901
|
-
return safeToString(message);
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
LogixiaLoggerService = _LogixiaLoggerService = __decorate([Injectable({ scope: Scope.TRANSIENT }), __decorateMetadata("design:paramtypes", [Object])], LogixiaLoggerService);
|
|
1905
|
-
|
|
1906
|
-
//#endregion
|
|
1907
|
-
//#region src/core/kafka-trace.interceptor.ts
|
|
1908
|
-
var _KafkaTraceInterceptor;
|
|
1909
|
-
let KafkaTraceInterceptor = class KafkaTraceInterceptor$1 {
|
|
1910
|
-
static {
|
|
1911
|
-
_KafkaTraceInterceptor = this;
|
|
1912
|
-
}
|
|
1913
|
-
static #_ = this.metrics = {
|
|
1914
|
-
accepted: 0,
|
|
1915
|
-
acceptedWithoutTrace: 0,
|
|
1916
|
-
dropped: 0
|
|
1917
|
-
};
|
|
1918
|
-
/** Reset counters (tests). */
|
|
1919
|
-
static resetMetrics() {
|
|
1920
|
-
_KafkaTraceInterceptor.metrics.accepted = 0;
|
|
1921
|
-
_KafkaTraceInterceptor.metrics.acceptedWithoutTrace = 0;
|
|
1922
|
-
_KafkaTraceInterceptor.metrics.dropped = 0;
|
|
1923
|
-
}
|
|
1924
|
-
/**
|
|
1925
|
-
* @param config - TraceIdConfig options (extractor keys, contextKey, etc.)
|
|
1926
|
-
* @param requireTraceId - When true, messages with no traceId are silently skipped
|
|
1927
|
-
* (EMPTY Observable — message is ack'd, consumer stays alive).
|
|
1928
|
-
* A WARN is logged AND `KafkaTraceInterceptor.metrics.dropped`
|
|
1929
|
-
* increments so the missing traceId is observable end-to-end.
|
|
1930
|
-
* Default: false (handler runs without trace context).
|
|
1931
|
-
*/
|
|
1932
|
-
constructor(config, requireTraceId = false) {
|
|
1933
|
-
this.config = config;
|
|
1934
|
-
this.requireTraceId = requireTraceId;
|
|
1935
|
-
this.ctx = TraceContext.instance;
|
|
1936
|
-
this.config = {
|
|
1937
|
-
enabled: true,
|
|
1938
|
-
contextKey: "traceId",
|
|
1939
|
-
extractor: {
|
|
1940
|
-
body: [
|
|
1941
|
-
"traceId",
|
|
1942
|
-
"trace_id",
|
|
1943
|
-
"x-trace-id"
|
|
1944
|
-
],
|
|
1945
|
-
header: ["x-trace-id", "trace-id"]
|
|
1946
|
-
},
|
|
1947
|
-
...config
|
|
1948
|
-
};
|
|
1949
|
-
}
|
|
1950
|
-
intercept(context, next) {
|
|
1951
|
-
var _this$config;
|
|
1952
|
-
if (!((_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enabled)) return next.handle();
|
|
1953
|
-
const rpcContext = context.switchToRpc();
|
|
1954
|
-
const data = rpcContext.getData();
|
|
1955
|
-
const rpcData = rpcContext.getContext();
|
|
1956
|
-
let traceId;
|
|
1957
|
-
if (this.config.extractor) traceId = extractTraceId({
|
|
1958
|
-
body: data,
|
|
1959
|
-
headers: (rpcData === null || rpcData === void 0 ? void 0 : rpcData.headers) ?? {},
|
|
1960
|
-
query: {},
|
|
1961
|
-
params: {}
|
|
1962
|
-
}, this.config.extractor);
|
|
1963
|
-
if (!traceId) traceId = this.ctx.getCurrentTraceId();
|
|
1964
|
-
if (!traceId) {
|
|
1965
|
-
if (this.requireTraceId) {
|
|
1966
|
-
var _LogixiaLoggerModule$;
|
|
1967
|
-
_KafkaTraceInterceptor.metrics.dropped++;
|
|
1968
|
-
(_LogixiaLoggerModule$ = LogixiaLoggerModule.getGlobalLogger()) === null || _LogixiaLoggerModule$ === void 0 || _LogixiaLoggerModule$.warn(`[KafkaTraceInterceptor] Missing traceId on topic "${rpcData === null || rpcData === void 0 ? void 0 : rpcData.topic}" — message skipped.`);
|
|
1969
|
-
return EMPTY;
|
|
1970
|
-
}
|
|
1971
|
-
_KafkaTraceInterceptor.metrics.acceptedWithoutTrace++;
|
|
1972
|
-
return next.handle();
|
|
1973
|
-
}
|
|
1974
|
-
_KafkaTraceInterceptor.metrics.accepted++;
|
|
1975
|
-
const kafkaContext = {
|
|
1976
|
-
messageType: "kafka",
|
|
1977
|
-
topic: rpcData === null || rpcData === void 0 ? void 0 : rpcData.topic,
|
|
1978
|
-
partition: rpcData === null || rpcData === void 0 ? void 0 : rpcData.partition,
|
|
1979
|
-
offset: rpcData === null || rpcData === void 0 ? void 0 : rpcData.offset,
|
|
1980
|
-
key: rpcData === null || rpcData === void 0 ? void 0 : rpcData.key,
|
|
1981
|
-
timestamp: rpcData === null || rpcData === void 0 ? void 0 : rpcData.timestamp
|
|
1982
|
-
};
|
|
1983
|
-
return new Observable((subscriber) => {
|
|
1984
|
-
let inner;
|
|
1985
|
-
this.ctx.run(traceId, () => {
|
|
1986
|
-
inner = next.handle().subscribe({
|
|
1987
|
-
next: (value) => subscriber.next(value),
|
|
1988
|
-
error: (err) => subscriber.error(err),
|
|
1989
|
-
complete: () => subscriber.complete()
|
|
1990
|
-
});
|
|
1991
|
-
}, kafkaContext);
|
|
1992
|
-
return () => inner === null || inner === void 0 ? void 0 : inner.unsubscribe();
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
};
|
|
1996
|
-
KafkaTraceInterceptor = _KafkaTraceInterceptor = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [Object, Boolean])], KafkaTraceInterceptor);
|
|
1997
|
-
|
|
1998
|
-
//#endregion
|
|
1999
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/decorateParam.js
|
|
2000
|
-
function __decorateParam(paramIndex, decorator) {
|
|
2001
|
-
return function(target, key) {
|
|
2002
|
-
decorator(target, key, paramIndex);
|
|
2003
|
-
};
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
//#endregion
|
|
2007
|
-
//#region src/core/trace.middleware.ts
|
|
2008
|
-
/** Default response header used to echo the resolved traceId back to the caller. */
|
|
2009
|
-
const DEFAULT_TRACE_RESPONSE_HEADER = "X-Trace-Id";
|
|
2010
|
-
/**
|
|
2011
|
-
* Resolve the response header name from config.
|
|
2012
|
-
* - `undefined` → default `'X-Trace-Id'`
|
|
2013
|
-
* - `string` → user's custom header
|
|
2014
|
-
* - `false` → `null` (suppress entirely)
|
|
2015
|
-
*/
|
|
2016
|
-
function resolveResponseHeader(config) {
|
|
2017
|
-
if ((config === null || config === void 0 ? void 0 : config.responseHeader) === false) return null;
|
|
2018
|
-
return (config === null || config === void 0 ? void 0 : config.responseHeader) ?? DEFAULT_TRACE_RESPONSE_HEADER;
|
|
2019
|
-
}
|
|
2020
|
-
/**
|
|
2021
|
-
* Echo the trace ID on the response, tolerating non-Express responses and
|
|
2022
|
-
* already-sent headers. NestJS can run on Fastify (reply.header() instead of
|
|
2023
|
-
* res.setHeader()), and on a closed/sent response setHeader throws — neither
|
|
2024
|
-
* should crash the request. The trace ID is still propagated via async context.
|
|
2025
|
-
*/
|
|
2026
|
-
function writeTraceHeader(res, header, traceId) {
|
|
2027
|
-
const r = res;
|
|
2028
|
-
if (r.headersSent) return;
|
|
2029
|
-
try {
|
|
2030
|
-
if (typeof r.setHeader === "function") r.setHeader(header, traceId);
|
|
2031
|
-
else if (typeof r.header === "function") r.header(header, traceId);
|
|
2032
|
-
} catch {}
|
|
2033
|
-
}
|
|
2034
|
-
let TraceMiddleware = class TraceMiddleware$1 {
|
|
2035
|
-
constructor(config) {
|
|
2036
|
-
this.config = config;
|
|
2037
|
-
this.ctx = TraceContext.instance;
|
|
2038
|
-
const defaultExtractor = {
|
|
2039
|
-
header: DEFAULT_TRACE_HEADERS,
|
|
2040
|
-
query: ["traceId", "trace_id"]
|
|
2041
|
-
};
|
|
2042
|
-
this.config = {
|
|
2043
|
-
enabled: true,
|
|
2044
|
-
generator: () => this.ctx.generate(),
|
|
2045
|
-
contextKey: "traceId",
|
|
2046
|
-
...config,
|
|
2047
|
-
extractor: (config === null || config === void 0 ? void 0 : config.extractor) ? {
|
|
2048
|
-
...defaultExtractor,
|
|
2049
|
-
...config.extractor
|
|
2050
|
-
} : defaultExtractor
|
|
2051
|
-
};
|
|
2052
|
-
if (this.config.enabled) this.ctx.setContextKey(this.config.contextKey ?? "traceId");
|
|
2053
|
-
}
|
|
2054
|
-
use(req, res, next) {
|
|
2055
|
-
var _this$config, _req$socket, _req$connection;
|
|
2056
|
-
if (!((_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enabled)) return next();
|
|
2057
|
-
let traceId;
|
|
2058
|
-
if (this.config.extractor) traceId = extractTraceId(req, this.config.extractor);
|
|
2059
|
-
if (!traceId && this.config.generator) {
|
|
2060
|
-
const candidate = this.config.generator();
|
|
2061
|
-
if (typeof candidate === "string" && candidate.trim().length > 0) traceId = candidate;
|
|
2062
|
-
else internalWarn("TraceIdConfig.generator returned a non-string/empty value — using built-in generator.");
|
|
2063
|
-
}
|
|
2064
|
-
if (!traceId) traceId = this.ctx.generate();
|
|
2065
|
-
req.traceId = traceId;
|
|
2066
|
-
const header = resolveResponseHeader(this.config);
|
|
2067
|
-
if (header) writeTraceHeader(res, header, traceId);
|
|
2068
|
-
this.ctx.run(traceId, () => next(), {
|
|
2069
|
-
method: req.method,
|
|
2070
|
-
url: req.url,
|
|
2071
|
-
userAgent: req.get("User-Agent"),
|
|
2072
|
-
ip: req.ip || ((_req$socket = req.socket) === null || _req$socket === void 0 ? void 0 : _req$socket.remoteAddress) || ((_req$connection = req.connection) === null || _req$connection === void 0 ? void 0 : _req$connection.remoteAddress)
|
|
2073
|
-
});
|
|
2074
|
-
}
|
|
2075
|
-
};
|
|
2076
|
-
TraceMiddleware = __decorate([
|
|
2077
|
-
Injectable(),
|
|
2078
|
-
__decorateParam(0, Optional()),
|
|
2079
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
2080
|
-
], TraceMiddleware);
|
|
2081
|
-
|
|
2082
|
-
//#endregion
|
|
2083
|
-
//#region src/core/websocket-trace.interceptor.ts
|
|
2084
|
-
let WebSocketTraceInterceptor = class WebSocketTraceInterceptor$1 {
|
|
2085
|
-
constructor(config) {
|
|
2086
|
-
this.config = config;
|
|
2087
|
-
this.ctx = TraceContext.instance;
|
|
2088
|
-
this.config = {
|
|
2089
|
-
enabled: true,
|
|
2090
|
-
contextKey: "traceId",
|
|
2091
|
-
extractor: {
|
|
2092
|
-
body: [
|
|
2093
|
-
"traceId",
|
|
2094
|
-
"trace_id",
|
|
2095
|
-
"x-trace-id"
|
|
2096
|
-
],
|
|
2097
|
-
header: ["x-trace-id", "trace-id"],
|
|
2098
|
-
query: ["traceId", "trace_id"]
|
|
2099
|
-
},
|
|
2100
|
-
...config
|
|
2101
|
-
};
|
|
2102
|
-
}
|
|
2103
|
-
intercept(context, next) {
|
|
2104
|
-
var _this$config, _client$handshake3;
|
|
2105
|
-
if (!((_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.enabled)) return next.handle();
|
|
2106
|
-
const wsContext = context.switchToWs();
|
|
2107
|
-
const data = wsContext.getData();
|
|
2108
|
-
const client = wsContext.getClient();
|
|
2109
|
-
let traceId;
|
|
2110
|
-
if (this.config.extractor) {
|
|
2111
|
-
var _client$handshake, _client$handshake2;
|
|
2112
|
-
traceId = extractTraceId({
|
|
2113
|
-
body: data,
|
|
2114
|
-
headers: (client === null || client === void 0 || (_client$handshake = client.handshake) === null || _client$handshake === void 0 ? void 0 : _client$handshake.headers) || {},
|
|
2115
|
-
query: (client === null || client === void 0 || (_client$handshake2 = client.handshake) === null || _client$handshake2 === void 0 ? void 0 : _client$handshake2.query) || {},
|
|
2116
|
-
params: {}
|
|
2117
|
-
}, this.config.extractor);
|
|
2118
|
-
}
|
|
2119
|
-
if (!traceId) traceId = this.ctx.getCurrentTraceId();
|
|
2120
|
-
if (!traceId) return next.handle();
|
|
2121
|
-
const wsContextData = {
|
|
2122
|
-
messageType: "websocket",
|
|
2123
|
-
event: data === null || data === void 0 ? void 0 : data.event,
|
|
2124
|
-
socketId: client === null || client === void 0 ? void 0 : client.id,
|
|
2125
|
-
rooms: (client === null || client === void 0 ? void 0 : client.rooms) ? Array.from(client.rooms) : [],
|
|
2126
|
-
clientAddress: client === null || client === void 0 || (_client$handshake3 = client.handshake) === null || _client$handshake3 === void 0 ? void 0 : _client$handshake3.address
|
|
2127
|
-
};
|
|
2128
|
-
return new Observable((observer) => {
|
|
2129
|
-
let inner;
|
|
2130
|
-
this.ctx.run(traceId, () => {
|
|
2131
|
-
inner = next.handle().subscribe({
|
|
2132
|
-
next: (value) => observer.next(value),
|
|
2133
|
-
error: (err) => observer.error(err),
|
|
2134
|
-
complete: () => observer.complete()
|
|
2135
|
-
});
|
|
2136
|
-
}, wsContextData);
|
|
2137
|
-
return () => inner === null || inner === void 0 ? void 0 : inner.unsubscribe();
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
};
|
|
2141
|
-
WebSocketTraceInterceptor = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [Object])], WebSocketTraceInterceptor);
|
|
2142
|
-
|
|
2143
|
-
//#endregion
|
|
2144
|
-
//#region src/core/logitron-logger.module.ts
|
|
2145
|
-
var _LogixiaLoggerModule;
|
|
2146
|
-
const DEFAULT_ROUTES = [{
|
|
2147
|
-
path: "*",
|
|
2148
|
-
method: RequestMethod.ALL
|
|
2149
|
-
}];
|
|
2150
|
-
const LOGIXIA_LOGGER_CONFIG = "LOGIXIA_LOGGER_CONFIG";
|
|
2151
|
-
const LOGIXIA_TRACE_CONFIG = "TRACE_CONFIG";
|
|
2152
|
-
const LOGIXIA_LOGGER_PREFIX = "LOGIXIA_LOGGER_";
|
|
2153
|
-
let LogixiaLoggerModule = class LogixiaLoggerModule$1 {
|
|
2154
|
-
static {
|
|
2155
|
-
_LogixiaLoggerModule = this;
|
|
2156
|
-
}
|
|
2157
|
-
constructor() {
|
|
2158
|
-
this.config = {};
|
|
2159
|
-
}
|
|
2160
|
-
static #_ = this.loggerConfig = {};
|
|
2161
|
-
static #_2 = this._globalLogger = null;
|
|
2162
|
-
/**
|
|
2163
|
-
* @internal Set the global logger exactly once.
|
|
2164
|
-
*
|
|
2165
|
-
* Called from the module's forRoot / forRootAsync factory. If the module is
|
|
2166
|
-
* initialised more than once in the same process (nested DI context, test
|
|
2167
|
-
* harness creating multiple apps, hot reload, etc.) a warning is written to
|
|
2168
|
-
* stderr and the first logger wins — silently overwriting would allow the
|
|
2169
|
-
* newer instance's transport config to replace the live one while the old
|
|
2170
|
-
* one is still being used by registered shutdown hooks, decorators, etc.
|
|
2171
|
-
*
|
|
2172
|
-
* Use {@link _resetGlobalLogger} in tests to reset between runs.
|
|
2173
|
-
*/
|
|
2174
|
-
static _setGlobalLogger(service) {
|
|
2175
|
-
if (_LogixiaLoggerModule._globalLogger !== null) {
|
|
2176
|
-
internalWarn("LogixiaLoggerModule.forRoot() was called more than once — ignoring the second init. If this is intentional (e.g. in tests), call LogixiaLoggerModule._resetGlobalLogger() first.");
|
|
2177
|
-
return;
|
|
2178
|
-
}
|
|
2179
|
-
_LogixiaLoggerModule._globalLogger = service;
|
|
2180
|
-
}
|
|
2181
|
-
/** @internal Clear the global logger. Tests only. */
|
|
2182
|
-
static _resetGlobalLogger() {
|
|
2183
|
-
_LogixiaLoggerModule._globalLogger = null;
|
|
2184
|
-
}
|
|
2185
|
-
/**
|
|
2186
|
-
* Returns the global LogixiaLoggerService instance that was created when the
|
|
2187
|
-
* module booted. Useful for logging outside of NestJS DI — utility functions,
|
|
2188
|
-
* plain scripts, decorators — without injecting the service everywhere.
|
|
2189
|
-
*
|
|
2190
|
-
* Returns `null` if called before `LogixiaLoggerModule.forRoot[Async]()` has
|
|
2191
|
-
* been initialised (i.e. before the NestJS app has started).
|
|
2192
|
-
*
|
|
2193
|
-
* @example
|
|
2194
|
-
* ```ts
|
|
2195
|
-
* // some-util.ts
|
|
2196
|
-
* import { LogixiaLoggerModule } from 'logixia/nest';
|
|
2197
|
-
*
|
|
2198
|
-
* export function doSomething() {
|
|
2199
|
-
* LogixiaLoggerModule.getGlobalLogger()?.info('doing something');
|
|
2200
|
-
* }
|
|
2201
|
-
* ```
|
|
2202
|
-
*/
|
|
2203
|
-
static getGlobalLogger() {
|
|
2204
|
-
return _LogixiaLoggerModule._globalLogger;
|
|
2205
|
-
}
|
|
2206
|
-
configure(consumer) {
|
|
2207
|
-
const { forRoutes = DEFAULT_ROUTES, exclude } = this.config;
|
|
2208
|
-
let resolvedTraceConfig;
|
|
2209
|
-
if (typeof _LogixiaLoggerModule.loggerConfig.traceId === "object") resolvedTraceConfig = _LogixiaLoggerModule.loggerConfig.traceId;
|
|
2210
|
-
else if (_LogixiaLoggerModule.loggerConfig.traceId === true) resolvedTraceConfig = {
|
|
2211
|
-
enabled: true,
|
|
2212
|
-
contextKey: "traceId",
|
|
2213
|
-
generator: () => TraceContext.instance.generate()
|
|
2214
|
-
};
|
|
2215
|
-
const middleware = new TraceMiddleware(resolvedTraceConfig);
|
|
2216
|
-
const middlewareConfig = (req, res, next) => middleware.use(req, res, next);
|
|
2217
|
-
if (exclude) consumer.apply(middlewareConfig).exclude(...exclude).forRoutes(...forRoutes);
|
|
2218
|
-
else consumer.apply(middlewareConfig).forRoutes(...forRoutes);
|
|
2219
|
-
}
|
|
2220
|
-
/**
|
|
2221
|
-
* Configure the module with synchronous options
|
|
2222
|
-
*/
|
|
2223
|
-
static forRoot(config) {
|
|
2224
|
-
_LogixiaLoggerModule.loggerConfig = config || {};
|
|
2225
|
-
const traceConfig = (config === null || config === void 0 ? void 0 : config.traceId) && typeof config.traceId === "object" ? config.traceId : { enabled: !!(config === null || config === void 0 ? void 0 : config.traceId) };
|
|
2226
|
-
return {
|
|
2227
|
-
module: _LogixiaLoggerModule,
|
|
2228
|
-
providers: [
|
|
2229
|
-
{
|
|
2230
|
-
provide: LOGIXIA_LOGGER_CONFIG,
|
|
2231
|
-
useValue: config || {}
|
|
2232
|
-
},
|
|
2233
|
-
{
|
|
2234
|
-
provide: LOGIXIA_TRACE_CONFIG,
|
|
2235
|
-
useValue: traceConfig
|
|
2236
|
-
},
|
|
2237
|
-
{
|
|
2238
|
-
provide: LogixiaLoggerService,
|
|
2239
|
-
useFactory: (loggerConfig) => {
|
|
2240
|
-
const service = new LogixiaLoggerService({
|
|
2241
|
-
level: "info",
|
|
2242
|
-
service: "NestJSApp",
|
|
2243
|
-
environment: "development",
|
|
2244
|
-
fields: {},
|
|
2245
|
-
formatters: ["text"],
|
|
2246
|
-
outputs: ["console"],
|
|
2247
|
-
levelOptions: {
|
|
2248
|
-
level: "info",
|
|
2249
|
-
levels: {
|
|
2250
|
-
error: 0,
|
|
2251
|
-
warn: 1,
|
|
2252
|
-
info: 2,
|
|
2253
|
-
debug: 3,
|
|
2254
|
-
verbose: 4
|
|
2255
|
-
},
|
|
2256
|
-
colors: {
|
|
2257
|
-
error: "red",
|
|
2258
|
-
warn: "yellow",
|
|
2259
|
-
info: "green",
|
|
2260
|
-
debug: "blue",
|
|
2261
|
-
verbose: "cyan"
|
|
2262
|
-
}
|
|
2263
|
-
},
|
|
2264
|
-
...loggerConfig
|
|
2265
|
-
});
|
|
2266
|
-
_LogixiaLoggerModule._setGlobalLogger(service);
|
|
2267
|
-
return service;
|
|
2268
|
-
},
|
|
2269
|
-
inject: [LOGIXIA_LOGGER_CONFIG]
|
|
2270
|
-
},
|
|
2271
|
-
{
|
|
2272
|
-
provide: KafkaTraceInterceptor,
|
|
2273
|
-
useFactory: (traceConfig$1) => new KafkaTraceInterceptor(traceConfig$1),
|
|
2274
|
-
inject: [LOGIXIA_TRACE_CONFIG]
|
|
2275
|
-
},
|
|
2276
|
-
{
|
|
2277
|
-
provide: WebSocketTraceInterceptor,
|
|
2278
|
-
useFactory: (traceConfig$1) => new WebSocketTraceInterceptor(traceConfig$1),
|
|
2279
|
-
inject: [LOGIXIA_TRACE_CONFIG]
|
|
2280
|
-
}
|
|
2281
|
-
],
|
|
2282
|
-
exports: [
|
|
2283
|
-
LogixiaLoggerService,
|
|
2284
|
-
LOGIXIA_LOGGER_CONFIG,
|
|
2285
|
-
KafkaTraceInterceptor,
|
|
2286
|
-
WebSocketTraceInterceptor
|
|
2287
|
-
],
|
|
2288
|
-
global: true
|
|
2289
|
-
};
|
|
2290
|
-
}
|
|
2291
|
-
/**
|
|
2292
|
-
* Configure the module with asynchronous options
|
|
2293
|
-
*/
|
|
2294
|
-
static forRootAsync(options) {
|
|
2295
|
-
return {
|
|
2296
|
-
module: _LogixiaLoggerModule,
|
|
2297
|
-
imports: options.imports || [],
|
|
2298
|
-
providers: [
|
|
2299
|
-
...this.createAsyncProviders(options),
|
|
2300
|
-
{
|
|
2301
|
-
provide: LOGIXIA_TRACE_CONFIG,
|
|
2302
|
-
useFactory: (loggerConfig) => {
|
|
2303
|
-
return typeof (loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) === "object" ? loggerConfig.traceId : { enabled: !!(loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) };
|
|
2304
|
-
},
|
|
2305
|
-
inject: [LOGIXIA_LOGGER_CONFIG]
|
|
2306
|
-
},
|
|
2307
|
-
{
|
|
2308
|
-
provide: LogixiaLoggerService,
|
|
2309
|
-
useFactory: (loggerConfig) => {
|
|
2310
|
-
const defaultConfig = {
|
|
2311
|
-
level: "info",
|
|
2312
|
-
service: "NestJSApp",
|
|
2313
|
-
environment: "development",
|
|
2314
|
-
fields: {},
|
|
2315
|
-
formatters: ["text"],
|
|
2316
|
-
outputs: ["console"],
|
|
2317
|
-
levelOptions: {
|
|
2318
|
-
level: "info",
|
|
2319
|
-
levels: {
|
|
2320
|
-
error: 0,
|
|
2321
|
-
warn: 1,
|
|
2322
|
-
info: 2,
|
|
2323
|
-
debug: 3,
|
|
2324
|
-
verbose: 4
|
|
2325
|
-
},
|
|
2326
|
-
colors: {
|
|
2327
|
-
error: "red",
|
|
2328
|
-
warn: "yellow",
|
|
2329
|
-
info: "green",
|
|
2330
|
-
debug: "blue",
|
|
2331
|
-
verbose: "cyan"
|
|
2332
|
-
}
|
|
2333
|
-
},
|
|
2334
|
-
...loggerConfig
|
|
2335
|
-
};
|
|
2336
|
-
_LogixiaLoggerModule.loggerConfig = defaultConfig;
|
|
2337
|
-
const service = new LogixiaLoggerService(defaultConfig);
|
|
2338
|
-
_LogixiaLoggerModule._setGlobalLogger(service);
|
|
2339
|
-
return service;
|
|
2340
|
-
},
|
|
2341
|
-
inject: [LOGIXIA_LOGGER_CONFIG]
|
|
2342
|
-
},
|
|
2343
|
-
{
|
|
2344
|
-
provide: KafkaTraceInterceptor,
|
|
2345
|
-
useFactory: (traceConfig) => new KafkaTraceInterceptor(traceConfig),
|
|
2346
|
-
inject: [LOGIXIA_TRACE_CONFIG]
|
|
2347
|
-
},
|
|
2348
|
-
{
|
|
2349
|
-
provide: WebSocketTraceInterceptor,
|
|
2350
|
-
useFactory: (traceConfig) => new WebSocketTraceInterceptor(traceConfig),
|
|
2351
|
-
inject: [LOGIXIA_TRACE_CONFIG]
|
|
2352
|
-
}
|
|
2353
|
-
],
|
|
2354
|
-
exports: [
|
|
2355
|
-
LogixiaLoggerService,
|
|
2356
|
-
LOGIXIA_LOGGER_CONFIG,
|
|
2357
|
-
KafkaTraceInterceptor,
|
|
2358
|
-
WebSocketTraceInterceptor
|
|
2359
|
-
],
|
|
2360
|
-
global: true
|
|
2361
|
-
};
|
|
2362
|
-
}
|
|
2363
|
-
/**
|
|
2364
|
-
* Create feature-specific logger instances
|
|
2365
|
-
*/
|
|
2366
|
-
static forFeature(context) {
|
|
2367
|
-
const providerToken = `${LOGIXIA_LOGGER_PREFIX}${context.toUpperCase()}`;
|
|
2368
|
-
return {
|
|
2369
|
-
module: _LogixiaLoggerModule,
|
|
2370
|
-
providers: [{
|
|
2371
|
-
provide: providerToken,
|
|
2372
|
-
useFactory: (baseLogger) => {
|
|
2373
|
-
return baseLogger.child(context);
|
|
2374
|
-
},
|
|
2375
|
-
inject: [LogixiaLoggerService]
|
|
2376
|
-
}],
|
|
2377
|
-
exports: [providerToken]
|
|
2378
|
-
};
|
|
2379
|
-
}
|
|
2380
|
-
static createAsyncProviders(options) {
|
|
2381
|
-
if (options.useExisting || options.useFactory) return [this.createAsyncOptionsProvider(options)];
|
|
2382
|
-
return [this.createAsyncOptionsProvider(options), {
|
|
2383
|
-
provide: options.useClass,
|
|
2384
|
-
useClass: options.useClass
|
|
2385
|
-
}];
|
|
2386
|
-
}
|
|
2387
|
-
static createAsyncOptionsProvider(options) {
|
|
2388
|
-
if (options.useFactory) return {
|
|
2389
|
-
provide: LOGIXIA_LOGGER_CONFIG,
|
|
2390
|
-
useFactory: options.useFactory,
|
|
2391
|
-
inject: options.inject || []
|
|
2392
|
-
};
|
|
2393
|
-
return {
|
|
2394
|
-
provide: LOGIXIA_LOGGER_CONFIG,
|
|
2395
|
-
useFactory: async (optionsFactory) => await optionsFactory.createLogixiaOptions(),
|
|
2396
|
-
inject: [options.useExisting || options.useClass]
|
|
2397
|
-
};
|
|
2398
|
-
}
|
|
2399
|
-
};
|
|
2400
|
-
LogixiaLoggerModule = _LogixiaLoggerModule = __decorate([Module({})], LogixiaLoggerModule);
|
|
2401
|
-
|
|
2402
1769
|
//#endregion
|
|
2403
1770
|
//#region src/exceptions/exception.ts
|
|
2404
1771
|
var LogixiaException = class extends Error {
|
|
@@ -2613,166 +1980,5 @@ var ErrorResponseBuilder = class {
|
|
|
2613
1980
|
};
|
|
2614
1981
|
|
|
2615
1982
|
//#endregion
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
/**
|
|
2619
|
-
* Inject the Logixia logger registered in the current NestJS DI container.
|
|
2620
|
-
*
|
|
2621
|
-
* Equivalent to `@Inject(LOGIXIA_LOGGER_TOKEN)` but without needing to import
|
|
2622
|
-
* the internal token constant yourself.
|
|
2623
|
-
*
|
|
2624
|
-
* @example
|
|
2625
|
-
* ```ts
|
|
2626
|
-
* constructor(@InjectLogger() private readonly logger: LogixiaLoggerService) {}
|
|
2627
|
-
* ```
|
|
2628
|
-
*/
|
|
2629
|
-
const InjectLogger = () => Inject(`${LOGIXIA_LOGGER_PREFIX}SERVICE`);
|
|
2630
|
-
/**
|
|
2631
|
-
* Method decorator that auto-logs entry, exit, duration, and errors.
|
|
2632
|
-
*
|
|
2633
|
-
* Preserves the original method's sync/async contract: a synchronous method
|
|
2634
|
-
* stays synchronous (returns its value directly, with logs emitted
|
|
2635
|
-
* fire-and-forget), and an async method is awaited so exit/error logs reflect
|
|
2636
|
-
* the resolved result. Attaches to the logger found on the class instance via a
|
|
2637
|
-
* `logger` property (the conventional NestJS name).
|
|
2638
|
-
*
|
|
2639
|
-
* @example
|
|
2640
|
-
* ```ts
|
|
2641
|
-
* @LogMethod({ level: 'info', logArgs: true })
|
|
2642
|
-
* async processPayment(orderId: string): Promise<void> { … }
|
|
2643
|
-
* ```
|
|
2644
|
-
*/
|
|
2645
|
-
function LogMethod(options = {}) {
|
|
2646
|
-
const { level = "debug", logArgs = true, logResult = false, logErrors = true } = options;
|
|
2647
|
-
return function(target, propertyKey, descriptor) {
|
|
2648
|
-
var _constructor;
|
|
2649
|
-
const originalMethod = descriptor.value;
|
|
2650
|
-
if (typeof originalMethod !== "function") return descriptor;
|
|
2651
|
-
const methodName = String(propertyKey);
|
|
2652
|
-
const className = ((_constructor = target.constructor) === null || _constructor === void 0 ? void 0 : _constructor.name) ?? "Unknown";
|
|
2653
|
-
const label = options.label ?? `${className}.${methodName}`;
|
|
2654
|
-
let _warnedNoLogger = false;
|
|
2655
|
-
const reportLogFailure = (phase, err) => {
|
|
2656
|
-
internalError(`@LogMethod(${label}) ${phase} log failed: ${String(err)}`);
|
|
2657
|
-
};
|
|
2658
|
-
const emit = (logger, phase, message, data) => {
|
|
2659
|
-
const logFnRaw = logger[level];
|
|
2660
|
-
const p = (typeof logFnRaw === "function" ? logFnRaw : logger.debug).bind(logger)(message, data);
|
|
2661
|
-
if (p && typeof p.catch === "function") p.catch((e) => reportLogFailure(phase, e));
|
|
2662
|
-
};
|
|
2663
|
-
const emitError = (logger, error, start) => {
|
|
2664
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
2665
|
-
const errLog = logger.error(err, {
|
|
2666
|
-
method: label,
|
|
2667
|
-
durationMs: Date.now() - start
|
|
2668
|
-
});
|
|
2669
|
-
if (errLog && typeof errLog.catch === "function") errLog.catch((e) => reportLogFailure("error", e));
|
|
2670
|
-
};
|
|
2671
|
-
descriptor.value = function(...args) {
|
|
2672
|
-
const logger = this.logger ?? LogixiaLoggerModule._globalLogger ?? void 0;
|
|
2673
|
-
if (!logger && !_warnedNoLogger) {
|
|
2674
|
-
_warnedNoLogger = true;
|
|
2675
|
-
internalWarn(`@LogMethod on ${label}: no logger available. Either inject LogixiaLoggerService as this.logger or ensure LogixiaLoggerModule is initialised.`);
|
|
2676
|
-
}
|
|
2677
|
-
const start = Date.now();
|
|
2678
|
-
const entry = { method: label };
|
|
2679
|
-
if (logArgs && args.length > 0) entry["args"] = args;
|
|
2680
|
-
if (logger) emit(logger, "entry", `→ ${label}`, entry);
|
|
2681
|
-
const buildExit = (result$1) => {
|
|
2682
|
-
const exit = {
|
|
2683
|
-
method: label,
|
|
2684
|
-
durationMs: Date.now() - start
|
|
2685
|
-
};
|
|
2686
|
-
if (logResult) exit["result"] = result$1;
|
|
2687
|
-
return exit;
|
|
2688
|
-
};
|
|
2689
|
-
let result;
|
|
2690
|
-
try {
|
|
2691
|
-
result = originalMethod.apply(this, args);
|
|
2692
|
-
} catch (error) {
|
|
2693
|
-
if (logger && logErrors) emitError(logger, error, start);
|
|
2694
|
-
throw error;
|
|
2695
|
-
}
|
|
2696
|
-
if (result && typeof result.then === "function") return result.then((resolved) => {
|
|
2697
|
-
if (logger) emit(logger, "exit", `← ${label}`, buildExit(resolved));
|
|
2698
|
-
return resolved;
|
|
2699
|
-
}, (error) => {
|
|
2700
|
-
if (logger && logErrors) emitError(logger, error, start);
|
|
2701
|
-
throw error;
|
|
2702
|
-
});
|
|
2703
|
-
if (logger) emit(logger, "exit", `← ${label}`, buildExit(result));
|
|
2704
|
-
return result;
|
|
2705
|
-
};
|
|
2706
|
-
return descriptor;
|
|
2707
|
-
};
|
|
2708
|
-
}
|
|
2709
|
-
/** Injection token for {@link LogixiaExceptionFilterOptions}. */
|
|
2710
|
-
const LOGIXIA_EXCEPTION_FILTER_OPTIONS = "LOGIXIA_EXCEPTION_FILTER_OPTIONS";
|
|
2711
|
-
let LogixiaExceptionFilter = class LogixiaExceptionFilter$1 {
|
|
2712
|
-
constructor(logger, loggerConfig, options) {
|
|
2713
|
-
this._options = options ?? {};
|
|
2714
|
-
this._logger = logger ?? LogixiaLoggerModule._globalLogger ?? void 0;
|
|
2715
|
-
this._traceConfig = typeof (loggerConfig === null || loggerConfig === void 0 ? void 0 : loggerConfig.traceId) === "object" ? loggerConfig.traceId : void 0;
|
|
2716
|
-
}
|
|
2717
|
-
catch(exception, host) {
|
|
2718
|
-
var _request$headers;
|
|
2719
|
-
const ctx = host.switchToHttp();
|
|
2720
|
-
const request = ctx.getRequest();
|
|
2721
|
-
const response = ctx.getResponse();
|
|
2722
|
-
const traceId = TraceContext.instance.getCurrentTraceId() ?? sanitizeIncomingId((_request$headers = request.headers) === null || _request$headers === void 0 ? void 0 : _request$headers["x-trace-id"]) ?? sanitizeIncomingId(request.id) ?? void 0;
|
|
2723
|
-
const { response: errorResponse, httpStatus } = ErrorResponseBuilder.build({
|
|
2724
|
-
exception,
|
|
2725
|
-
traceId,
|
|
2726
|
-
path: request.url ?? "/",
|
|
2727
|
-
startTime: request.startTime,
|
|
2728
|
-
exposeDebug: this._options.exposeDebug === true,
|
|
2729
|
-
exposeCause: this._options.exposeCause === true
|
|
2730
|
-
});
|
|
2731
|
-
if (this._logger) {
|
|
2732
|
-
const requestMeta = {
|
|
2733
|
-
method: request.method ?? "",
|
|
2734
|
-
url: request.url ?? "",
|
|
2735
|
-
status: httpStatus,
|
|
2736
|
-
...errorResponse.meta.trace_id !== void 0 ? { trace_id: errorResponse.meta.trace_id } : {}
|
|
2737
|
-
};
|
|
2738
|
-
const onLogFailure = (err) => {
|
|
2739
|
-
internalError(`ExceptionFilter failed to write log entry: ${String(err)}`);
|
|
2740
|
-
};
|
|
2741
|
-
let logPromise;
|
|
2742
|
-
if (httpStatus >= 500) {
|
|
2743
|
-
const err = exception instanceof Error ? exception : new Error(String(exception));
|
|
2744
|
-
logPromise = this._logger.error(err, requestMeta);
|
|
2745
|
-
} else if (isLogixiaException(exception)) logPromise = this._logger.warn(`[${errorResponse.error.code}] ${errorResponse.error.message}`, requestMeta);
|
|
2746
|
-
else logPromise = this._logger.warn(`[${httpStatus}] ${errorResponse.error.message}`, requestMeta);
|
|
2747
|
-
if (logPromise && typeof logPromise.catch === "function") logPromise.catch(onLogFailure);
|
|
2748
|
-
}
|
|
2749
|
-
if (errorResponse.meta.trace_id) {
|
|
2750
|
-
const traceHeader = resolveResponseHeader(this._traceConfig);
|
|
2751
|
-
if (traceHeader) try {
|
|
2752
|
-
response.setHeader(traceHeader, errorResponse.meta.trace_id);
|
|
2753
|
-
} catch {}
|
|
2754
|
-
}
|
|
2755
|
-
if (httpStatus === 429) try {
|
|
2756
|
-
response.setHeader("Retry-After", "60");
|
|
2757
|
-
} catch {}
|
|
2758
|
-
response.status(httpStatus).json(errorResponse);
|
|
2759
|
-
}
|
|
2760
|
-
};
|
|
2761
|
-
LogixiaExceptionFilter = __decorate([
|
|
2762
|
-
Catch(),
|
|
2763
|
-
__decorateParam(0, Optional()),
|
|
2764
|
-
__decorateParam(0, Inject(`${LOGIXIA_LOGGER_PREFIX}SERVICE`)),
|
|
2765
|
-
__decorateParam(1, Optional()),
|
|
2766
|
-
__decorateParam(1, Inject(LOGIXIA_LOGGER_CONFIG)),
|
|
2767
|
-
__decorateParam(2, Optional()),
|
|
2768
|
-
__decorateParam(2, Inject(LOGIXIA_EXCEPTION_FILTER_OPTIONS)),
|
|
2769
|
-
__decorateMetadata("design:paramtypes", [
|
|
2770
|
-
Object,
|
|
2771
|
-
typeof (_ref = typeof Partial !== "undefined" && Partial) === "function" ? _ref : Object,
|
|
2772
|
-
Object
|
|
2773
|
-
])
|
|
2774
|
-
], LogixiaExceptionFilter);
|
|
2775
|
-
|
|
2776
|
-
//#endregion
|
|
2777
|
-
export { initOtelBridge as A, registerForShutdown as C, disableOtelBridge as D, redactObject as E, DEFAULT_LOG_LEVELS as F, LogLevel as I, PluginRegistry as L, normalizeError as M, serializeError as N, getActiveOtelContext as O, DEFAULT_LOG_COLORS as P, globalPluginRegistry as R, flushOnExit as S, applyRedaction as T, LogixiaLoggerService as _, ErrorResponseBuilder as a, _shutdownRegistrySize as b, LogixiaException as c, LOGIXIA_LOGGER_PREFIX as d, LOGIXIA_TRACE_CONFIG as f, KafkaTraceInterceptor as g, TraceMiddleware as h, LogixiaExceptionFilter as i, isError as j, getOtelMetaFields as k, isLogixiaException as l, WebSocketTraceInterceptor as m, LOGIXIA_EXCEPTION_FILTER_OPTIONS as n, generateRequestId as o, LogixiaLoggerModule as p, LogMethod as r, generateTraceId as s, InjectLogger as t, LOGIXIA_LOGGER_CONFIG as u, LogixiaLogger as v, resetShutdownHandlers as w, deregisterFromShutdown as x, createLogger as y, usePlugin as z };
|
|
2778
|
-
//# sourceMappingURL=nestjs-extras-ImbuDhs1.mjs.map
|
|
1983
|
+
export { globalPluginRegistry as C, DEFAULT_LOG_LEVELS as D, DEFAULT_LOG_COLORS as E, LogLevel as O, PluginRegistry as S, DEFAULT_CONFIG as T, getOtelMetaFields as _, isLogixiaException as a, normalizeError as b, _shutdownRegistrySize as c, registerForShutdown as d, resetShutdownHandlers as f, getActiveOtelContext as g, disableOtelBridge as h, LogixiaException as i, deregisterFromShutdown as l, redactObject as m, generateRequestId as n, LogixiaLogger as o, applyRedaction as p, generateTraceId as r, createLogger as s, ErrorResponseBuilder as t, flushOnExit as u, initOtelBridge as v, usePlugin as w, serializeError as x, isError as y };
|
|
1984
|
+
//# sourceMappingURL=builder-0gEzRopq.mjs.map
|