@crimson-education/browser-logger 2.0.2 → 3.0.1-pinpoint-middleware.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 +212 -67
- package/lib/index.d.ts +12 -82
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +69 -213
- package/lib/index.js.map +1 -1
- package/lib/logger/consoleTransport.d.ts +37 -0
- package/lib/logger/consoleTransport.d.ts.map +1 -0
- package/lib/logger/consoleTransport.js +81 -0
- package/lib/logger/consoleTransport.js.map +1 -0
- package/lib/logger/datadogTransport.d.ts +8 -0
- package/lib/logger/datadogTransport.d.ts.map +1 -0
- package/lib/logger/datadogTransport.js +21 -0
- package/lib/logger/datadogTransport.js.map +1 -0
- package/lib/logger/index.d.ts +16 -0
- package/lib/logger/index.d.ts.map +1 -0
- package/lib/logger/index.js +148 -0
- package/lib/logger/index.js.map +1 -0
- package/lib/logger/index.test.d.ts +2 -0
- package/lib/logger/index.test.d.ts.map +1 -0
- package/lib/logger/index.test.js +60 -0
- package/lib/logger/index.test.js.map +1 -0
- package/lib/logger/utils.d.ts +15 -0
- package/lib/logger/utils.d.ts.map +1 -0
- package/lib/logger/utils.js +32 -0
- package/lib/logger/utils.js.map +1 -0
- package/lib/reporters/amplifyReporter.d.ts +83 -77
- package/lib/reporters/amplifyReporter.d.ts.map +1 -1
- package/lib/reporters/amplifyReporter.js +162 -151
- package/lib/reporters/amplifyReporter.js.map +1 -1
- package/lib/reporters/amplifyReporter.test.d.ts +1 -1
- package/lib/reporters/amplifyReporter.test.js +50 -50
- package/lib/reporters/datadogReporter.d.ts +76 -74
- package/lib/reporters/datadogReporter.d.ts.map +1 -1
- package/lib/reporters/datadogReporter.js +122 -185
- package/lib/reporters/datadogReporter.js.map +1 -1
- package/lib/reporters/gtmReporter.d.ts +8 -8
- package/lib/reporters/gtmReporter.d.ts.map +1 -1
- package/lib/reporters/gtmReporter.js +56 -61
- package/lib/reporters/gtmReporter.js.map +1 -1
- package/lib/reporters/index.d.ts +66 -3
- package/lib/reporters/index.d.ts.map +1 -1
- package/lib/reporters/index.js +212 -19
- package/lib/reporters/index.js.map +1 -1
- package/lib/reporters/logReporter.d.ts +35 -0
- package/lib/reporters/logReporter.d.ts.map +1 -0
- package/lib/reporters/logReporter.js +62 -0
- package/lib/reporters/logReporter.js.map +1 -0
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +18 -18
- package/lib/types/logger.d.ts +77 -36
- package/lib/types/logger.d.ts.map +1 -1
- package/lib/types/logger.js +10 -10
- package/lib/types/logger.js.map +1 -1
- package/lib/types/reporter.d.ts +154 -102
- package/lib/types/reporter.d.ts.map +1 -1
- package/lib/types/reporter.js +2 -2
- package/lib/utils.d.ts +9 -8
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +31 -51
- package/lib/utils.js.map +1 -1
- package/lib/utils.test.d.ts +1 -1
- package/lib/utils.test.js +31 -18
- package/lib/utils.test.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +38 -208
- package/src/logger/consoleTransport.ts +101 -0
- package/src/logger/datadogTransport.ts +20 -0
- package/src/logger/index.test.ts +68 -0
- package/src/logger/index.ts +139 -0
- package/src/logger/utils.ts +28 -0
- package/src/reporters/amplifyReporter.ts +37 -17
- package/src/reporters/datadogReporter.ts +48 -116
- package/src/reporters/gtmReporter.ts +2 -7
- package/src/reporters/index.ts +216 -3
- package/src/reporters/logReporter.ts +86 -0
- package/src/types/logger.ts +49 -4
- package/src/types/reporter.ts +66 -6
- package/src/utils.test.ts +20 -6
- package/src/utils.ts +37 -62
package/lib/index.js
CHANGED
|
@@ -1,214 +1,70 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
const
|
|
19
|
-
const reporters_1 = require("./reporters");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.trackEvent = trackEvent;
|
|
73
|
-
/**
|
|
74
|
-
* Tracks an Analytics event, recording the time since the last event, if available.
|
|
75
|
-
*/
|
|
76
|
-
function trackEventSinceLastAction(event) {
|
|
77
|
-
const lastEvent = getLastTrackedEvent();
|
|
78
|
-
if (lastEvent) {
|
|
79
|
-
const duration = new Date().getTime() - lastEvent.occurred.getTime();
|
|
80
|
-
trackEvent({
|
|
81
|
-
...event,
|
|
82
|
-
metadata: {
|
|
83
|
-
...event.metadata,
|
|
84
|
-
lastEventName: lastEvent.message,
|
|
85
|
-
timeSinceLastEvent: duration,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
trackEvent(event);
|
|
91
|
-
}
|
|
92
|
-
sessionStorage.setItem('loggerLastEvent', JSON.stringify({ ...event, occurred: new Date() }));
|
|
93
|
-
}
|
|
94
|
-
exports.trackEventSinceLastAction = trackEventSinceLastAction;
|
|
95
|
-
/**
|
|
96
|
-
* Gets the last tracked event, if available.
|
|
97
|
-
*/
|
|
98
|
-
function getLastTrackedEvent() {
|
|
99
|
-
const eventStr = sessionStorage.getItem('loggerLastEvent');
|
|
100
|
-
if (!eventStr)
|
|
101
|
-
return null;
|
|
102
|
-
const event = JSON.parse(eventStr);
|
|
103
|
-
event.occurred = new Date(event.occurred);
|
|
104
|
-
return event;
|
|
105
|
-
}
|
|
106
|
-
exports.getLastTrackedEvent = getLastTrackedEvent;
|
|
107
|
-
/**
|
|
108
|
-
* Breadcrumbs to create a trail of events that happened prior to an issue.
|
|
109
|
-
* These events are very similar to traditional logs, but can record more rich structured data.
|
|
110
|
-
*/
|
|
111
|
-
function addBreadcrumb(breadcrumb) {
|
|
112
|
-
for (const reporter of getReporters(breadcrumb)) {
|
|
113
|
-
reporter.addBreadcrumb(breadcrumb);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.addBreadcrumb = addBreadcrumb;
|
|
117
|
-
/**
|
|
118
|
-
* Adds global metadata to all events.
|
|
119
|
-
* @param metadata Metadata to add.
|
|
120
|
-
* @param filters Optional filters to specify which reporters to add metadata to.
|
|
121
|
-
*/
|
|
122
|
-
function addMetadata(metadata, filters) {
|
|
123
|
-
for (const reporter of getReporters(filters)) {
|
|
124
|
-
reporter.addMetadata(metadata);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.addMetadata = addMetadata;
|
|
128
|
-
/**
|
|
129
|
-
* Sets the user information in Analytics.
|
|
130
|
-
* @param user User information, or null to clear.
|
|
131
|
-
* @param filters Optional filters to specify which reporters to set the user for.
|
|
132
|
-
*/
|
|
133
|
-
function setUser(user, filters) {
|
|
134
|
-
for (const reporter of getReporters(filters)) {
|
|
135
|
-
reporter.setUser(user);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.setUser = setUser;
|
|
139
|
-
/**
|
|
140
|
-
* Sets the route name in Analytics.
|
|
141
|
-
* Some Analytics services use this differentiate SPA Route vs Page changes.
|
|
142
|
-
* @param routeName Name of the Route.
|
|
143
|
-
* @param filters Optional filters to specify which reporters to set the route name for.
|
|
144
|
-
*/
|
|
145
|
-
function setRouteName(routeName, filters) {
|
|
146
|
-
for (const reporter of getReporters(filters)) {
|
|
147
|
-
reporter.setRouteName(routeName);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.setRouteName = setRouteName;
|
|
151
|
-
/**
|
|
152
|
-
* Sets the page name in Analytics.
|
|
153
|
-
* @param pageName Name of the Page.
|
|
154
|
-
* @param filters Optional filters to specify which reporters to set the page name for.
|
|
155
|
-
*/
|
|
156
|
-
function setPageName(pageName, filters) {
|
|
157
|
-
for (const reporter of getReporters(filters)) {
|
|
158
|
-
reporter.setPageName(pageName);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
exports.setPageName = setPageName;
|
|
162
|
-
/**
|
|
163
|
-
* Reports an Error in Reporters that support error tracking.
|
|
164
|
-
* @param error Error data.
|
|
165
|
-
* @param metadata Metadata to add to the error.
|
|
166
|
-
* @param filters Optional filters to specify which reporters to report the error to.
|
|
167
|
-
*/
|
|
168
|
-
function reportError(error, metadata, filters) {
|
|
169
|
-
var _a;
|
|
170
|
-
for (const reporter of getReporters(filters)) {
|
|
171
|
-
(_a = reporter.reportError) === null || _a === void 0 ? void 0 : _a.call(reporter, error, metadata);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
exports.reportError = reportError;
|
|
175
|
-
/**
|
|
176
|
-
* Starts a session recording in Analytics, e.g. RUM Session Replay
|
|
177
|
-
* @param filters Optional filters to specify which reporters to start a session recording for.
|
|
178
|
-
*/
|
|
179
|
-
function recordSession(filters) {
|
|
180
|
-
var _a;
|
|
181
|
-
for (const reporter of getReporters(filters)) {
|
|
182
|
-
(_a = reporter.recordSession) === null || _a === void 0 ? void 0 : _a.call(reporter);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
exports.recordSession = recordSession;
|
|
186
|
-
/**
|
|
187
|
-
* Stops a session recording in Analytics, e.g. RUM Session Replay
|
|
188
|
-
* @param filters Optional filters to specify which reporters to stop a session recording for.
|
|
189
|
-
*/
|
|
190
|
-
function recordSessionStop(filters) {
|
|
191
|
-
var _a;
|
|
192
|
-
for (const reporter of getReporters(filters)) {
|
|
193
|
-
(_a = reporter.recordSessionStop) === null || _a === void 0 ? void 0 : _a.call(reporter);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
exports.recordSessionStop = recordSessionStop;
|
|
197
|
-
/**
|
|
198
|
-
* Creates a Logger instance.
|
|
199
|
-
* @param name Name of the Logger.
|
|
200
|
-
* @param options Logger configuration options.
|
|
201
|
-
*/
|
|
202
|
-
function createLogger(name, options) {
|
|
203
|
-
if (!initialized) {
|
|
204
|
-
throw new Error('You must call init on BrowserLogger before creating a logger');
|
|
205
|
-
}
|
|
206
|
-
if (ddInitialized) {
|
|
207
|
-
return (0, reporters_1.datadogLogger)(name, options);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
return (0, utils_1.consoleLogger)(name, options);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
exports.createLogger = createLogger;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.init = void 0;
|
|
18
|
+
const logger_1 = require("./logger");
|
|
19
|
+
const reporters_1 = require("./reporters");
|
|
20
|
+
const gtmReporter_1 = require("./reporters/gtmReporter");
|
|
21
|
+
const amplifyReporter_1 = require("./reporters/amplifyReporter");
|
|
22
|
+
const datadogReporter_1 = require("./reporters/datadogReporter");
|
|
23
|
+
const logReporter_1 = require("./reporters/logReporter");
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
25
|
+
__exportStar(require("./reporters"), exports);
|
|
26
|
+
__exportStar(require("./logger"), exports);
|
|
27
|
+
let initialized = false;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes the logger and reporters.
|
|
30
|
+
* @param config Reporter config options.
|
|
31
|
+
*/
|
|
32
|
+
function init(config) {
|
|
33
|
+
var _a, _b, _c, _d, _e, _f;
|
|
34
|
+
// Some reporters don't like being initialized multiple times.
|
|
35
|
+
if (initialized) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
initialized = true;
|
|
39
|
+
// Log Reporter enabled by default.
|
|
40
|
+
const logReporterConfig = (_b = (_a = config.reporters) === null || _a === void 0 ? void 0 : _a.log) !== null && _b !== void 0 ? _b : true;
|
|
41
|
+
if (logReporterConfig !== false) {
|
|
42
|
+
reporters_1.reporters['log'] = (0, logReporter_1.logReporter)(config, typeof logReporterConfig === 'boolean' ? {} : logReporterConfig);
|
|
43
|
+
}
|
|
44
|
+
if ((_c = config.reporters) === null || _c === void 0 ? void 0 : _c.datadog) {
|
|
45
|
+
reporters_1.reporters['datadog'] = (0, datadogReporter_1.datadogReporter)(config, config.reporters.datadog);
|
|
46
|
+
}
|
|
47
|
+
if ((_d = config.reporters) === null || _d === void 0 ? void 0 : _d.amplify) {
|
|
48
|
+
reporters_1.reporters['amplify'] = (0, amplifyReporter_1.amplifyReporter)(config, config.reporters.amplify);
|
|
49
|
+
}
|
|
50
|
+
if ((_e = config.reporters) === null || _e === void 0 ? void 0 : _e.gtm) {
|
|
51
|
+
reporters_1.reporters['gtm'] = (0, gtmReporter_1.gtmReporter)(config, typeof config.reporters.gtm === 'boolean' ? {} : config.reporters.gtm);
|
|
52
|
+
}
|
|
53
|
+
const defaultMetadata = {
|
|
54
|
+
...((_f = config.defaultMetadata) !== null && _f !== void 0 ? _f : {}),
|
|
55
|
+
service: config.service,
|
|
56
|
+
environment: config.environment,
|
|
57
|
+
version: config.version,
|
|
58
|
+
};
|
|
59
|
+
// Sets the global log level, if specified.
|
|
60
|
+
if (config.logLevel) {
|
|
61
|
+
(0, logger_1.setLogLevel)(config.logLevel);
|
|
62
|
+
}
|
|
63
|
+
// Sets the global event level, if specified.
|
|
64
|
+
if (config.eventLevel) {
|
|
65
|
+
(0, reporters_1.setEventLevel)(config.eventLevel);
|
|
66
|
+
}
|
|
67
|
+
(0, reporters_1.addMetadata)(defaultMetadata);
|
|
68
|
+
}
|
|
69
|
+
exports.init = init;
|
|
214
70
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,qCAAuC;AACvC,2CAAoE;AACpE,yDAAsD;AACtD,iEAA8D;AAC9D,iEAA8D;AAC9D,yDAAsD;AAEtD,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AAIzB,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB;;;GAGG;AACH,SAAgB,IAAI,CAAC,MAAoB;;IACvC,8DAA8D;IAC9D,IAAI,WAAW,EAAE;QACf,OAAO;KACR;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,mCAAmC;IACnC,MAAM,iBAAiB,GAAG,MAAA,MAAA,MAAM,CAAC,SAAS,0CAAE,GAAG,mCAAI,IAAI,CAAC;IACxD,IAAI,iBAAiB,KAAK,KAAK,EAAE;QAC/B,qBAAS,CAAC,KAAK,CAAC,GAAG,IAAA,yBAAW,EAAC,MAAM,EAAE,OAAO,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;KACzG;IAED,IAAI,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,EAAE;QAC7B,qBAAS,CAAC,SAAS,CAAC,GAAG,IAAA,iCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;KAC1E;IAED,IAAI,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,EAAE;QAC7B,qBAAS,CAAC,SAAS,CAAC,GAAG,IAAA,iCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;KAC1E;IAED,IAAI,MAAA,MAAM,CAAC,SAAS,0CAAE,GAAG,EAAE;QACzB,qBAAS,CAAC,KAAK,CAAC,GAAG,IAAA,yBAAW,EAAC,MAAM,EAAE,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC/G;IAED,MAAM,eAAe,GAAG;QACtB,GAAG,CAAC,MAAA,MAAM,CAAC,eAAe,mCAAI,EAAE,CAAC;QACjC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;IAEF,2CAA2C;IAC3C,IAAI,MAAM,CAAC,QAAQ,EAAE;QACnB,IAAA,oBAAW,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;KAC9B;IAED,6CAA6C;IAC7C,IAAI,MAAM,CAAC,UAAU,EAAE;QACrB,IAAA,yBAAa,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KAClC;IAED,IAAA,uBAAW,EAAC,eAAe,CAAC,CAAC;AAC/B,CAAC;AA3CD,oBA2CC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ILogTransport, LogLevel, LogTransportConfigBase } from '../types';
|
|
2
|
+
declare const colors: {
|
|
3
|
+
bold: number[];
|
|
4
|
+
italic: number[];
|
|
5
|
+
underline: number[];
|
|
6
|
+
inverse: number[];
|
|
7
|
+
white: number[];
|
|
8
|
+
grey: number[];
|
|
9
|
+
black: number[];
|
|
10
|
+
blue: number[];
|
|
11
|
+
cyan: number[];
|
|
12
|
+
green: number[];
|
|
13
|
+
magenta: number[];
|
|
14
|
+
red: number[];
|
|
15
|
+
yellow: number[];
|
|
16
|
+
};
|
|
17
|
+
export declare type ColorizeColor = keyof typeof colors;
|
|
18
|
+
/**
|
|
19
|
+
* Colorize a string with a specified color.
|
|
20
|
+
* @param str String to colorize
|
|
21
|
+
* @param color Color to colorize the string with
|
|
22
|
+
* @returns Colorized string
|
|
23
|
+
*/
|
|
24
|
+
export declare function colorize(str: string, color: ColorizeColor): string;
|
|
25
|
+
export interface ConsoleLogTransportConfig extends LogTransportConfigBase {
|
|
26
|
+
/**
|
|
27
|
+
* Add colors to log messages.
|
|
28
|
+
*/
|
|
29
|
+
colorize?: false | typeof colorize;
|
|
30
|
+
/**
|
|
31
|
+
* Gets the color for the log level.
|
|
32
|
+
*/
|
|
33
|
+
getLogLevelColor?: (level: LogLevel) => ColorizeColor;
|
|
34
|
+
}
|
|
35
|
+
export declare function consoleTransport(config?: ConsoleLogTransportConfig): ILogTransport & ConsoleLogTransportConfig;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=consoleTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleTransport.d.ts","sourceRoot":"","sources":["../../src/logger/consoleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAG3E,QAAA,MAAM,MAAM;;;;;;;;;;;;;;CAcX,CAAC;AACF,oBAAY,aAAa,GAAG,MAAM,OAAO,MAAM,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,UAGzD;AAWD,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB;IACvE;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,QAAQ,CAAC;IAEnC;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,aAAa,CAAC;CACvD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,yBAA8B,6CAgDtE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.consoleTransport = exports.colorize = void 0;
|
|
4
|
+
// from browser-util-inspect
|
|
5
|
+
const colors = {
|
|
6
|
+
bold: [1, 22],
|
|
7
|
+
italic: [3, 23],
|
|
8
|
+
underline: [4, 24],
|
|
9
|
+
inverse: [7, 27],
|
|
10
|
+
white: [37, 39],
|
|
11
|
+
grey: [90, 39],
|
|
12
|
+
black: [30, 39],
|
|
13
|
+
blue: [34, 39],
|
|
14
|
+
cyan: [36, 39],
|
|
15
|
+
green: [32, 39],
|
|
16
|
+
magenta: [35, 39],
|
|
17
|
+
red: [31, 39],
|
|
18
|
+
yellow: [33, 39],
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Colorize a string with a specified color.
|
|
22
|
+
* @param str String to colorize
|
|
23
|
+
* @param color Color to colorize the string with
|
|
24
|
+
* @returns Colorized string
|
|
25
|
+
*/
|
|
26
|
+
function colorize(str, color) {
|
|
27
|
+
const colorData = colors[color];
|
|
28
|
+
return '\u001b[' + colorData[0] + 'm' + str + '\u001b[' + colorData[1] + 'm';
|
|
29
|
+
}
|
|
30
|
+
exports.colorize = colorize;
|
|
31
|
+
/**
|
|
32
|
+
* Gets a stack trace from metadata or accompanying error.
|
|
33
|
+
*/
|
|
34
|
+
function getStackTrace(data) {
|
|
35
|
+
var _a;
|
|
36
|
+
const stack = ((_a = data === null || data === void 0 ? void 0 : data.err) === null || _a === void 0 ? void 0 : _a.stack) || data.stack || data['error.stack'];
|
|
37
|
+
delete data.stack;
|
|
38
|
+
return stack !== null && stack !== void 0 ? stack : '';
|
|
39
|
+
}
|
|
40
|
+
function consoleTransport(config = {}) {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
// Default ignore patterns
|
|
43
|
+
(_a = config.ignoreMetadataPatterns) !== null && _a !== void 0 ? _a : (config.ignoreMetadataPatterns = ['application', 'service', 'environment', 'version']);
|
|
44
|
+
// Get the colorizer function, or a no-op if not enabled.
|
|
45
|
+
const colorizer = config.colorize !== false ? (_b = config.colorize) !== null && _b !== void 0 ? _b : colorize : (str) => str;
|
|
46
|
+
// Get the log level color function, or use the default colors.
|
|
47
|
+
const getLogLevelColor = (_c = config.getLogLevelColor) !== null && _c !== void 0 ? _c : ((level) => {
|
|
48
|
+
return {
|
|
49
|
+
error: 'red',
|
|
50
|
+
warn: 'yellow',
|
|
51
|
+
info: 'cyan',
|
|
52
|
+
debug: 'green',
|
|
53
|
+
}[level];
|
|
54
|
+
});
|
|
55
|
+
const transport = {
|
|
56
|
+
...config,
|
|
57
|
+
log: ({ level, message, timestamp, splat, ...metadata }) => {
|
|
58
|
+
let splatData = splat !== null && splat !== void 0 ? splat : [];
|
|
59
|
+
const stackTrace = getStackTrace(metadata);
|
|
60
|
+
const strippedInfo = { ...metadata };
|
|
61
|
+
delete strippedInfo['level'];
|
|
62
|
+
delete strippedInfo['message'];
|
|
63
|
+
delete strippedInfo['splat'];
|
|
64
|
+
delete strippedInfo['timestamp'];
|
|
65
|
+
delete strippedInfo['stack'];
|
|
66
|
+
if (Object.keys(strippedInfo).length > 0) {
|
|
67
|
+
splatData = [strippedInfo, ...splatData];
|
|
68
|
+
}
|
|
69
|
+
if (message) {
|
|
70
|
+
splatData = [message, ...splatData];
|
|
71
|
+
}
|
|
72
|
+
if (stackTrace) {
|
|
73
|
+
splatData = [...splatData, stackTrace];
|
|
74
|
+
}
|
|
75
|
+
console.log(`${colorizer(timestamp, 'magenta')} ${colorizer(level, getLogLevelColor(level))}: `, ...splatData);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
return transport;
|
|
79
|
+
}
|
|
80
|
+
exports.consoleTransport = consoleTransport;
|
|
81
|
+
//# sourceMappingURL=consoleTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleTransport.js","sourceRoot":"","sources":["../../src/logger/consoleTransport.ts"],"names":[],"mappings":";;;AAEA,4BAA4B;AAC5B,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACb,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACf,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC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,EAAE,GAAG,SAAS,CAAC,CAAC;aACrC;YAED,IAAI,UAAU,EAAE;gBACd,SAAS,GAAG,CAAC,GAAG,SAAS,EAAE,UAAU,CAAC,CAAC;aACxC;YAED,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,SAAS,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,GAAG,SAAS,CAAC,CAAC;QACjH,CAAC;KACF,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC;AAhDD,4CAgDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ILogTransport, LogTransportConfigBase } from '../types';
|
|
2
|
+
export declare type DatadogLogTransportConfig = LogTransportConfigBase;
|
|
3
|
+
/**
|
|
4
|
+
* A transport that sends logs to Datadog.
|
|
5
|
+
* Note: This requires the datadog reporter to be initialized for it to work.
|
|
6
|
+
*/
|
|
7
|
+
export declare function datadogTransport(config?: DatadogLogTransportConfig): ILogTransport;
|
|
8
|
+
//# sourceMappingURL=datadogTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datadogTransport.d.ts","sourceRoot":"","sources":["../../src/logger/datadogTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAIjE,oBAAY,yBAAyB,GAAG,sBAAsB,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,yBAA8B,iBAStE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.datadogTransport = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const browser_logs_1 = require("@datadog/browser-logs");
|
|
6
|
+
/**
|
|
7
|
+
* A transport that sends logs to Datadog.
|
|
8
|
+
* Note: This requires the datadog reporter to be initialized for it to work.
|
|
9
|
+
*/
|
|
10
|
+
function datadogTransport(config = {}) {
|
|
11
|
+
const transport = {
|
|
12
|
+
...config,
|
|
13
|
+
log: ({ level, message, ...metadata }) => {
|
|
14
|
+
// Datadog expects a string message.
|
|
15
|
+
browser_logs_1.datadogLogs.logger[level]((0, utils_1.getLogMessage)(message), metadata);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
return transport;
|
|
19
|
+
}
|
|
20
|
+
exports.datadogTransport = datadogTransport;
|
|
21
|
+
//# sourceMappingURL=datadogTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datadogTransport.js","sourceRoot":"","sources":["../../src/logger/datadogTransport.ts"],"names":[],"mappings":";;;AACA,mCAAwC;AACxC,wDAAoD;AAIpD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,SAAoC,EAAE;IACrE,MAAM,SAAS,GAAkB;QAC/B,GAAG,MAAM;QACT,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,EAAE,EAAE;YACvC,oCAAoC;YACpC,0BAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC9D,CAAC;KACF,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC;AATD,4CASC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ILogger, ILogTransport, LoggerOptions, LogLevel, Metadata } from '../types';
|
|
2
|
+
export * from './consoleTransport';
|
|
3
|
+
export * from './datadogTransport';
|
|
4
|
+
export declare const globalMetadata: Metadata;
|
|
5
|
+
export declare const logTransports: ILogTransport[];
|
|
6
|
+
export declare let globalLogLevel: LogLevel | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Sets the global log level.
|
|
9
|
+
*/
|
|
10
|
+
export declare function setLogLevel(level: LogLevel | null): void;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Logger Instance.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLogger(options?: LoggerOptions): ILogger;
|
|
15
|
+
export declare const logger: ILogger;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAA2B,MAAM,UAAU,CAAC;AAK9G,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AAEnC,eAAO,MAAM,cAAc,EAAE,QAAa,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,aAAa,EAAyB,CAAC;AAEnE,eAAO,IAAI,cAAc,EAAE,QAAQ,GAAG,SAAS,CAAC;AAChD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAExD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAgHjE;AAED,eAAO,MAAM,MAAM,SAAiB,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.logger = exports.createLogger = exports.setLogLevel = exports.globalLogLevel = exports.logTransports = exports.globalMetadata = void 0;
|
|
18
|
+
/* eslint-disable prefer-rest-params */
|
|
19
|
+
const types_1 = require("../types");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
const consoleTransport_1 = require("./consoleTransport");
|
|
22
|
+
const utils_2 = require("./utils");
|
|
23
|
+
__exportStar(require("./consoleTransport"), exports);
|
|
24
|
+
__exportStar(require("./datadogTransport"), exports);
|
|
25
|
+
exports.globalMetadata = {};
|
|
26
|
+
exports.logTransports = [(0, consoleTransport_1.consoleTransport)()];
|
|
27
|
+
/**
|
|
28
|
+
* Sets the global log level.
|
|
29
|
+
*/
|
|
30
|
+
function setLogLevel(level) {
|
|
31
|
+
exports.globalLogLevel = level !== null && level !== void 0 ? level : undefined;
|
|
32
|
+
}
|
|
33
|
+
exports.setLogLevel = setLogLevel;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Logger Instance.
|
|
36
|
+
*/
|
|
37
|
+
function createLogger(options = {}) {
|
|
38
|
+
var _a;
|
|
39
|
+
const rootMetadata = (_a = options.metadata) !== null && _a !== void 0 ? _a : {};
|
|
40
|
+
const logger = {
|
|
41
|
+
// impl loosely based on Winston Logger's dynamic log function
|
|
42
|
+
// https://github.com/winstonjs/winston/blob/master/lib/winston/logger.js
|
|
43
|
+
log() {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
let logInfo;
|
|
46
|
+
// Optimize for the hotpath of logging JSON literals
|
|
47
|
+
if (arguments.length === 1) {
|
|
48
|
+
logInfo = {
|
|
49
|
+
level: types_1.LogLevel.Info,
|
|
50
|
+
...arguments[0],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Slightly less hotpath, but worth optimizing for.
|
|
54
|
+
else if (arguments.length === 2) {
|
|
55
|
+
const [level, message] = Array.from(arguments);
|
|
56
|
+
if (message && typeof message === 'object') {
|
|
57
|
+
logInfo = {
|
|
58
|
+
...message,
|
|
59
|
+
level: (_a = message.level) !== null && _a !== void 0 ? _a : level,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
logInfo = {
|
|
64
|
+
level,
|
|
65
|
+
message,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const [level, message, ...splat] = Array.from(arguments);
|
|
71
|
+
const [meta] = splat;
|
|
72
|
+
if (typeof meta === 'object' && meta !== null) {
|
|
73
|
+
logInfo = {
|
|
74
|
+
...meta,
|
|
75
|
+
level,
|
|
76
|
+
splat: splat.slice(1),
|
|
77
|
+
message,
|
|
78
|
+
};
|
|
79
|
+
if (meta.message) {
|
|
80
|
+
logInfo.message = `${(0, utils_2.getLogMessage)(logInfo.message)} ${(0, utils_2.getLogMessage)(meta.message)}`;
|
|
81
|
+
}
|
|
82
|
+
if (meta.stack) {
|
|
83
|
+
logInfo.stack = meta.stack;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logInfo = {
|
|
88
|
+
level,
|
|
89
|
+
splat,
|
|
90
|
+
message,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Check if we should log this message
|
|
95
|
+
const minLevel = exports.globalLogLevel !== null && exports.globalLogLevel !== void 0 ? exports.globalLogLevel : options.logLevel;
|
|
96
|
+
if (minLevel && !(0, utils_2.isAboveLevel)(logInfo.level, minLevel)) {
|
|
97
|
+
return logger;
|
|
98
|
+
}
|
|
99
|
+
// Add timestamp and root metadata.
|
|
100
|
+
// Ensure there is a message property.
|
|
101
|
+
logInfo = {
|
|
102
|
+
...exports.globalMetadata,
|
|
103
|
+
...rootMetadata,
|
|
104
|
+
timestamp: new Date().toISOString(),
|
|
105
|
+
...logInfo,
|
|
106
|
+
message: (_b = logInfo.message) !== null && _b !== void 0 ? _b : '',
|
|
107
|
+
};
|
|
108
|
+
for (const transport of exports.logTransports) {
|
|
109
|
+
if (transport.logLevel) {
|
|
110
|
+
if (!(0, utils_2.isAboveLevel)(logInfo.level, transport.logLevel)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
transport.log({
|
|
115
|
+
...(0, utils_1.filterReporterMetadata)(logInfo, transport),
|
|
116
|
+
// These would break the transport if excluded.
|
|
117
|
+
level: logInfo.level,
|
|
118
|
+
message: logInfo.message,
|
|
119
|
+
splat: logInfo.splat,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return logger;
|
|
123
|
+
},
|
|
124
|
+
child(metadata) {
|
|
125
|
+
return createLogger({ ...rootMetadata, metadata });
|
|
126
|
+
},
|
|
127
|
+
startTimer() {
|
|
128
|
+
const start = new Date();
|
|
129
|
+
return {
|
|
130
|
+
logger: this,
|
|
131
|
+
done: ({ message, level, metadata } = {}) => {
|
|
132
|
+
const duration = new Date().getTime() - start.getTime();
|
|
133
|
+
logger.log(level !== null && level !== void 0 ? level : types_1.LogLevel.Info, message !== null && message !== void 0 ? message : 'Timer Completed', { duration, ...(metadata !== null && metadata !== void 0 ? metadata : {}) });
|
|
134
|
+
return true;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
// Forward the log levels into the log function, essentially shortcuts.
|
|
139
|
+
debug: (...args) => logger.log(types_1.LogLevel.Debug, ...args),
|
|
140
|
+
info: (...args) => logger.log(types_1.LogLevel.Info, ...args),
|
|
141
|
+
warn: (...args) => logger.log(types_1.LogLevel.Warn, ...args),
|
|
142
|
+
error: (...args) => logger.log(types_1.LogLevel.Error, ...args),
|
|
143
|
+
};
|
|
144
|
+
return logger;
|
|
145
|
+
}
|
|
146
|
+
exports.createLogger = createLogger;
|
|
147
|
+
exports.logger = createLogger();
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAuC;AACvC,oCAA8G;AAC9G,oCAAkD;AAClD,yDAAsD;AACtD,mCAAsD;AAEtD,qDAAmC;AACnC,qDAAmC;AAEtB,QAAA,cAAc,GAAa,EAAE,CAAC;AAE9B,QAAA,aAAa,GAAoB,CAAC,IAAA,mCAAgB,GAAE,CAAC,CAAC;AAGnE;;GAEG;AACH,SAAgB,WAAW,CAAC,KAAsB;IAChD,sBAAc,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC;AACtC,CAAC;AAFD,kCAEC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,UAAyB,EAAE;;IACtD,MAAM,YAAY,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,EAAE,CAAC;IAE5C,MAAM,MAAM,GAAY;QACtB,8DAA8D;QAC9D,yEAAyE;QACzE,GAAG;;YACD,IAAI,OAAsB,CAAC;YAE3B,oDAAoD;YACpD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC1B,OAAO,GAAG;oBACR,KAAK,EAAE,gBAAQ,CAAC,IAAI;oBACpB,GAAG,SAAS,CAAC,CAAC,CAAC;iBAChB,CAAC;aACH;YACD,mDAAmD;iBAC9C,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC/B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC/C,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;oBAC1C,OAAO,GAAG;wBACR,GAAG,OAAO;wBACV,KAAK,EAAE,MAAA,OAAO,CAAC,KAAK,mCAAI,KAAK;qBAC9B,CAAC;iBACH;qBAAM;oBACL,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