@matter/general 0.13.0-alpha.0-20250322-f085fa576 → 0.13.0-alpha.0-20250323-770919c6a
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/dist/cjs/log/Console.d.ts +21 -0
- package/dist/cjs/log/Console.d.ts.map +1 -0
- package/dist/cjs/log/Console.js +58 -0
- package/dist/cjs/log/Console.js.map +6 -0
- package/dist/cjs/log/Diagnostic.d.ts +6 -0
- package/dist/cjs/log/Diagnostic.d.ts.map +1 -1
- package/dist/cjs/log/Diagnostic.js +16 -0
- package/dist/cjs/log/Diagnostic.js.map +1 -1
- package/dist/cjs/log/LogDestination.d.ts +67 -0
- package/dist/cjs/log/LogDestination.d.ts.map +1 -0
- package/dist/cjs/log/LogDestination.js +65 -0
- package/dist/cjs/log/LogDestination.js.map +6 -0
- package/dist/cjs/log/LogFormat.d.ts +18 -12
- package/dist/cjs/log/LogFormat.d.ts.map +1 -1
- package/dist/cjs/log/LogFormat.js +17 -24
- package/dist/cjs/log/LogFormat.js.map +1 -1
- package/dist/cjs/log/LogLevel.d.ts +19 -9
- package/dist/cjs/log/LogLevel.d.ts.map +1 -1
- package/dist/cjs/log/LogLevel.js +40 -25
- package/dist/cjs/log/LogLevel.js.map +1 -1
- package/dist/cjs/log/Logger.d.ts +157 -106
- package/dist/cjs/log/Logger.d.ts.map +1 -1
- package/dist/cjs/log/Logger.js +298 -256
- package/dist/cjs/log/Logger.js.map +2 -2
- package/dist/cjs/log/index.d.ts +1 -0
- package/dist/cjs/log/index.d.ts.map +1 -1
- package/dist/cjs/log/index.js +1 -0
- package/dist/cjs/log/index.js.map +1 -1
- package/dist/cjs/transaction/Transaction.d.ts +19 -19
- package/dist/esm/log/Console.d.ts +21 -0
- package/dist/esm/log/Console.d.ts.map +1 -0
- package/dist/esm/log/Console.js +38 -0
- package/dist/esm/log/Console.js.map +6 -0
- package/dist/esm/log/Diagnostic.d.ts +6 -0
- package/dist/esm/log/Diagnostic.d.ts.map +1 -1
- package/dist/esm/log/Diagnostic.js +16 -0
- package/dist/esm/log/Diagnostic.js.map +1 -1
- package/dist/esm/log/LogDestination.d.ts +67 -0
- package/dist/esm/log/LogDestination.d.ts.map +1 -0
- package/dist/esm/log/LogDestination.js +45 -0
- package/dist/esm/log/LogDestination.js.map +6 -0
- package/dist/esm/log/LogFormat.d.ts +18 -12
- package/dist/esm/log/LogFormat.d.ts.map +1 -1
- package/dist/esm/log/LogFormat.js +17 -24
- package/dist/esm/log/LogFormat.js.map +1 -1
- package/dist/esm/log/LogLevel.d.ts +19 -9
- package/dist/esm/log/LogLevel.d.ts.map +1 -1
- package/dist/esm/log/LogLevel.js +40 -25
- package/dist/esm/log/LogLevel.js.map +1 -1
- package/dist/esm/log/Logger.d.ts +157 -106
- package/dist/esm/log/Logger.d.ts.map +1 -1
- package/dist/esm/log/Logger.js +298 -256
- package/dist/esm/log/Logger.js.map +2 -2
- package/dist/esm/log/index.d.ts +1 -0
- package/dist/esm/log/index.d.ts.map +1 -1
- package/dist/esm/log/index.js +1 -0
- package/dist/esm/log/index.js.map +1 -1
- package/dist/esm/transaction/Transaction.d.ts +19 -19
- package/package.json +2 -2
- package/src/log/Console.ts +52 -0
- package/src/log/Diagnostic.ts +21 -0
- package/src/log/LogDestination.ts +113 -0
- package/src/log/LogFormat.ts +39 -36
- package/src/log/LogLevel.ts +55 -25
- package/src/log/Logger.ts +379 -314
- package/src/log/index.ts +1 -0
package/dist/cjs/log/Logger.js
CHANGED
|
@@ -18,8 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var Logger_exports = {};
|
|
20
20
|
__export(Logger_exports, {
|
|
21
|
-
Logger: () => Logger
|
|
22
|
-
consoleLogger: () => consoleLogger
|
|
21
|
+
Logger: () => Logger
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(Logger_exports);
|
|
25
24
|
var import_Boot = require("#util/Boot.js");
|
|
@@ -28,6 +27,7 @@ var import_MatterError = require("../MatterError.js");
|
|
|
28
27
|
var import_Time = require("../time/Time.js");
|
|
29
28
|
var import_Bytes = require("../util/Bytes.js");
|
|
30
29
|
var import_Diagnostic = require("./Diagnostic.js");
|
|
30
|
+
var import_LogDestination = require("./LogDestination.js");
|
|
31
31
|
var import_LogFormat = require("./LogFormat.js");
|
|
32
32
|
var import_LogLevel = require("./LogLevel.js");
|
|
33
33
|
/**
|
|
@@ -35,121 +35,275 @@ var import_LogLevel = require("./LogLevel.js");
|
|
|
35
35
|
* Copyright 2022-2025 Matter.js Authors
|
|
36
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
37
|
*/
|
|
38
|
-
function consoleLogger(level, formattedLog, _facility) {
|
|
39
|
-
const console2 = consoleLogger.console;
|
|
40
|
-
switch (level) {
|
|
41
|
-
case import_LogLevel.LogLevel.DEBUG:
|
|
42
|
-
console2.debug(formattedLog);
|
|
43
|
-
break;
|
|
44
|
-
case import_LogLevel.LogLevel.INFO:
|
|
45
|
-
console2.info(formattedLog);
|
|
46
|
-
break;
|
|
47
|
-
case import_LogLevel.LogLevel.NOTICE:
|
|
48
|
-
console2.info(formattedLog);
|
|
49
|
-
break;
|
|
50
|
-
case import_LogLevel.LogLevel.WARN:
|
|
51
|
-
console2.warn(formattedLog);
|
|
52
|
-
break;
|
|
53
|
-
case import_LogLevel.LogLevel.ERROR:
|
|
54
|
-
console2.error(formattedLog);
|
|
55
|
-
break;
|
|
56
|
-
case import_LogLevel.LogLevel.FATAL:
|
|
57
|
-
console2.error(formattedLog);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const globalConsole = console;
|
|
62
|
-
((consoleLogger2) => {
|
|
63
|
-
consoleLogger2.console = globalConsole;
|
|
64
|
-
})(consoleLogger || (consoleLogger = {}));
|
|
65
|
-
function logFormatterFor(formatName) {
|
|
66
|
-
const format = (0, import_LogFormat.LogFormat)(formatName);
|
|
67
|
-
return (now, level, facility, prefix, ...values) => format(import_Diagnostic.Diagnostic.message({ now, level, facility, prefix, values }));
|
|
68
|
-
}
|
|
69
38
|
class Logger {
|
|
70
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Log destinations.
|
|
41
|
+
*
|
|
42
|
+
* By default there is a single destination named "default". You can create new destinations using
|
|
43
|
+
* {@link LogDestination}. Add or remove destinations by modifying this object.
|
|
44
|
+
*
|
|
45
|
+
* Throws an error if you access a destination that doesn't exist.
|
|
46
|
+
*/
|
|
47
|
+
static destinations = (0, import_LogDestination.LogDestinations)();
|
|
48
|
+
/**
|
|
49
|
+
* The number of indents to print with messages.
|
|
50
|
+
*/
|
|
71
51
|
static nestingLevel;
|
|
72
52
|
#name;
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Create a new logger for a facility.
|
|
55
|
+
*
|
|
56
|
+
* @param name the name of the facility
|
|
57
|
+
* @returns a new facility
|
|
58
|
+
*/
|
|
59
|
+
static get(name) {
|
|
60
|
+
return new Logger(name);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the default log level.
|
|
64
|
+
*/
|
|
65
|
+
static get level() {
|
|
66
|
+
return import_LogDestination.LogDestination.defaults.level;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set log level as name or number for all destinations.
|
|
70
|
+
*/
|
|
71
|
+
static set level(level) {
|
|
72
|
+
level = (0, import_LogLevel.LogLevel)(level);
|
|
73
|
+
import_LogDestination.LogDestination.defaults.level = level;
|
|
74
|
+
for (const name in this.destinations) {
|
|
75
|
+
this.destinations[name].level = level;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the default facility levels.
|
|
80
|
+
*/
|
|
81
|
+
static get facilityLevels() {
|
|
82
|
+
return import_LogDestination.LogDestination.defaults.facilityLevels;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Set log level as name or number for facilities in all destinations.
|
|
86
|
+
*
|
|
87
|
+
* Existing levels that are not named in {@link levels} will remain unchanged.
|
|
88
|
+
*/
|
|
89
|
+
static set facilityLevels(levels) {
|
|
90
|
+
for (const name in levels) {
|
|
91
|
+
levels[name] = (0, import_LogLevel.LogLevel)(levels[name]);
|
|
92
|
+
}
|
|
93
|
+
Object.assign(import_LogDestination.LogDestination.defaults.facilityLevels, levels);
|
|
94
|
+
for (const name in this.destinations) {
|
|
95
|
+
Object.assign(this.destinations[name].facilityLevels, levels);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the default format name.
|
|
100
|
+
*/
|
|
101
|
+
static get format() {
|
|
102
|
+
return import_LogDestination.LogDestination.defaults.format.name;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Set the format for all destinations.
|
|
106
|
+
*/
|
|
107
|
+
static set format(format) {
|
|
108
|
+
format = (0, import_LogFormat.LogFormat)(format);
|
|
109
|
+
import_LogDestination.LogDestination.defaults.format = format;
|
|
110
|
+
for (const name in this.destinations) {
|
|
111
|
+
this.destinations[name].format = format;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Mask a string with a given character. If unmaskedLength is provided then these number of characters will be
|
|
116
|
+
* shown unmasked.
|
|
117
|
+
*
|
|
118
|
+
* @param str String to mask
|
|
119
|
+
* @param maskChar character to mask with
|
|
120
|
+
* @param unmaskedLength number of characters to show unmasked in the beginning
|
|
121
|
+
*/
|
|
122
|
+
static maskString(str, maskChar = "*", unmaskedLength) {
|
|
123
|
+
return str.substring(0, unmaskedLength ?? 0) + str.substring(unmaskedLength ?? 0).replace(/./g, maskChar);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Perform operations in a nested logging context. Messages will be
|
|
127
|
+
* indented while the context executes.
|
|
128
|
+
*/
|
|
129
|
+
static nest(context) {
|
|
130
|
+
this.nestingLevel++;
|
|
131
|
+
try {
|
|
132
|
+
return context();
|
|
133
|
+
} finally {
|
|
134
|
+
this.nestingLevel--;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Async version of nest().
|
|
139
|
+
*/
|
|
140
|
+
static async nestAsync(context) {
|
|
141
|
+
this.nestingLevel++;
|
|
142
|
+
try {
|
|
143
|
+
return await context();
|
|
144
|
+
} finally {
|
|
145
|
+
this.nestingLevel--;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Unhandled error reporter.
|
|
150
|
+
*
|
|
151
|
+
* Some environments do not report full error details such as {@link Error#cause} and {@link AggregateError#errors}.
|
|
152
|
+
*
|
|
153
|
+
* To ensure these details are always recorded somewhere, unhandled errors may be reported here.
|
|
154
|
+
*
|
|
155
|
+
* To disable this behavior replace this function.
|
|
156
|
+
*/
|
|
157
|
+
static reportUnhandledError(error) {
|
|
158
|
+
try {
|
|
159
|
+
Logger.get("Logger").fatal("Unhandled error detected:", error);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
constructor(name) {
|
|
164
|
+
this.#name = name;
|
|
165
|
+
}
|
|
166
|
+
debug(...values) {
|
|
167
|
+
this.#log(import_LogLevel.LogLevel.DEBUG, values);
|
|
168
|
+
}
|
|
169
|
+
info(...values) {
|
|
170
|
+
this.#log(import_LogLevel.LogLevel.INFO, values);
|
|
171
|
+
}
|
|
172
|
+
notice(...values) {
|
|
173
|
+
this.#log(import_LogLevel.LogLevel.NOTICE, values);
|
|
174
|
+
}
|
|
175
|
+
warn(...values) {
|
|
176
|
+
this.#log(import_LogLevel.LogLevel.WARN, values);
|
|
177
|
+
}
|
|
178
|
+
error(...values) {
|
|
179
|
+
this.#log(import_LogLevel.LogLevel.ERROR, values);
|
|
180
|
+
}
|
|
181
|
+
fatal(...values) {
|
|
182
|
+
this.#log(import_LogLevel.LogLevel.FATAL, values);
|
|
183
|
+
}
|
|
184
|
+
log(level, ...values) {
|
|
185
|
+
this.#log(level, values);
|
|
186
|
+
}
|
|
187
|
+
#log(level, values) {
|
|
188
|
+
for (const name in Logger.destinations) {
|
|
189
|
+
const dest = Logger.destinations[name];
|
|
190
|
+
if (level < (dest.facilityLevels?.[this.#name] ?? dest.level)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!dest.context) {
|
|
194
|
+
dest.context = import_Diagnostic.Diagnostic.Context();
|
|
195
|
+
}
|
|
196
|
+
dest.context.run(
|
|
197
|
+
() => dest.add(
|
|
198
|
+
import_Diagnostic.Diagnostic.message({
|
|
199
|
+
now: import_Time.Time.now(),
|
|
200
|
+
facility: this.#name,
|
|
201
|
+
level,
|
|
202
|
+
prefix: nestingPrefix(),
|
|
203
|
+
values
|
|
204
|
+
})
|
|
205
|
+
)
|
|
206
|
+
);
|
|
77
207
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
208
|
+
}
|
|
209
|
+
//
|
|
210
|
+
// DEPRECATED API SURFACE FOLLOWS
|
|
211
|
+
//
|
|
212
|
+
/**
|
|
213
|
+
* Stringify a value (BigInt aware) as JSON.
|
|
214
|
+
*
|
|
215
|
+
* @param data the value to stringify
|
|
216
|
+
* @returns the stringified value
|
|
217
|
+
*
|
|
218
|
+
* @deprecated use {@link Diagnostic.json}
|
|
219
|
+
*/
|
|
220
|
+
static toJSON(data) {
|
|
221
|
+
return JSON.stringify(data, (_, value) => {
|
|
222
|
+
if (typeof value === "bigint") {
|
|
223
|
+
return value.toString();
|
|
224
|
+
}
|
|
225
|
+
if (value instanceof Uint8Array) {
|
|
226
|
+
return import_Bytes.Bytes.toHex(value);
|
|
227
|
+
}
|
|
228
|
+
if (value === void 0) {
|
|
229
|
+
return "undefined";
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
84
232
|
});
|
|
85
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Add additional logger to the list of loggers including the default configuration.
|
|
236
|
+
*
|
|
237
|
+
* @deprecated use {@link destinations}
|
|
238
|
+
*/
|
|
239
|
+
static addLogger(identifier, logger, options) {
|
|
240
|
+
if (identifier in this.destinations) {
|
|
241
|
+
throw new import_MatterError.ImplementationError(`Logger "${identifier}" already exists`);
|
|
242
|
+
}
|
|
243
|
+
const dest = (0, import_LogDestination.LogDestination)({ name: identifier });
|
|
244
|
+
const legacy = adaptDestinationToLegacy(dest);
|
|
245
|
+
legacy.log = logger;
|
|
246
|
+
if (options?.defaultLogLevel !== void 0) {
|
|
247
|
+
legacy.defaultLogLevel = options.defaultLogLevel;
|
|
248
|
+
}
|
|
249
|
+
if (options?.logLevels !== void 0) {
|
|
250
|
+
legacy.logLevels = options.logLevels;
|
|
251
|
+
}
|
|
252
|
+
if (options?.logFormat !== void 0) {
|
|
253
|
+
legacy.logFormatter = logFormatterFor(options.logFormat);
|
|
254
|
+
}
|
|
255
|
+
this.destinations[identifier] = dest;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @deprecated use {@link destinations}
|
|
259
|
+
*/
|
|
86
260
|
static removeLogger(identifier) {
|
|
87
|
-
|
|
88
|
-
if (index === -1) {
|
|
261
|
+
if (!(identifier in this.destinations)) {
|
|
89
262
|
throw new import_MatterError.NotImplementedError(`Logger "${identifier}" does not exist`);
|
|
90
263
|
}
|
|
91
|
-
|
|
264
|
+
delete this.destinations[identifier];
|
|
92
265
|
}
|
|
93
266
|
/**
|
|
94
267
|
* Check if a logger with the matching identifier exists.
|
|
95
268
|
* @param identifier The identifier of the logger
|
|
269
|
+
*
|
|
270
|
+
* @deprecated use {@link destinations}
|
|
96
271
|
*/
|
|
97
272
|
static hasLoggerForIdentifier(identifier) {
|
|
98
|
-
return
|
|
273
|
+
return identifier in this.destinations;
|
|
99
274
|
}
|
|
100
275
|
/**
|
|
101
276
|
* Get the logger with the matching identifier.
|
|
102
277
|
* @param identifier The identifier of the logger
|
|
278
|
+
*
|
|
279
|
+
* @deprecated use {@link destinations}
|
|
103
280
|
*/
|
|
104
281
|
static getLoggerForIdentifier(identifier) {
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
282
|
+
const dest = this.destinations[identifier];
|
|
283
|
+
if (dest === void 0) {
|
|
107
284
|
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
108
285
|
}
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Set log level using configuration-style level name for the default logger.
|
|
113
|
-
*/
|
|
114
|
-
static set level(level) {
|
|
115
|
-
if (level === void 0) {
|
|
116
|
-
level = import_LogLevel.LogLevel.DEBUG;
|
|
117
|
-
}
|
|
118
|
-
let levelNum;
|
|
119
|
-
if (typeof level === "string") {
|
|
120
|
-
if (level.match(/^\d+$/)) {
|
|
121
|
-
levelNum = Number.parseInt(level);
|
|
122
|
-
} else {
|
|
123
|
-
levelNum = import_LogLevel.LogLevel[level.toUpperCase()];
|
|
124
|
-
if (levelNum === void 0) {
|
|
125
|
-
throw new import_MatterError.ImplementationError(`Unsupported log level "${level}"`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
levelNum = level;
|
|
130
|
-
}
|
|
131
|
-
if (import_LogLevel.LogLevel[levelNum] === void 0) {
|
|
132
|
-
throw new import_MatterError.ImplementationError(`Unsupported log level "${level}"`);
|
|
133
|
-
}
|
|
134
|
-
Logger.defaultLogLevel = levelNum;
|
|
286
|
+
return adaptDestinationToLegacy(dest);
|
|
135
287
|
}
|
|
136
288
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @param format the name of the formatter (see Format enum)
|
|
289
|
+
* @deprecated use {@link destinations}
|
|
140
290
|
*/
|
|
141
|
-
static
|
|
142
|
-
|
|
291
|
+
static getLoggerforIdentifier(identifier) {
|
|
292
|
+
return this.getLoggerForIdentifier(identifier);
|
|
143
293
|
}
|
|
144
294
|
/**
|
|
145
295
|
* Set facility loglevels for the default logger.
|
|
146
296
|
* @param levels The levels to set
|
|
297
|
+
*
|
|
298
|
+
* @deprecated use {@link destinations}
|
|
147
299
|
*/
|
|
148
300
|
static set logLevels(levels) {
|
|
149
301
|
Logger.setLogLevelsForLogger("default", levels);
|
|
150
302
|
}
|
|
151
303
|
/**
|
|
152
304
|
* Get facility loglevels for the default logger.
|
|
305
|
+
*
|
|
306
|
+
* @deprecated use {@link Logger.facilityLevels}
|
|
153
307
|
*/
|
|
154
308
|
static get logLevels() {
|
|
155
309
|
return Logger.getLoggerForIdentifier("default").logLevels;
|
|
@@ -158,12 +312,16 @@ class Logger {
|
|
|
158
312
|
* Set default loglevel for the default logger.
|
|
159
313
|
*
|
|
160
314
|
* @param level The level to set
|
|
315
|
+
*
|
|
316
|
+
* @deprecated use {@link Logger.level}
|
|
161
317
|
*/
|
|
162
318
|
static set defaultLogLevel(level) {
|
|
163
319
|
Logger.setDefaultLoglevelForLogger("default", level);
|
|
164
320
|
}
|
|
165
321
|
/**
|
|
166
322
|
* Get default loglevel for the default logger.
|
|
323
|
+
*
|
|
324
|
+
* @deprecated use {@link destinations}
|
|
167
325
|
*/
|
|
168
326
|
static get defaultLogLevel() {
|
|
169
327
|
return Logger.getLoggerForIdentifier("default").defaultLogLevel;
|
|
@@ -172,12 +330,16 @@ class Logger {
|
|
|
172
330
|
* Set the log function for the default logger.
|
|
173
331
|
*
|
|
174
332
|
* @param log The log function to set
|
|
333
|
+
*
|
|
334
|
+
* @deprecated use {@link destinations}
|
|
175
335
|
*/
|
|
176
336
|
static set log(log) {
|
|
177
337
|
Logger.setLogger("default", log);
|
|
178
338
|
}
|
|
179
339
|
/**
|
|
180
340
|
* Get the log function for the default logger.
|
|
341
|
+
*
|
|
342
|
+
* @deprecated use {@link destinations}
|
|
181
343
|
*/
|
|
182
344
|
static get log() {
|
|
183
345
|
return Logger.getLoggerForIdentifier("default").log;
|
|
@@ -186,12 +348,16 @@ class Logger {
|
|
|
186
348
|
* Set the log formatter for the default logger.
|
|
187
349
|
*
|
|
188
350
|
* @param logFormatter
|
|
351
|
+
*
|
|
352
|
+
* @deprecated use {@link destinations}
|
|
189
353
|
*/
|
|
190
354
|
static set logFormatter(logFormatter) {
|
|
191
355
|
Logger.setLogFormatterForLogger("default", logFormatter);
|
|
192
356
|
}
|
|
193
357
|
/**
|
|
194
358
|
* Get the log formatter for the default logger.
|
|
359
|
+
*
|
|
360
|
+
* @deprecated use {@link destinations}
|
|
195
361
|
*/
|
|
196
362
|
static get logFormatter() {
|
|
197
363
|
return Logger.getLoggerForIdentifier("default").logFormatter;
|
|
@@ -201,208 +367,55 @@ class Logger {
|
|
|
201
367
|
*
|
|
202
368
|
* @param identifier The identifier of the logger
|
|
203
369
|
* @param format the name of the formatter (see Format enum)
|
|
370
|
+
*
|
|
371
|
+
* @deprecated use {@link destinations}
|
|
204
372
|
*/
|
|
205
373
|
static setFormatForLogger(identifier, format) {
|
|
206
|
-
|
|
207
|
-
if (logger) {
|
|
208
|
-
logger.logFormatter = logFormatterFor(format);
|
|
209
|
-
} else {
|
|
210
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
211
|
-
}
|
|
374
|
+
this.getLoggerForIdentifier(identifier).logFormatter = logFormatterFor(format);
|
|
212
375
|
}
|
|
213
376
|
/**
|
|
214
377
|
* Set default loglevel for the logger with the matching identifier.
|
|
215
378
|
*
|
|
216
379
|
* @param identifier The identifier of the logger
|
|
217
380
|
* @param level The level to set
|
|
381
|
+
*
|
|
382
|
+
* @deprecated use {@link destinations}
|
|
218
383
|
*/
|
|
219
384
|
static setDefaultLoglevelForLogger(identifier, level) {
|
|
220
|
-
|
|
221
|
-
if (logger) {
|
|
222
|
-
logger.defaultLogLevel = level;
|
|
223
|
-
} else {
|
|
224
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
225
|
-
}
|
|
385
|
+
this.getLoggerForIdentifier(identifier).defaultLogLevel = level;
|
|
226
386
|
}
|
|
227
387
|
/**
|
|
228
388
|
* Set facility loglevels for the logger with the matching identifier.
|
|
229
389
|
*
|
|
230
390
|
* @param identifier The identifier of the logger
|
|
231
391
|
* @param levels The levels to set
|
|
392
|
+
*
|
|
393
|
+
* @deprecated use {@link destinations}
|
|
232
394
|
*/
|
|
233
395
|
static setLogLevelsForLogger(identifier, levels) {
|
|
234
|
-
|
|
235
|
-
if (logger) {
|
|
236
|
-
logger.logLevels = levels;
|
|
237
|
-
} else {
|
|
238
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
239
|
-
}
|
|
396
|
+
this.getLoggerForIdentifier(identifier).logLevels = levels;
|
|
240
397
|
}
|
|
241
398
|
/**
|
|
242
399
|
* Set the log function for the logger with the matching identifier.
|
|
243
400
|
*
|
|
244
401
|
* @param identifier The identifier of the logger
|
|
245
402
|
* @param log The log function to set
|
|
403
|
+
*
|
|
404
|
+
* @deprecated use {@link destinations}
|
|
246
405
|
*/
|
|
247
406
|
static setLogger(identifier, log) {
|
|
248
|
-
|
|
249
|
-
if (logger) {
|
|
250
|
-
logger.log = log;
|
|
251
|
-
} else {
|
|
252
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
253
|
-
}
|
|
407
|
+
this.getLoggerForIdentifier(identifier).log = log;
|
|
254
408
|
}
|
|
255
409
|
/**
|
|
256
410
|
* Set the log formatter for the logger with the matching identifier.
|
|
257
411
|
*
|
|
258
412
|
* @param identifier The identifier of the logger
|
|
259
413
|
* @param logFormatter The log formatter to set
|
|
260
|
-
*/
|
|
261
|
-
static setLogFormatterForLogger(identifier, logFormatter) {
|
|
262
|
-
const logger = Logger.logger.find((logger2) => logger2.logIdentifier === identifier);
|
|
263
|
-
if (logger) {
|
|
264
|
-
logger.logFormatter = logFormatter;
|
|
265
|
-
} else {
|
|
266
|
-
throw new import_MatterError.NotImplementedError(`Unknown logger "${identifier}"`);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Create a new facility.
|
|
271
|
-
*
|
|
272
|
-
* @param name the name of the facility
|
|
273
|
-
* @returns a new facility
|
|
274
|
-
*/
|
|
275
|
-
static get(name) {
|
|
276
|
-
return new Logger(name);
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Stringify a value (BigInt aware) as JSON.
|
|
280
|
-
*
|
|
281
|
-
* @param data the value to stringify
|
|
282
|
-
* @returns the stringified value
|
|
283
|
-
*/
|
|
284
|
-
static toJSON(data) {
|
|
285
|
-
return JSON.stringify(data, (_, value) => {
|
|
286
|
-
if (typeof value === "bigint") {
|
|
287
|
-
return value.toString();
|
|
288
|
-
}
|
|
289
|
-
if (value instanceof Uint8Array) {
|
|
290
|
-
return import_Bytes.Bytes.toHex(value);
|
|
291
|
-
}
|
|
292
|
-
if (value === void 0) {
|
|
293
|
-
return "undefined";
|
|
294
|
-
}
|
|
295
|
-
return value;
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Mask a string with a given character. If unmaskedLength is provided then these number of characters will be
|
|
300
|
-
* shown unmasked.
|
|
301
|
-
*
|
|
302
|
-
* @param str String to mask
|
|
303
|
-
* @param maskChar character to mask with
|
|
304
|
-
* @param unmaskedLength number of characters to show unmasked in the beginning
|
|
305
|
-
*/
|
|
306
|
-
static maskString(str, maskChar = "*", unmaskedLength) {
|
|
307
|
-
return str.substring(0, unmaskedLength ?? 0) + str.substring(unmaskedLength ?? 0).replace(/./g, maskChar);
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Perform operations in a nested logging context. Messages will be
|
|
311
|
-
* indented while the context executes.
|
|
312
|
-
*/
|
|
313
|
-
static nest(context) {
|
|
314
|
-
this.nestingLevel++;
|
|
315
|
-
try {
|
|
316
|
-
return context();
|
|
317
|
-
} finally {
|
|
318
|
-
this.nestingLevel--;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Async version of nest().
|
|
323
|
-
*/
|
|
324
|
-
static async nestAsync(context) {
|
|
325
|
-
this.nestingLevel++;
|
|
326
|
-
try {
|
|
327
|
-
return await context();
|
|
328
|
-
} finally {
|
|
329
|
-
this.nestingLevel--;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Unhandled error reporter.
|
|
334
|
-
*
|
|
335
|
-
* Some environments do not report full error details such as {@link Error#cause} and {@link AggregateError#errors}.
|
|
336
|
-
*
|
|
337
|
-
* To ensure these details are always recorded somewhere, unhandled errors may be reported here.
|
|
338
414
|
*
|
|
339
|
-
*
|
|
340
|
-
*/
|
|
341
|
-
static reportUnhandledError(error) {
|
|
342
|
-
try {
|
|
343
|
-
Logger.get("Logger").fatal("Unhandled error detected:", error);
|
|
344
|
-
} catch (e) {
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Invoke logic and return any log messages produced.
|
|
415
|
+
* @deprecated use {@link destinations}
|
|
349
416
|
*/
|
|
350
|
-
static
|
|
351
|
-
|
|
352
|
-
throw new Error("No logger loaded, cannot capture logs");
|
|
353
|
-
}
|
|
354
|
-
const logger = Logger.getLoggerForIdentifier(fromLogger);
|
|
355
|
-
const actualLogSettings = {
|
|
356
|
-
logFormatter: logger.logFormatter,
|
|
357
|
-
log: logger.log,
|
|
358
|
-
defaultLogLevel: logger.defaultLogLevel,
|
|
359
|
-
logLevels: { ...logger.logLevels }
|
|
360
|
-
};
|
|
361
|
-
try {
|
|
362
|
-
Logger.setFormatForLogger(fromLogger, import_LogFormat.LogFormat.PLAIN);
|
|
363
|
-
const captured = new Array();
|
|
364
|
-
Logger.setLogger(
|
|
365
|
-
fromLogger,
|
|
366
|
-
(level, message) => captured.push({
|
|
367
|
-
level,
|
|
368
|
-
message: message.replace(/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d/, "xxxx-xx-xx xx:xx:xx.xxx")
|
|
369
|
-
})
|
|
370
|
-
);
|
|
371
|
-
fn();
|
|
372
|
-
return captured;
|
|
373
|
-
} finally {
|
|
374
|
-
Logger.setLogFormatterForLogger(fromLogger, actualLogSettings.logFormatter);
|
|
375
|
-
Logger.setDefaultLoglevelForLogger(fromLogger, actualLogSettings.defaultLogLevel);
|
|
376
|
-
Logger.setLogLevelsForLogger(fromLogger, actualLogSettings.logLevels);
|
|
377
|
-
Logger.setLogger(fromLogger, actualLogSettings.log);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
constructor(name) {
|
|
381
|
-
this.#name = name;
|
|
382
|
-
}
|
|
383
|
-
debug = (...values) => this.#log(import_LogLevel.LogLevel.DEBUG, values);
|
|
384
|
-
info = (...values) => this.#log(import_LogLevel.LogLevel.INFO, values);
|
|
385
|
-
notice = (...values) => this.#log(import_LogLevel.LogLevel.NOTICE, values);
|
|
386
|
-
warn = (...values) => this.#log(import_LogLevel.LogLevel.WARN, values);
|
|
387
|
-
error = (...values) => this.#log(import_LogLevel.LogLevel.ERROR, values);
|
|
388
|
-
fatal = (...values) => this.#log(import_LogLevel.LogLevel.FATAL, values);
|
|
389
|
-
log = (level, ...values) => this.#log(level, values);
|
|
390
|
-
#log(level, values) {
|
|
391
|
-
for (const logger of Logger.logger) {
|
|
392
|
-
if (level < (logger.logLevels[this.#name] ?? logger.defaultLogLevel)) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
if (!logger.context) {
|
|
396
|
-
logger.context = import_Diagnostic.Diagnostic.Context();
|
|
397
|
-
}
|
|
398
|
-
logger.context.run(
|
|
399
|
-
() => logger.log(
|
|
400
|
-
level,
|
|
401
|
-
logger.logFormatter(import_Time.Time.now(), level, this.#name, nestingPrefix(), values),
|
|
402
|
-
this.#name
|
|
403
|
-
)
|
|
404
|
-
);
|
|
405
|
-
}
|
|
417
|
+
static setLogFormatterForLogger(identifier, logFormatter) {
|
|
418
|
+
this.getLoggerForIdentifier(identifier).logFormatter = logFormatter;
|
|
406
419
|
}
|
|
407
420
|
}
|
|
408
421
|
function nestingPrefix() {
|
|
@@ -412,17 +425,46 @@ function nestingPrefix() {
|
|
|
412
425
|
return "";
|
|
413
426
|
}
|
|
414
427
|
import_Boot.Boot.init(() => {
|
|
415
|
-
Logger.
|
|
416
|
-
logIdentifier: "default",
|
|
417
|
-
logFormatter: import_LogFormat.LogFormat.plain,
|
|
418
|
-
log: consoleLogger,
|
|
419
|
-
defaultLogLevel: import_LogLevel.LogLevel.DEBUG,
|
|
420
|
-
logLevels: {}
|
|
421
|
-
});
|
|
428
|
+
Logger.destinations = (0, import_LogDestination.LogDestinations)();
|
|
422
429
|
Logger.nestingLevel = 0;
|
|
423
430
|
if (typeof MatterHooks !== "undefined") {
|
|
424
431
|
MatterHooks.loggerSetup?.(Logger);
|
|
425
432
|
}
|
|
426
433
|
});
|
|
427
434
|
import_Cancelable.CancelablePromise.logger = Logger.get("CancelablePromise");
|
|
435
|
+
function logFormatterFor(formatName) {
|
|
436
|
+
const format = (0, import_LogFormat.LogFormat)(formatName);
|
|
437
|
+
return (now, level, facility, prefix, ...values) => format(import_Diagnostic.Diagnostic.message({ now, level, facility, prefix, values }));
|
|
438
|
+
}
|
|
439
|
+
function adaptDestinationToLegacy(destination) {
|
|
440
|
+
return {
|
|
441
|
+
get logIdentifier() {
|
|
442
|
+
return destination.name;
|
|
443
|
+
},
|
|
444
|
+
get logFormatter() {
|
|
445
|
+
return (now, level, facility, prefix, values) => destination.format(import_Diagnostic.Diagnostic.message({ now, level, facility, prefix, values }));
|
|
446
|
+
},
|
|
447
|
+
set logFormatter(logFormatter) {
|
|
448
|
+
destination.format = (message) => logFormatter(message.now, message.level, message.facility, message.prefix, message.values);
|
|
449
|
+
},
|
|
450
|
+
get log() {
|
|
451
|
+
return (level, formattedLog, facility) => destination.write(formattedLog, import_Diagnostic.Diagnostic.message({ level, facility }));
|
|
452
|
+
},
|
|
453
|
+
set log(log) {
|
|
454
|
+
destination.write = (text, message) => log(message.level, text, message.facility);
|
|
455
|
+
},
|
|
456
|
+
get defaultLogLevel() {
|
|
457
|
+
return destination.level;
|
|
458
|
+
},
|
|
459
|
+
set defaultLogLevel(level) {
|
|
460
|
+
destination.level = level;
|
|
461
|
+
},
|
|
462
|
+
get logLevels() {
|
|
463
|
+
return destination.facilityLevels;
|
|
464
|
+
},
|
|
465
|
+
set logLevels(levels) {
|
|
466
|
+
destination.facilityLevels = levels;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
428
470
|
//# sourceMappingURL=Logger.js.map
|